public class GrowableDataBuffer
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
GrowableDataBuffer.WeakLink |
Modifier and Type | Field and Description |
---|---|
(package private) static GrowableDataBuffer.WeakLink |
buflist |
(package private) static int |
MAX_VAL_GROW |
(package private) static int |
MIN_OBJ_GROW |
(package private) java.lang.Object[] |
objs |
(package private) int |
readobjpos |
(package private) int |
readvalpos |
(package private) int |
saveobjpos |
(package private) int |
savevalpos |
(package private) static int |
VAL_GROW_QUANTUM |
(package private) byte[] |
vals |
(package private) int |
writeobjpos |
(package private) int |
writevalpos |
Modifier | Constructor and Description |
---|---|
private |
GrowableDataBuffer(int initvalsize,
int initobjsize) |
Modifier and Type | Method and Description |
---|---|
void |
append(GrowableDataBuffer gdb)
Appends the contents of both the byte and
Object buffers in
the indicated GrowableDataBuffer to this object. |
private void |
ensureReadCapacity(int bytesneeded) |
private void |
ensureWriteCapacity(int newbytes) |
boolean |
getBoolean()
Decodes and returns a single boolean value from the current read
position in the byte-encoded stream and bumps the read position
past the decoded value.
|
static GrowableDataBuffer |
getBuffer(int minsize)
Retrieve a buffer with an initial byte-encoding capacity of at least
minsize bytes. |
static GrowableDataBuffer |
getBuffer(int minvals,
int minobjs)
Retrieve a buffer with an initial byte-encoding capacity of at least
minvals bytes and an initial object buffer capacity of at
least minobjs Objects. |
byte |
getByte()
Returns a single byte value from the current read
position in the byte-encoded stream and bumps the read position
past the returned value.
|
char |
getChar()
Decodes and returns a single char value from the current read
position in the byte-encoded stream and bumps the read position
past the decoded value.
|
double |
getDouble()
Decodes and returns a single double value from the current read
position in the byte-encoded stream and bumps the read position
past the decoded value.
|
float |
getFloat()
Decodes and returns a single float value from the current read
position in the byte-encoded stream and bumps the read position
past the decoded value.
|
int |
getInt()
Decodes and returns a single int value from the current read
position in the byte-encoded stream and bumps the read position
past the decoded value.
|
long |
getLong()
Decodes and returns a single long value from the current read
position in the byte-encoded stream and bumps the read position
past the decoded value.
|
java.lang.Object |
getObject()
Returns a single
Object from the current object read
position in the Object stream and bumps the read position
past the returned value. |
short |
getShort()
Decodes and returns a single short value from the current read
position in the byte-encoded stream and bumps the read position
past the decoded value.
|
int |
getUByte()
Decodes a single unsigned byte value from the current read
position in the byte-encoded stream and returns the value cast to
an int and bumps the read position
past the decoded value.
|
boolean |
hasObjects()
Indicates whether or not there are objects in the object
buffer waiting to be read.
|
boolean |
hasValues()
Indicates whether or not there are values in the byte-encoding
buffer waiting to be read.
|
boolean |
isEmpty()
Indicates whether the byte-encoding buffer is completely empty.
|
int |
objectCapacity()
The capacity, in objects, of the
Object buffer. |
byte |
peekByte(int i)
Read a single byte from the byte-encoded stream, ignoring any read
position, but honoring the current write position as a limit.
|
java.lang.Object |
peekObject(int i)
Read a single
Object from the object buffer, ignoring any read
position, but honoring the current write position as a limit. |
void |
putBoolean(boolean b)
Encode a boolean value and write it to the end of the byte-encoding array
|
void |
putByte(byte b)
Write a byte value to the end of the byte-encoding array
|
void |
putChar(char c)
Encode a char value and write it to the end of the byte-encoding array
|
void |
putDouble(double d)
Encode a double value and write it to the end of the byte-encoding array
|
void |
putFloat(float f)
Encode a float value and write it to the end of the byte-encoding array
|
void |
putInt(int i)
Encode an int value and write it to the end of the byte-encoding array
|
void |
putLong(long l)
Encode a long value and write it to the end of the byte-encoding array
|
void |
putObject(java.lang.Object o)
Write an
Object to the end of the object array |
void |
putShort(short s)
Encode a short value and write it to the end of the byte-encoding array
|
int |
readObjectPosition()
The location of the next object to be read from the object buffer.
|
int |
readValuePosition()
The location of the next byte to be read from the encoded value
buffer.
|
void |
reset()
Clears out all data and resets all positions to the start of the
buffers so that a new sequence of writing, then reading of data
and objects can begin.
|
void |
restore()
Restore the read positions of both the byte-encoding buffer and
the
Object buffer to their last saved positions. |
static void |
returnBuffer(GrowableDataBuffer retgdb)
Return the indicated
GrowableDataBuffer object to the pool
for reuse. |
void |
save()
Save aside the current read positions of both the byte-encoding
buffer and the
Object buffer for a later restore()
operation. |
int |
valueCapacity()
The capacity, in bytes, of the byte-encoding buffer.
|
int |
writeObjectPosition()
The location of the next object to be written to the object buffer.
|
int |
writeValuePosition()
The location of the next byte to be written to the encoded value
buffer.
|
static final int VAL_GROW_QUANTUM
static final int MAX_VAL_GROW
static final int MIN_OBJ_GROW
static GrowableDataBuffer.WeakLink buflist
byte[] vals
int writevalpos
int readvalpos
int savevalpos
java.lang.Object[] objs
int writeobjpos
int readobjpos
int saveobjpos
public static GrowableDataBuffer getBuffer(int minsize)
minsize
bytes.
The initial capacity of the object buffer will be the default size.minsize
- the minimum initial size of the byte-encoding bufferGrowableDataBuffer
object of the requested sizepublic static GrowableDataBuffer getBuffer(int minvals, int minobjs)
minvals
bytes and an initial object buffer capacity of at
least minobjs
Objects.minvals
- the minimum initial size of the byte-encoding bufferminobjs
- the minimum initial size of the Object bufferGrowableDataBuffer
object of the requested sizespublic static void returnBuffer(GrowableDataBuffer retgdb)
GrowableDataBuffer
object to the pool
for reuse.
A given GrowableDataBuffer
object should only be returned to
the pool once per retrieval from the getBuffer()
methods.gdb
- the GrowableDataBuffer
object to be reused.public int readValuePosition()
writeValuePosition()
.public int writeValuePosition()
public int readObjectPosition()
writeObjectPosition()
.public int writeObjectPosition()
public int valueCapacity()
public int objectCapacity()
Object
buffer.Object
bufferpublic void save()
Object
buffer for a later restore()
operation.public void restore()
Object
buffer to their last saved positions.public boolean hasValues()
public boolean hasObjects()
public boolean isEmpty()
public void reset()
Object
array is cleared to nulls here and
those objects will finally become collectable by the garbage collector.public void append(GrowableDataBuffer gdb)
Object
buffers in
the indicated GrowableDataBuffer
to this object.
The data in the other indicated GrowableDataBuffer
object
is not disturbed in any way.gdb
- the GrowableDataBuffer
to append to this objectprivate void ensureWriteCapacity(int newbytes)
private void ensureReadCapacity(int bytesneeded)
public void putBoolean(boolean b)
b
- the boolean value to be writtenpublic void putByte(byte b)
b
- the byte value to be writtenpublic void putChar(char c)
c
- the char value to be writtenpublic void putShort(short s)
s
- the short value to be writtenpublic void putInt(int i)
i
- the int value to be writtenpublic void putLong(long l)
l
- the long value to be writtenpublic void putFloat(float f)
f
- the float value to be writtenpublic void putDouble(double d)
d
- the double value to be writtenpublic void putObject(java.lang.Object o)
Object
to the end of the object arrayo
- the Object
to be writtenpublic byte peekByte(int i)
i
- the absolute byte location to return from the byte-encoding arraypublic java.lang.Object peekObject(int i)
Object
from the object buffer, ignoring any read
position, but honoring the current write position as a limit.
The read and saved positions are not used or modified in any way
by this methodi
- the absolute index to return from the Object
arrayObject
stored at the indicated indexpublic boolean getBoolean()
public byte getByte()
public int getUByte()
public char getChar()
public short getShort()
public int getInt()
public long getLong()
public float getFloat()
public double getDouble()
public java.lang.Object getObject()
Object
from the current object read
position in the Object
stream and bumps the read position
past the returned value.Object
read from the buffer