KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datasystem > persistentsystem > EncryptDRandomAccessFile


1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem;
2
3 import java.io.*;
4
5
6 import com.daffodilwoods.daffodildb.server.datasystem.encryptdecrypt.*;
7 import com.daffodilwoods.database.resource.*;
8 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.EncryptDRandomAccessFileUpto3_2;
9
10
11 public class EncryptDRandomAccessFile extends EncryptDRandomAccessFileUpto3_2{
12
13
14     public EncryptDRandomAccessFile(RandomAccessFile raf0,long fileSize0,String JavaDoc databaseURL0,int incrementFactor0,boolean multiFileSupport1,FileGenerator fileGenerator0,EDBlockCipher bolckCipher0,int clusterSize )throws DException {
15         super(raf0,fileSize0,databaseURL0,incrementFactor0,multiFileSupport1,fileGenerator0,bolckCipher0,clusterSize);
16
17     }
18     /**
19      * If multiFileSupport is required then gets total number of files from filegenerator for this database.
20      * If it gets -1 then puts database Entry in Filegenerator otheriwse initializes all random access files
21      * by null in Map.
22      */

23
24     protected void init() throws DException {
25       int no_OfFiles = fileGenerator.getIndex(databaseName);
26       if(no_OfFiles == -1)
27         fileGenerator.insert(databaseName);
28       for( int i = 1 ; i < no_OfFiles; i++ ){
29         filesMap.put("_"+i,null);
30       }
31     }
32     /**
33         * It is called when a position is to be seeked which is large than length
34         * of file and index caluculated for dat file is > fileMap size
35         * than we make a new file with passed index.
36         *
37         * @param x int - index with which new .dat file is to be created.
38         * @throws DException
39         * @throws IOException
40         */

41
42     protected void makeNewFile(int x) throws DException,IOException{
43       try{
44         fileGenerator.addNewFile(x,databaseName);
45         String JavaDoc newFileName = "_"+x;
46         raf = new RandomAccessFile(path+File.separator+newFileName+".dat","rw");
47         raf.setLength(newFileSize);
48         filesMap.put(newFileName, raf);
49       }
50       catch(NullPointerException JavaDoc de) {
51         throw new DException("DSE0",new Object JavaDoc[] {de.getMessage()});
52       }
53     }
54     /**
55         * It is used when a position to be seeked is lagre than file length and
56         * index caluculated for dat file is less than or equal to fileMap size
57         * than we assume that file is already created and we need to load it.
58         *
59         * @param x int - index of dat file to be loaded.
60         * @throws DException
61         * @throws IOException
62         */

63
64
65      protected void loadNewFile(int x)throws DException,IOException{
66        String JavaDoc name = x == 0 ? databaseName : "_"+x;
67        raf = (RandomAccessFile)filesMap.get(name);
68        if(raf == null){
69          raf = new RandomAccessFile(path+File.separator+name+".dat","rw");
70          raf.setLength(newFileSize);
71          filesMap.put(name,raf);
72        }
73   }
74 }
75
Popular Tags