Package db.buffers
Class DataBuffer
- java.lang.Object
-
- db.buffers.DataBuffer
-
- All Implemented Interfaces:
Buffer
,java.io.Externalizable
,java.io.Serializable
public class DataBuffer extends java.lang.Object implements Buffer, java.io.Externalizable
DataBuffer
provides an accessible binary buffer for use with a BufferMgr and BufferFile.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
COMPRESSED_SERIAL_OUTPUT_PROPERTY
protected byte[]
data
static long
serialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description DataBuffer()
Constructor for de-serializationprotected
DataBuffer(byte[] data)
Construct a data buffer.protected
DataBuffer(int bufsize)
Construct a data buffer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
readExternal(java.io.ObjectInput in)
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.static boolean
usingCompressedSerializationOutput()
void
writeExternal(java.io.ObjectOutput out)
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
- See Also:
- Constant Field Values
-
COMPRESSED_SERIAL_OUTPUT_PROPERTY
public static final java.lang.String COMPRESSED_SERIAL_OUTPUT_PROPERTY
- See Also:
- Constant Field Values
-
data
protected byte[] data
-
-
Constructor Detail
-
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 Detail
-
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 java.lang.ArrayIndexOutOfBoundsException
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:
java.lang.ArrayIndexOutOfBoundsException
- 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
public byte[] get(int offset, int length) throws java.lang.ArrayIndexOutOfBoundsException
Description copied from interface:Buffer
Get the byte data located at the specified offset.
-
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:
java.lang.ArrayIndexOutOfBoundsException
- is thrown if parameters result in data access beyond the buffer size.
-
copy
public void copy(int offset, DataBuffer buf, int bufOffset, int length)
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:
java.lang.ArrayIndexOutOfBoundsException
- is thrown if parameters result in data access beyond the buffer size.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
-