Package db
Class DBBuffer
java.lang.Object
db.DBBuffer
DBBuffer
facilitates synchronized access to a ChainedBuffer.-
Method Summary
Modifier and TypeMethodDescriptionvoid
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.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
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
length()
Returns the length;void
put
(int offset, byte[] bytes) Put the bytes provided into the buffer at the specified offset.void
put
(int offset, byte[] bytes, int dataOffset, int length) Put a specified number of bytes from the array provided into the buffer at the specified offset.void
putByte
(int offset, byte b) Put the 8-bit byte value into the buffer at the specified offset.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.
-
Method Details
-
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:
IndexOutOfBoundsException
- if offset is invalid.IOException
- thrown if an IO error occurs
-
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.
-
length
public int length()Returns the length;- Returns:
- this buffers length
-
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.- Returns:
- buffer ID
-
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, exclusivefillByte
- 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
-
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:
buffer
- the buffer to be appended to this buffer.- Throws:
UnsupportedOperationException
- if read-only, uninitialized data source is used, or both buffers do not have the same obfuscation enablementIOException
- thrown if an IO error occurs
-
getByte
Get the 8-bit byte value located at the specified offset.- 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.
-
get
public void get(int offset, byte[] data, int dataOffset, int length) throws IndexOutOfBoundsException, IOException Get the byte data located at the specified offset and store into the data array at the specified data offset.- 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.
-
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 void put(int offset, byte[] bytes, int dataOffset, int length) throws IndexOutOfBoundsException, IOException 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.- Parameters:
offset
- byte offset from start of buffer.bytes
- the byte data to be stored.dataOffset
- the starting offset into the data.length
- the number of bytes to be stored.- 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
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.- Parameters:
offset
- byte offset from start of buffer.bytes
- the byte data to be stored.- 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
Put the 8-bit byte value into the buffer at the specified offset.- Parameters:
offset
- byte offset from start of buffer.b
- the byte value to be stored.- Throws:
IndexOutOfBoundsException
- if an invalid offset is provided.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
get
Get the byte data located at the specified offset.- Parameters:
offset
- byte offset from start of buffer.data
- data buffer to be filled- 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.
-
delete
Delete and release all underlying DataBuffers.- Throws:
IOException
- is thrown if an error occurs while accessing the underlying storage.
-