Package db
Class DBBuffer
- java.lang.Object
-
- db.DBBuffer
-
public class DBBuffer extends java.lang.Object
DBBuffer
facilitates synchronized access to a ChainedBuffer.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(DBBuffer buffer)
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(java.io.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.DBBuffer
split(int offset)
Split this DBBuffer object into two seperate DBBuffers.
-
-
-
Method Detail
-
split
public DBBuffer split(int offset) throws java.io.IOException
Split this DBBuffer object into two seperate 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:
java.lang.ArrayIndexOutOfBoundsException
- if offset is invalid.java.io.IOException
- thrown if an IO error occurs
-
setSize
public void setSize(int size, boolean preserveData) throws java.io.IOException
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:
java.io.IOException
- thrown if an IO error occurs.
-
length
public int length()
Returns the length;- Returns:
-
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 java.io.IOException
Fill the buffer over the specified range with a byte value.- Parameters:
startOffset
- starting offset, inclusiveendOffset
- ending offset, exclusivefillByte
- byte value- Throws:
java.io.IOException
-
append
public void append(DBBuffer buffer) throws java.io.IOException
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:
java.io.IOException
- thrown if an IO error occurs
-
getByte
public byte getByte(int offset) throws java.io.IOException
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:
java.lang.ArrayIndexOutOfBoundsException
- is thrown if an invalid offset is specified.java.io.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 java.io.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:
java.lang.ArrayIndexOutOfBoundsException
- if an invalid offset, dataOffset, or length is specified.java.io.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
fill
public void fill(java.io.InputStream in) throws java.io.IOException
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:
java.io.IOException
- thrown if IO error occurs.
-
put
public void put(int offset, byte[] bytes, int dataOffset, int length) throws java.io.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.data
- the byte data to be stored.dataOffset
- the starting offset into the data.length
- the number of bytes to be stored.- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if an invalid offset is provided or the end of buffer was encountered while storing the data.java.io.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
put
public void put(int offset, byte[] bytes) throws java.io.IOException
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:
java.lang.ArrayIndexOutOfBoundsException
- if an invalid offset is provided or the end of buffer was encountered while storing the data.java.io.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
putByte
public void putByte(int offset, byte b) throws java.io.IOException
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:
java.lang.ArrayIndexOutOfBoundsException
- if an invalid offset is provided.java.io.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
get
public void get(int offset, byte[] data) throws java.io.IOException
Get the byte data located at the specified offset.- Parameters:
offset
- byte offset from start of buffer.- Throws:
java.lang.ArrayIndexOutOfBoundsException
- is thrown if an invalid offset is specified or the end of the buffer was encountered while reading the data.java.io.IOException
- is thrown if an error occurs while accessing the underlying storage.
-
delete
public void delete() throws java.io.IOException
Delete and release all underlying DataBuffers.- Throws:
java.io.IOException
-
-