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
-
Constructor Summary
ModifierConstructorDescriptionConstructor for de-serializationprotected
DataBuffer
(byte[] data) Construct a data buffer.protected
DataBuffer
(int bufsize) Construct a data buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Sets all the values in the buffer to 0;void
copy
(int offset, DataBuffer buf, int bufOffset, int length) Copy data from another buffer into this buffer.static void
enableCompressedSerializationOutput
(boolean enable) void
get
(int offset, byte[] bytes) Get the byte data located at the specified offset and store into the bytes array provided.void
get
(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.byte
getByte
(int offset) Get the 8-bit byte value located at the specified offset.protected byte[]
getData()
Get the storage array associated with this buffer.int
getId()
Get the ID associated with this 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
isDirty()
Return true if this buffer contains modified data.boolean
isEmpty()
Return true if this buffer is empty/unused.int
length()
Get the length of the buffer in bytes.void
move
(int src, int dest, int length) Move the data within this buffer.int
put
(int offset, byte[] bytes) Put the bytes provided into the buffer at the specified offset.int
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.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
protected void
setData
(byte[] data) Get the storage array associated with this buffer.protected void
setDirty
(boolean state) Set the dirty flag.protected void
setEmpty
(boolean state) Set the empty flag.protected void
setId
(int id) Set the ID associated with this buffer.int
unsignedCompareTo
(byte[] otherData, int offset, int len) Perform an unsigned data comparisonstatic boolean
void
-
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:Buffer
Get 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: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.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:Buffer
Get the byte data located at the specified offset and store into the bytes array provided. -
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.
-
getByte
public byte getByte(int offset) Description copied from interface:Buffer
Get the 8-bit byte value located at the specified offset. -
getInt
public int getInt(int offset) Description copied from interface:Buffer
Get the 32-bit integer value located at the specified offset. -
getShort
public short getShort(int offset) Description copied from interface:Buffer
Get the 16-bit short value located at the specified offset. -
getLong
public long getLong(int offset) Description copied from interface:Buffer
Get 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: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.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: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. -
putByte
public int putByte(int offset, byte b) Description copied from interface:Buffer
Put the 8-bit byte value into the buffer at the specified offset. -
putInt
public int putInt(int offset, int v) Description copied from interface:Buffer
Put the 32-bit integer value into the buffer at the specified offset. -
putShort
public int putShort(int offset, short v) Description copied from interface:Buffer
Put the 16-bit short value into the buffer at the specified offset. -
putLong
public int putLong(int offset, long v) Description copied from interface:Buffer
Put 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:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
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.
-