Package db
Class ChainedBuffer
java.lang.Object
db.ChainedBuffer
- All Implemented Interfaces:
Buffer
DBBuffer
provides storage for large data objects utilizing a common
buffer management system. Smaller data buffers are allocated and chained as needed.
All instances of DBBuffer must be immediately discarded following an undo or redo on the
associated DBHandle.
The largest supported chained buffer is about 2-GBytes. This limit may be slightly smaller based upon the underlying database buffer size.
The buffer may consist of either a single Data Node or a series of Index Nodes which reference Data Nodes.
Data Node (Non-indexed): | 9 (1) | Obfuscation/DataLength(4) | Data ... Data Node (Indexed): | 9 (1) | Data ... Index Node: | 8 (1) | Obfuscation/DataLength(4) | NextIndexId(4) | DataBuffer1Id(4) | ... | DataBufferNId(4) | Number of index entries computed based upon data length and buffer size. The index for the entire data space is divided among a series of Index Nodes which are chained together using the NextIndexId field. Each Index Node identifies Data Nodes which have been allocated by a DataBufferId. A DataBufferId of -1 indicates an non-allocated data node. The DataLength field is only used in the first index buffer. Obfuscation: Data obfuscation is indicated by a '1' in the most-significant bit of the Obfuscation/DataLength field.Once a DBBuffer is deleted or appended to another DBBuffer, it becomes invalid and may no longer be used.
-
Constructor Summary
ConstructorDescriptionChainedBuffer
(int size, boolean enableObfuscation, Buffer uninitializedDataSource, int unintializedDataSourceOffset, BufferMgr bufferMgr) Construct a new chained buffer with optional obfuscation and uninitialized data source.ChainedBuffer
(int size, boolean enableObfuscation, BufferMgr bufferMgr) Construct a new chained buffer with optional obfuscation.ChainedBuffer
(int size, BufferMgr bufferMgr) Construct a new chained buffer.ChainedBuffer
(BufferMgr bufferMgr, int bufferId) Construct an existing chained buffer.ChainedBuffer
(BufferMgr bufferMgr, int bufferId, Buffer uninitializedDataSource, int unintializedDataSourceOffset) Construct an existing chained buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(ChainedBuffer dbBuf) Append the contents of the specified dbBuf onto the end of this buffer.void
delete()
Delete and release all underlying DataBuffers.void
fill
(int startOffset, int endOffset, byte fillByte) Fill the buffer over the specified range with a byte value.void
fill
(InputStream in) Fill buffer with data provided by InputStream.void
get
(int offset, byte[] data) Get the byte data located at the specified offset and store into the bytes array provided.void
get
(int offset, byte[] data, int dataOffset, int length) Get the byte data located at the specified offset and store into the data array at the specified data offset.byte[]
get
(int offset, int length) Get the byte data located at the specified offset.byte
getByte
(int offset) Get the 8-bit byte value located at the specified offset.int
getId()
Get the first buffer ID associated with this chained buffer.int
getInt
(int offset) Get the 32-bit integer value located at the specified offset.long
getLong
(int offset) Get the 64-bit long value located at the specified offset.short
getShort
(int offset) Get the 16-bit short value located at the specified offset.boolean
int
length()
Get the length of the buffer in bytes.int
put
(int offset, byte[] bytes) Put the bytes provided into the buffer at the specified offset.int
put
(int offset, byte[] data, int dataOffset, int length) Put a specified number of bytes from the array provided into the buffer at the specified offset.int
putByte
(int offset, byte b) Put the 8-bit byte value into the buffer at the specified offset.int
putInt
(int offset, int v) Put the 32-bit integer value into the buffer at the specified offset.int
putLong
(int offset, long v) Put the 64-bit long value into the buffer at the specified offset.int
putShort
(int offset, short v) Put the 16-bit short value into the buffer at the specified offset.void
Set the read-only state of this ChainedBuffer.void
setSize
(int size, boolean preserveData) Set the new size for this DBBuffer object.split
(int offset) Split this DBBuffer object into two separate DBBuffers.
-
Constructor Details
-
ChainedBuffer
public ChainedBuffer(int size, boolean enableObfuscation, Buffer uninitializedDataSource, int unintializedDataSourceOffset, BufferMgr bufferMgr) throws IOException Construct a new chained buffer with optional obfuscation and uninitialized data source. This method may only be invoked while a database transaction is in progress.- Parameters:
size
- buffer size (0 < size <= 0x7fffffff)enableObfuscation
- true to enable xor-ing of stored data to facilitate data obfuscation.uninitializedDataSource
- optional data source for uninitialized data. This should be a read-only buffer which will always be used when re-instantiating the same stored ChainedBuffer. This should not be specified if buffer will be completely filled/initialized.unintializedDataSourceOffset
- uninitialized data source offset which corresponds to this buffers contents.bufferMgr
- database buffer manager- Throws:
IOException
- thrown if an IO error occurs
-
ChainedBuffer
Construct a new chained buffer with optional obfuscation. This method may only be invoked while a database transaction is in progress.- Parameters:
size
- buffer size (0 < size <= 0x7fffffff)enableObfuscation
- true to enable xor-ing of stored data to facilitate data obfuscation.bufferMgr
- database buffer manager- Throws:
IOException
- thrown if an IO error occurs
-
ChainedBuffer
Construct a new chained buffer. This method may only be invoked while a database transaction is in progress.- Parameters:
size
- buffer size (0 < size <= 0x7fffffff)bufferMgr
- database buffer manager- Throws:
IOException
- thrown if an IO error occurs
-
ChainedBuffer
public ChainedBuffer(BufferMgr bufferMgr, int bufferId, Buffer uninitializedDataSource, int unintializedDataSourceOffset) throws IOException Construct an existing chained buffer.- Parameters:
bufferMgr
- database buffer managerbufferId
- database buffer ID which corresponds to a stored ChainedBufferuninitializedDataSource
- optional data source for uninitialized data. This should be a read-only buffer which will always be used when re-instantiating the same stored ChainedBuffer. This should not be specified if buffer will be completely filled/initialized.unintializedDataSourceOffset
- uninitialized data source offset which corresponds to this buffers contents.- Throws:
IOException
- thrown if an IO error occurs
-
ChainedBuffer
Construct an existing chained buffer.- Parameters:
bufferMgr
- database buffer managerbufferId
- database buffer ID which corresponds to a stored ChainedBuffer- Throws:
IOException
- thrown if an IO error occurs
-
-
Method Details
-
hasObfuscatedStorage
public boolean hasObfuscatedStorage()- Returns:
- true if obfuscated data storage has been enabled
-
setReadOnly
public void setReadOnly()Set the read-only state of this ChainedBuffer. After invoking this method any attempt to alter this buffer will result in an UnsupportedOperation exception. -
setSize
Set the new size for this DBBuffer object.- Parameters:
size
- new sizepreserveData
- if true, existing data is preserved at the original offsets. If false, no additional effort will be expended to preserve data.- Throws:
UnsupportedOperationException
- thrown if this ChainedBuffer utilizes an Uninitialized Data Source or is read-onlyIOException
- thrown if an IO error occurs.
-
split
Split this DBBuffer object into two separate DBBuffers. This DBBuffer remains valid but its new size is equal offset. The newly created DBBuffer is returned.- Parameters:
offset
- the split point. The byte at this offset becomes the first byte within the new buffer.- Returns:
- the new DBBuffer object.
- Throws:
UnsupportedOperationException
- thrown if this ChainedBuffer is read-onlyIndexOutOfBoundsException
- if offset is invalid.IOException
- thrown if an IO error occurs
-
append
Append the contents of the specified dbBuf onto the end of this buffer. The size of this buffer increases by the size of dbBuf. When the operation is complete, dbBuf object is no longer valid and must not be used.- Parameters:
dbBuf
- the buffer to be appended to this buffer.- Throws:
IOException
- thrown if an IO error occursUnsupportedOperationException
- if read-only, uninitialized data source is used, or both buffers do not have the same obfuscation enablement
-
getId
public int getId()Get the first buffer ID associated with this chained buffer. This DBBuffer may be reinstatiated using the returned buffer ID provided subsequent changes are not made. -
delete
Delete and release all underlying DataBuffers.- Throws:
IOException
- thrown if an IO error occurs
-
get
public void get(int offset, byte[] data, int dataOffset, int length) throws IndexOutOfBoundsException, IOException Description copied from interface:Buffer
Get the byte data located at the specified offset and store into the data array at the specified data offset.- Specified by:
get
in interfaceBuffer
- Parameters:
offset
- byte offset from the start of the buffer.data
- byte array to store the data.dataOffset
- offset into the data bufferlength
- amount of data to read- Throws:
IndexOutOfBoundsException
- if an invalid offset, dataOffset, or length is specified.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
get
Description copied from interface:Buffer
Get the byte data located at the specified offset and store into the bytes array provided.- Specified by:
get
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.data
- byte array to store data- Throws:
IndexOutOfBoundsException
- is thrown if an invalid offset is specified.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
get
Description copied from interface:Buffer
Get the byte data located at the specified offset.- Specified by:
get
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.length
- number of bytes to be read and returned- Returns:
- the byte array.
- Throws:
IndexOutOfBoundsException
- is thrown if an invalid offset is specified or the end of the buffer was encountered while reading the data.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
getByte
Description copied from interface:Buffer
Get the 8-bit byte value located at the specified offset.- Specified by:
getByte
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.- Returns:
- the byte value at the specified offset.
- Throws:
IndexOutOfBoundsException
- is thrown if an invalid offset is specified.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
getInt
Description copied from interface:Buffer
Get the 32-bit integer value located at the specified offset.- Specified by:
getInt
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.- Returns:
- the integer value at the specified offset.
- Throws:
IndexOutOfBoundsException
- is thrown if an invalid offset is specified or the end of the buffer was encountered while reading the value.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
getLong
Description copied from interface:Buffer
Get the 64-bit long value located at the specified offset.- Specified by:
getLong
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.- Returns:
- the long value at the specified offset.
- Throws:
IndexOutOfBoundsException
- is thrown if an invalid offset is specified or the end of the buffer was encountered while reading the value.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
getShort
Description copied from interface:Buffer
Get the 16-bit short value located at the specified offset.- Specified by:
getShort
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.- Returns:
- the short value at the specified offset.
- Throws:
IndexOutOfBoundsException
- is thrown if an invalid offset is specified or the end of the buffer was encountered while reading the value.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
length
public int length()Description copied from interface:Buffer
Get the length of the buffer in bytes. The length reflects the number of bytes which have been allocated to the buffer. -
fill
public void fill(int startOffset, int endOffset, byte fillByte) throws IndexOutOfBoundsException, IOException Fill the buffer over the specified range with a byte value.- Parameters:
startOffset
- starting offset, inclusiveendOffset
- ending offset, inclusivefillByte
- byte value- Throws:
IndexOutOfBoundsException
- if an invalid offsets are provided or the end of buffer was encountered while storing the data.IOException
- thrown if an IO error occurs
-
fill
Fill buffer with data provided by InputStream. If stream is exhausted, the remainder of the buffer will be filled with 0's.- Parameters:
in
- data source- Throws:
IOException
- thrown if IO error occurs.
-
put
public int put(int offset, byte[] data, int dataOffset, int length) throws IndexOutOfBoundsException, IOException Description copied from interface:Buffer
Put a specified number of bytes from the array provided into the buffer at the specified offset. The number of bytes stored is specified by the length specified.- Specified by:
put
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.data
- the byte data to be stored.dataOffset
- the starting offset into the data.length
- the number of bytes to be stored.- Returns:
- the next available offset into the buffer, or -1 if the buffer is full.
- Throws:
IndexOutOfBoundsException
- if an invalid offset is provided or the end of buffer was encountered while storing the data.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
put
Description copied from interface:Buffer
Put the bytes provided into the buffer at the specified offset. The number of bytes stored is determined by the length of the bytes array.- Specified by:
put
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.bytes
- the byte data to be stored.- Returns:
- the next available offset into the buffer, or -1 if the buffer is full.
- Throws:
IndexOutOfBoundsException
- if an invalid offset is provided or the end of buffer was encountered while storing the data.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
putByte
Description copied from interface:Buffer
Put the 8-bit byte value into the buffer at the specified offset.- Specified by:
putByte
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.b
- the byte value to be stored.- Returns:
- the next available offset into the buffer, or -1 if the buffer is full.
- Throws:
IndexOutOfBoundsException
- if an invalid offset is provided.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
putInt
Description copied from interface:Buffer
Put the 32-bit integer value into the buffer at the specified offset.- Specified by:
putInt
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.v
- the integer value to be stored.- Returns:
- the next available offset into the buffer, or -1 if the buffer is full.
- Throws:
IndexOutOfBoundsException
- if an invalid offset is provided or the end of buffer was encountered while storing the data.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
putLong
Description copied from interface:Buffer
Put the 64-bit long value into the buffer at the specified offset.- Specified by:
putLong
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.v
- the long value to be stored.- Returns:
- the next available offset into the buffer, or -1 if the buffer is full.
- Throws:
IndexOutOfBoundsException
- if an invalid offset is provided or the end of buffer was encountered while storing the data.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
putShort
Description copied from interface:Buffer
Put the 16-bit short value into the buffer at the specified offset.- Specified by:
putShort
in interfaceBuffer
- Parameters:
offset
- byte offset from start of buffer.v
- the short value to be stored.- Returns:
- the next available offset into the buffer, or -1 if the buffer is full.
- Throws:
IndexOutOfBoundsException
- if an invalid offset is provided or the end of buffer was encountered while storing the data.IOException
- is thrown if an error occurs while accessing the underlying storage.
-