Package org.apache.derby.impl.jdbc
Class EncryptedLOBFile
java.lang.Object
org.apache.derby.impl.jdbc.LOBFile
org.apache.derby.impl.jdbc.EncryptedLOBFile
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
FieldsModifier and TypeFieldDescriptionprivate final int
Block size for encryption.private long
Current file position.private final DataFactory
Factory object used for encryption and decryption.private final byte[]
Leftover bytes.private int
Number of actual bytes in tail array. -
Constructor Summary
ConstructorsConstructorDescriptionEncryptedLOBFile
(StorageFile lobFile, DataFactory df) Constructs the EncryptedLOBFile object with encryption support. -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]
getBlocks
(long pos, int len) Find the blocks containing the data we are interested in.(package private) long
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
close, getStorageFile
-
Field Details
-
blockSize
private final int blockSizeBlock size for encryption. -
tail
private final byte[] tailLeftover bytes. Stored in memory until they fill one block . -
tailSize
private int tailSizeNumber of actual bytes in tail array. -
currentPos
private long currentPosCurrent file position. -
df
Factory object used for encryption and decryption.
-
-
Constructor Details
-
EncryptedLOBFile
EncryptedLOBFile(StorageFile lobFile, DataFactory df) throws FileNotFoundException Constructs the EncryptedLOBFile object with encryption support.- Parameters:
lobFile
- StorageFile Object for which file will be createddf
- data factory for encryption and decription- Throws:
FileNotFoundException
- if the file exists but is a directory or cannot be opened
-
-
Method Details
-
getBlocks
Find the blocks containing the data we are interested in.- Parameters:
pos
- first position we are interested inlen
- number of bytes of interest- Returns:
- byte array containing all the blocks of data the specified region spans over
- Throws:
IOException
StandardException
-
length
Returns file length.- Overrides:
length
in classLOBFile
- Returns:
- file length
- Throws:
IOException
- if an I/O error occurs
-
getFilePointer
long getFilePointer()Returns the currrent position in the file.- Overrides:
getFilePointer
in classLOBFile
- Returns:
- current position of file pointer
-
seek
Sets the current file pointer to specific location.- Overrides:
seek
in classLOBFile
- Parameters:
pos
- new position- Throws:
IOException
-
write
Writes one byte into the file.- Overrides:
write
in classLOBFile
- Parameters:
b
- byte value- Throws:
IOException
- if disk operation failsStandardException
- if error occurred during encryption/decryption
-
write
Writes length number of bytes from buffer starting from off position.- Overrides:
write
in classLOBFile
- Parameters:
b
- byte array containing bytes to be writtenoff
- starting offset of the byte array from where the data should be written to the filelen
- number of bytes to be written- Throws:
IOException
- if disk operation failsStandardException
- if error occurred during encryption/decryption
-
write
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 classLOBFile
- Parameters:
b
- byte array to be written- Throws:
IOException
- if disk operation failsStandardException
- if error occurred during encryption/decryption
-
readByte
Reads one byte from file.- Overrides:
readByte
in classLOBFile
- Returns:
- byte
- Throws:
IOException
- if disk operation failsStandardException
- if error occurred during decryption
-
read
Reads len or remaining bytes in the file (whichever is lower) bytes into buff starting from off position of the buffer.- Overrides:
read
in classLOBFile
- Parameters:
buff
- byte array to fill read bytesoff
- offset of buff where the byte will be writtenlen
- number of bytes to be read- Returns:
- number of bytes read
- Throws:
IOException
- if disk operation failsStandardException
- if error occurred during decryption
-
setLength
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 classLOBFile
- Parameters:
size
- new file size. Must be lower than file length.- Throws:
IOException
- if file i/o failsStandardException
- if error occurred during decryption
-