Package db.buffers
Class DataBuffer
java.lang.Object
db.buffers.DataBuffer
- All Implemented Interfaces:
Buffer,Externalizable,Serializable
DataBuffer provides an accessible binary buffer
for use with a BufferMgr and BufferFile.- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructor for de-serializationprotectedDataBuffer(byte[] data) Construct a data buffer.protectedDataBuffer(int bufsize) Construct a data buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all the values in the buffer to 0;voidcopy(int offset, DataBuffer buf, int bufOffset, int length) Copy data from another buffer into this buffer.static voidenableCompressedSerializationOutput(boolean enable) voidget(int offset, byte[] bytes) Get the byte data located at the specified offset and store into the bytes array provided.voidget(int offset, byte[] bytes, 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.bytegetByte(int offset) Get the 8-bit byte value located at the specified offset.protected byte[]getData()Get the storage array associated with this buffer.intgetId()Get the ID associated with this buffer.intgetInt(int offset) Get the 32-bit integer value located at the specified offset.longgetLong(int offset) Get the 64-bit long value located at the specified offset.shortgetShort(int offset) Get the 16-bit short value located at the specified offset.booleanisDirty()Return true if this buffer contains modified data.booleanisEmpty()Return true if this buffer is empty/unused.intlength()Get the length of the buffer in bytes.voidmove(int src, int dest, int length) Move the data within this buffer.intput(int offset, byte[] bytes) Put the bytes provided into the buffer at the specified offset.intput(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.intputByte(int offset, byte b) Put the 8-bit byte value into the buffer at the specified offset.intputInt(int offset, int v) Put the 32-bit integer value into the buffer at the specified offset.intputLong(int offset, long v) Put the 64-bit long value into the buffer at the specified offset.intputShort(int offset, short v) Put the 16-bit short value into the buffer at the specified offset.voidprotected voidsetData(byte[] data) Get the storage array associated with this buffer.protected voidsetDirty(boolean state) Set the dirty flag.protected voidsetEmpty(boolean state) Set the empty flag.protected voidsetId(int id) Set the ID associated with this buffer.intunsignedCompareTo(byte[] otherData, int offset, int len) Perform an unsigned data comparisonstatic booleanvoid
-
Field Details
-
serialVersionUID
public static final long serialVersionUID- See Also:
-
COMPRESSED_SERIAL_OUTPUT_PROPERTY
- See Also:
-
data
protected byte[] data
-
-
Constructor Details
-
DataBuffer
public DataBuffer()Constructor for de-serialization -
DataBuffer
protected DataBuffer(int bufsize) Construct a data buffer. A new binary buffer is created.- Parameters:
bufsize- buffer size
-
DataBuffer
protected DataBuffer(byte[] data) Construct a data buffer.- Parameters:
data- binary storage array for this buffer.
-
-
Method Details
-
enableCompressedSerializationOutput
public static void enableCompressedSerializationOutput(boolean enable) -
usingCompressedSerializationOutput
public static boolean usingCompressedSerializationOutput() -
getData
protected byte[] getData()Get the storage array associated with this buffer.- Returns:
- byte storage array.
-
setData
protected void setData(byte[] data) Get the storage array associated with this buffer. -
getId
public int getId()Get the ID associated with this buffer. -
setId
protected void setId(int id) Set the ID associated with this buffer.- Parameters:
id- buffer ID
-
isDirty
public boolean isDirty()Return true if this buffer contains modified data. When this buffer is released to the BufferMgr, the data is consumed and this flag reset to false. -
setDirty
protected void setDirty(boolean state) Set the dirty flag.- Parameters:
state- flag state.
-
isEmpty
public boolean isEmpty()Return true if this buffer is empty/unused. Writing to empty buffer does not change the state of this flag. -
setEmpty
protected void setEmpty(boolean state) Set the empty flag.- Parameters:
state- flag state
-
length
public int length()Description copied from interface:BufferGet the length of the buffer in bytes. The length reflects the number of bytes which have been allocated to the buffer. -
get
public void get(int offset, byte[] bytes, int dataOffset, int length) throws IndexOutOfBoundsException Description copied from interface:BufferGet the byte data located at the specified offset and store into the data array at the specified data offset.- Specified by:
getin interfaceBuffer- Parameters:
offset- byte offset from the start of the buffer.bytes- 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.
-
get
public void get(int offset, byte[] bytes) Description copied from interface:BufferGet the byte data located at the specified offset and store into the bytes array provided. -
get
Description copied from interface:BufferGet the byte data located at the specified offset.- Specified by:
getin 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.
-
getByte
public byte getByte(int offset) Description copied from interface:BufferGet the 8-bit byte value located at the specified offset. -
getInt
public int getInt(int offset) Description copied from interface:BufferGet the 32-bit integer value located at the specified offset. -
getShort
public short getShort(int offset) Description copied from interface:BufferGet the 16-bit short value located at the specified offset. -
getLong
public long getLong(int offset) Description copied from interface:BufferGet the 64-bit long value located at the specified offset. -
put
public int put(int offset, byte[] bytes, int dataOffset, int length) Description copied from interface:BufferPut 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:
putin interfaceBuffer- 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.- Returns:
- the next available offset into the buffer, or -1 if the buffer is full.
-
put
public int put(int offset, byte[] bytes) Description copied from interface:BufferPut the bytes provided into the buffer at the specified offset. The number of bytes stored is determined by the length of the bytes array. -
putByte
public int putByte(int offset, byte b) Description copied from interface:BufferPut the 8-bit byte value into the buffer at the specified offset. -
putInt
public int putInt(int offset, int v) Description copied from interface:BufferPut the 32-bit integer value into the buffer at the specified offset. -
putShort
public int putShort(int offset, short v) Description copied from interface:BufferPut the 16-bit short value into the buffer at the specified offset. -
putLong
public int putLong(int offset, long v) Description copied from interface:BufferPut the 64-bit long value into the buffer at the specified offset. -
clear
public void clear()Sets all the values in the buffer to 0; -
move
public void move(int src, int dest, int length) Move the data within this buffer.- Parameters:
src- source offset within this bufferdest- destination offset within this bufferlength- length of data to be moved- Throws:
IndexOutOfBoundsException- is thrown if parameters result in data access beyond the buffer size.
-
copy
Copy data from another buffer into this buffer.- Parameters:
offset- offset within this buffer.buf- source bufferbufOffset- source buffer offsetlength- amount of data to copy.- Throws:
IndexOutOfBoundsException- is thrown if parameters result in data access beyond the buffer size.
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
unsignedCompareTo
public int unsignedCompareTo(byte[] otherData, int offset, int len) Perform an unsigned data comparison- Parameters:
otherData- other data to be comparedoffset- offset within this bufferlen- length of data within this buffer- Returns:
- unsigned comparison result
- Throws:
IndexOutOfBoundsException- if specified region is not contained within this buffer.
-