Top Description Fields Constructors Methods
org.apache.derby.impl.jdbc

pack-priv Class EncryptedLOBFile

extends LOBFile
Class Inheritance
Imports
java.io.EOFException, .FileNotFoundException, .IOException, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.iapi.store.raw.data.DataFactory, org.apache.derby.io.StorageFile

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

Modifier and TypeField and Description
private final int
blockSize

Block size for encryption.

private long
currentPos

Current file position.

private final DataFactory
df

Factory object used for encryption and decryption.

private final byte[]
tail

Leftover bytes.

private int
tailSize

Number of actual bytes in tail array.

Constructor Summary

AccessConstructor and Description
pack-priv
EncryptedLOBFile(StorageFile
StorageFile Object for which file will be created
lobFile
,
DataFactory
data factory for encryption and decription
df
)

Constructs the EncryptedLOBFile object with encryption support.

Method Summary

Modifier and TypeMethod and Description
private byte[]

Returns:

byte array containing all the blocks of data the specified region spans over
getBlocks
(long
first position we are interested in
pos
,
int
number of bytes of interest
len
)

Find the blocks containing the data we are interested in.

pack-priv long

Returns:

current position of file pointer
getFilePointer
()

Overrides org.apache.derby.impl.jdbc.LOBFile.getFilePointer.

Returns the currrent position in the file.

pack-priv long

Returns:

file length
length
()

Overrides org.apache.derby.impl.jdbc.LOBFile.length.

Returns file length.

pack-priv int

Returns:

number of bytes read
read
(byte[]
byte array to fill read bytes
buff
,
int
offset of buff where the byte will be written
off
,
int
number of bytes to be read
len
)

Overrides org.apache.derby.impl.jdbc.LOBFile.read.

Reads len or remaining bytes in the file (whichever is lower) bytes into buff starting from off position of the buffer.

pack-priv int

Returns:

byte
readByte
()

Overrides org.apache.derby.impl.jdbc.LOBFile.readByte.

Reads one byte from file.

pack-priv void
seek(long
new position
pos
)

Overrides org.apache.derby.impl.jdbc.LOBFile.seek.

Sets the current file pointer to specific location.

pack-priv void
setLength(long
new file size. Must be lower than file length.
size
)

Overrides org.apache.derby.impl.jdbc.LOBFile.setLength.

Sets the file length to a given size.

pack-priv void
write(int
byte value
b
)

Overrides org.apache.derby.impl.jdbc.LOBFile.write.

Writes one byte into the file.

pack-priv void
write(byte[]
byte array containing bytes to be written
b
,
int
starting offset of the byte array from where the data should be written to the file
off
,
int
number of bytes to be written
len
)

Overrides org.apache.derby.impl.jdbc.LOBFile.write.

Writes length number of bytes from buffer starting from off position.

pack-priv void
write(byte[]
byte array to be written
b
)

Overrides org.apache.derby.impl.jdbc.LOBFile.write.

Write the buffer into file at current position.

Inherited from org.apache.derby.impl.jdbc.LOBFile:
closegetStorageFile

Field Detail

blockSizeback to summary
private final int blockSize

Block size for encryption.

currentPosback to summary
private long currentPos

Current file position.

dfback to summary
private final DataFactory df

Factory object used for encryption and decryption.

tailback to summary
private final byte[] tail

Leftover bytes. Stored in memory until they fill one block .

tailSizeback to summary
private int tailSize

Number of actual bytes in tail array.

Constructor Detail

EncryptedLOBFileback to summary
pack-priv EncryptedLOBFile(StorageFile lobFile, DataFactory df) throws FileNotFoundException

Constructs the EncryptedLOBFile object with encryption support.

Parameters
lobFile:StorageFile

StorageFile Object for which file will be created

df:DataFactory

data factory for encryption and decription

Exceptions
FileNotFoundException:
if the file exists but is a directory or cannot be opened

Method Detail

getBlocksback to summary
private byte[] getBlocks(long pos, int len) throws IOException, StandardException

Find the blocks containing the data we are interested in.

Parameters
pos:long

first position we are interested in

len:int

number of bytes of interest

Returns:byte[]

byte array containing all the blocks of data the specified region spans over

getFilePointerback to summary
pack-priv long getFilePointer()

Overrides org.apache.derby.impl.jdbc.LOBFile.getFilePointer.

Returns the currrent position in the file.

Returns:long

current position of file pointer

lengthback to summary
pack-priv long length() throws IOException

Overrides org.apache.derby.impl.jdbc.LOBFile.length.

Returns file length.

Returns:long

file length

Exceptions
IOException:
if an I/O error occurs
readback to summary
pack-priv int read(byte[] buff, int off, int len) throws IOException, StandardException

Overrides org.apache.derby.impl.jdbc.LOBFile.read.

Reads len or remaining bytes in the file (whichever is lower) bytes into buff starting from off position of the buffer.

Parameters
buff:byte[]

byte array to fill read bytes

off:int

offset of buff where the byte will be written

len:int

number of bytes to be read

Returns:int

number of bytes read

Exceptions
IOException:
if disk operation fails
StandardException:
if error occurred during decryption
readByteback to summary
pack-priv int readByte() throws IOException, StandardException

Overrides org.apache.derby.impl.jdbc.LOBFile.readByte.

Reads one byte from file.

Returns:int

byte

Exceptions
IOException:
if disk operation fails
StandardException:
if error occurred during decryption
seekback to summary
pack-priv void seek(long pos) throws IOException

Overrides org.apache.derby.impl.jdbc.LOBFile.seek.

Sets the current file pointer to specific location.

Parameters
pos:long

new position

Exceptions
IOException:

Doc from org.apache.derby.impl.jdbc.LOBFile.seek.

if an I/O error occurs

setLengthback to summary
pack-priv void setLength(long size) throws IOException, StandardException

Overrides org.apache.derby.impl.jdbc.LOBFile.setLength.

Sets the file length to a given size. If the new size is smaller than the file length the file is truncated.

Parameters
size:long

new file size. Must be lower than file length.

Exceptions
IOException:
if file i/o fails
StandardException:
if error occurred during decryption
writeback to summary
pack-priv void write(int b) throws IOException, StandardException

Overrides org.apache.derby.impl.jdbc.LOBFile.write.

Writes one byte into the file.

Parameters
b:int

byte value

Exceptions
IOException:
if disk operation fails
StandardException:
if error occurred during encryption/decryption
writeback to summary
pack-priv void write(byte[] b, int off, int len) throws IOException, StandardException

Overrides org.apache.derby.impl.jdbc.LOBFile.write.

Writes length number of bytes from buffer starting from off position.

Parameters
b:byte[]

byte array containing bytes to be written

off:int

starting offset of the byte array from where the data should be written to the file

len:int

number of bytes to be written

Exceptions
IOException:
if disk operation fails
StandardException:
if error occurred during encryption/decryption
writeback to summary
pack-priv void write(byte[] b) throws IOException, StandardException

Overrides org.apache.derby.impl.jdbc.LOBFile.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.

Parameters
b:byte[]

byte array to be written

Exceptions
IOException:
if disk operation fails
StandardException:
if error occurred during encryption/decryption