org.apache.derby.impl.jdbc
Class EncryptedLOBFile

java.lang.Object
  extended by org.apache.derby.impl.jdbc.LOBFile
      extended by org.apache.derby.impl.jdbc.EncryptedLOBFile

 class EncryptedLOBFile
extends LOBFile

This class is a wrapper class on top of StorageRandomAccess to provide common methods to write in encrypted file. This class is NOT thread safe. The user class should take care of synchronization if being used in multi threaded environment.


Field Summary
private  int blockSize
          Block size for encryption.
private  long currentPos
          Current file position.
private  DataFactory df
          Factory object used for encryption and decryption.
private  byte[] tail
          Leftover bytes.
private  int tailSize
          Number of actual bytes in tail array.
 
Constructor Summary
EncryptedLOBFile(StorageFile lobFile, DataFactory df)
          Constructs the EncryptedLOBFile object with encryption support.
 
Method Summary
(package private)  void close()
          closes the file.
private  byte[] getBlocks(long pos, int len)
          Find the blocks containing the data we are interested in.
(package private)  long getFilePointer()
          Returns the currrent position in the file.
(package private)  long length()
          Returns file length.
(package private)  int read(byte[] buff, int off, int len)
          Reads len or remaining bytes in the file (whichever is lower) bytes into buff starting from off position of the buffer.
(package private)  int readByte()
          Reads one byte from file.
(package private)  void seek(long pos)
          Sets the current file pointer to specific location.
(package private)  void setLength(long size)
          Sets the file length to a given size.
(package private)  void write(byte[] b)
          Write the buffer into file at current position.
(package private)  void write(byte[] b, int off, int len)
          Writes length number of bytes from buffer starting from off position.
(package private)  void write(int b)
          Writes one byte into the file.
 
Methods inherited from class org.apache.derby.impl.jdbc.LOBFile
getStorageFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

blockSize

private final int blockSize
Block size for encryption.


tail

private final byte[] tail
Leftover bytes. Stored in memory until they fill one block .


tailSize

private int tailSize
Number of actual bytes in tail array.


currentPos

private long currentPos
Current file position.


df

private final DataFactory df
Factory object used for encryption and decryption.

Constructor Detail

EncryptedLOBFile

EncryptedLOBFile(StorageFile lobFile,
                 DataFactory df)
           throws java.io.FileNotFoundException
Constructs the EncryptedLOBFile object with encryption support.

Parameters:
lobFile - StorageFile Object for which file will be created
df - data factory for encryption and decription
Throws:
java.io.FileNotFoundException - if the file exists but is a directory or cannot be opened
Method Detail

getBlocks

private byte[] getBlocks(long pos,
                         int len)
                  throws java.io.IOException,
                         StandardException
Find the blocks containing the data we are interested in.

Parameters:
pos - first position we are interested in
len - number of bytes of interest
Returns:
byte array containing all the blocks of data the specified region spans over
Throws:
java.io.IOException
StandardException

length

long length()
      throws java.io.IOException
Returns file length.

Overrides:
length in class LOBFile
Returns:
file length
Throws:
java.io.IOException - if an I/O error occurs

getFilePointer

long getFilePointer()
Returns the currrent position in the file.

Overrides:
getFilePointer in class LOBFile
Returns:
current position of file pointer

seek

void seek(long pos)
    throws java.io.IOException
Sets the current file pointer to specific location.

Overrides:
seek in class LOBFile
Parameters:
pos - new position
Throws:
java.io.IOException

write

void write(int b)
     throws java.io.IOException,
            StandardException
Writes one byte into the file.

Overrides:
write in class LOBFile
Parameters:
b - byte value
Throws:
java.io.IOException - if disk operation fails
StandardException - if error occured during encryption/decryption

write

void write(byte[] b,
           int off,
           int len)
     throws java.io.IOException,
            StandardException
Writes length number of bytes from buffer starting from off position.

Overrides:
write in class LOBFile
Parameters:
b - byte array containing bytes to be written
off - starting offset of the byte array from where the data should be written to the file
len - number of bytes to be written
Throws:
java.io.IOException - if disk operation fails
StandardException - if error occured during encryption/decryption

write

void write(byte[] b)
     throws java.io.IOException,
            StandardException
Write the buffer into file at current position. It overwrites the data if current position is in the middle of the file and appends into the file if the total length exceeds the file size.

Overrides:
write in class LOBFile
Parameters:
b - byte array to be written
Throws:
java.io.IOException - if disk operation fails
StandardException - if error occured during encryption/decryption

close

void close()
     throws java.io.IOException
closes the file.

Overrides:
close in class LOBFile
Throws:
java.io.IOException

readByte

int readByte()
       throws java.io.IOException,
              StandardException
Reads one byte from file.

Overrides:
readByte in class LOBFile
Returns:
byte
Throws:
java.io.IOException - if disk operation fails
StandardException - if error occured during encryption/decryption

read

int read(byte[] buff,
         int off,
         int len)
   throws java.io.IOException,
          StandardException
Reads len or remaining bytes in the file (whichever is lower) bytes into buff starting from off position of the buffer.

Overrides:
read in class LOBFile
Parameters:
buff - byte array to fill read bytes
off - offset of buff where the byte will be written
len - number of bytes to be read
Returns:
number of bytes read
Throws:
java.io.IOException - if disk operation fails
StandardException - if error occured during encryption/decryption

setLength

void setLength(long size)
         throws java.io.IOException,
                StandardException
Sets the file length to a given size. If the new size is smaller than the file length the file is truncated.

Overrides:
setLength in class LOBFile
Parameters:
size - new file size. Must be lower than file length.
Throws:
java.io.IOException - if file i/o fails
StandardException - if error occured during encryption/decryption

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.