APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.javafx.sg.prism

public Class GrowableDataBuffer

extends Object
Class Inheritance
Imports
java.lang.ref.WeakReference, java.nio.BufferOverflowException, java.util.Arrays

A growable buffer that can contain both byte-encoded primitive values and a list of Objects stored for communication between a writer that fills it with data and a reader that empties the data behind the writer. Both buffers (the byte-encoded array and the Object array) grow as needed with no hard limits and the two are kept separately so it is up to the reader and writer to read the two streams in a predetermined synchronicity of the two streams. The methods on a given GrowableDataBuffer object are not synchronized or thread-safe and writing to or reading from the object from more than one thread at a time is unsupported. In particular, multiple writer threads and/or multiple reader threads will definitely cause problems. The static getBuffer() factory methods and the static returnBuffer() method are all synchronized so that they can be called from any thread at any time, but any given buffer should only be returned to the pool once.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static GrowableDataBuffer.WeakLink
pack-priv static final int
pack-priv static final int
pack-priv Object[]
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv static final int
pack-priv byte[]
pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
private
GrowableDataBuffer(int initvalsize, int initobjsize)

Method Summary

Modifier and TypeMethod and Description
public void
append(GrowableDataBuffer
the GrowableDataBuffer to append to this object
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)

public boolean

Returns:

the decoded boolean value
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.

public static GrowableDataBuffer

Returns:

a GrowableDataBuffer object of the requested size
getBuffer
(int
the minimum initial size of the byte-encoding buffer
minsize
)

Retrieve a buffer with an initial byte-encoding capacity of at least minsize bytes.

public static synchronized GrowableDataBuffer

Returns:

a GrowableDataBuffer object of the requested sizes
getBuffer
(int
the minimum initial size of the byte-encoding buffer
minvals
,
int
the minimum initial size of the Object buffer
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.

public byte

Returns:

the decoded byte value
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.

public char

Returns:

the decoded char value
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.

public double

Returns:

the decoded double value
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.

public float

Returns:

the decoded float value
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.

public int

Returns:

the decoded int value
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.

public long

Returns:

the decoded long value
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.

public Object

Returns:

the Object read from the buffer
getObject
()

Returns a single Object from the current object read position in the Object stream and bumps the read position past the returned value.

public short

Returns:

the decoded short value
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.

public int

Returns:

the decoded unsigned byte value as an 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.

public boolean

Returns:

true iff there are objects to be read
hasObjects
()

Indicates whether or not there are objects in the object buffer waiting to be read.

public boolean

Returns:

true iff there are data values to be read
hasValues
()

Indicates whether or not there are values in the byte-encoding buffer waiting to be read.

public boolean

Returns:

true iff there is no data at all stored in the byte buffer
isEmpty
()

Indicates whether the byte-encoding buffer is completely empty.

public int

Returns:

the capacity of the Object buffer
objectCapacity
()

The capacity, in objects, of the Object buffer.

public byte

Returns:

the byte stored at the indicated location in the byte array
peekByte
(int
the absolute byte location to return from the byte-encoding array
i
)

Read a single byte from the byte-encoded stream, ignoring any read position, but honoring the current write position as a limit.

public Object

Returns:

the Object stored at the indicated index
peekObject
(int
the absolute index to return from the Object array
i
)

Read a single Object from the object buffer, ignoring any read position, but honoring the current write position as a limit.

public void
putBoolean(boolean
the boolean value to be written
b
)

Encode a boolean value and write it to the end of the byte-encoding array

public void
putByte(byte
the byte value to be written
b
)

Write a byte value to the end of the byte-encoding array

public void
putChar(char
the char value to be written
c
)

Encode a char value and write it to the end of the byte-encoding array

public void
putDouble(double
the double value to be written
d
)

Encode a double value and write it to the end of the byte-encoding array

public void
putFloat(float
the float value to be written
f
)

Encode a float value and write it to the end of the byte-encoding array

public void
putInt(int
the int value to be written
i
)

Encode an int value and write it to the end of the byte-encoding array

public void
putLong(long
the long value to be written
l
)

Encode a long value and write it to the end of the byte-encoding array

public void
putObject(Object
the Object to be written
o
)

Write an Object to the end of the object array

public void
putShort(short
the short value to be written
s
)

Encode a short value and write it to the end of the byte-encoding array

public int

Returns:

the position of the next object to be read.
readObjectPosition
()

The location of the next object to be read from the object buffer.

public int

Returns:

the byte position of the next byte data to be read.
readValuePosition
()

The location of the next byte to be read from the encoded value buffer.

public 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.

public void
restore()

Restore the read positions of both the byte-encoding buffer and the Object buffer to their last saved positions.

public static synchronized void
returnBuffer(GrowableDataBuffer retgdb)

Return the indicated GrowableDataBuffer object to the pool for reuse.

public void
save()

Save aside the current read positions of both the byte-encoding buffer and the Object buffer for a later restore() operation.

public int

Returns:

the capacity of the byte-encoding buffer
valueCapacity
()

The capacity, in bytes, of the byte-encoding buffer.

public int

Returns:

the position of the next object to be written.
writeObjectPosition
()

The location of the next object to be written to the object buffer.

public int

Returns:

the byte position of the next byte data to be written.
writeValuePosition
()

The location of the next byte to be written to the encoded value buffer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

buflistback to summary
pack-priv static GrowableDataBuffer.WeakLink buflist
MAX_VAL_GROWback to summary
pack-priv static final int MAX_VAL_GROW
MIN_OBJ_GROWback to summary
pack-priv static final int MIN_OBJ_GROW
objsback to summary
pack-priv Object[] objs
readobjposback to summary
pack-priv int readobjpos
readvalposback to summary
pack-priv int readvalpos
saveobjposback to summary
pack-priv int saveobjpos
savevalposback to summary
pack-priv int savevalpos
VAL_GROW_QUANTUMback to summary
pack-priv static final int VAL_GROW_QUANTUM
valsback to summary
pack-priv byte[] vals
writeobjposback to summary
pack-priv int writeobjpos
writevalposback to summary
pack-priv int writevalpos

Constructor Detail

GrowableDataBufferback to summary
private GrowableDataBuffer(int initvalsize, int initobjsize)

Method Detail

appendback to summary
public void append(GrowableDataBuffer gdb)

Appends the contents of both the byte and Object buffers in the indicated GrowableDataBuffer to this object. The data in the other indicated GrowableDataBuffer object is not disturbed in any way.

Parameters
gdb:GrowableDataBuffer

the GrowableDataBuffer to append to this object

ensureReadCapacityback to summary
private void ensureReadCapacity(int bytesneeded)
ensureWriteCapacityback to summary
private void ensureWriteCapacity(int newbytes)
getBooleanback to summary
public 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.

Returns:boolean

the decoded boolean value

getBufferback to summary
public static GrowableDataBuffer getBuffer(int minsize)

Retrieve a buffer with an initial byte-encoding capacity of at least minsize bytes. The initial capacity of the object buffer will be the default size.

Parameters
minsize:int

the minimum initial size of the byte-encoding buffer

Returns:GrowableDataBuffer

a GrowableDataBuffer object of the requested size

getBufferback to summary
public static synchronized 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.

Parameters
minvals:int

the minimum initial size of the byte-encoding buffer

minobjs:int

the minimum initial size of the Object buffer

Returns:GrowableDataBuffer

a GrowableDataBuffer object of the requested sizes

getByteback to summary
public 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.

Returns:byte

the decoded byte value

getCharback to summary
public 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.

Returns:char

the decoded char value

getDoubleback to summary
public 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.

Returns:double

the decoded double value

getFloatback to summary
public 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.

Returns:float

the decoded float value

getIntback to summary
public 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.

Returns:int

the decoded int value

getLongback to summary
public 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.

Returns:long

the decoded long value

getObjectback to summary
public 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.

Returns:Object

the Object read from the buffer

getShortback to summary
public 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.

Returns:short

the decoded short value

getUByteback to summary
public 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.

Returns:int

the decoded unsigned byte value as an int

hasObjectsback to summary
public boolean hasObjects()

Indicates whether or not there are objects in the object buffer waiting to be read.

Returns:boolean

true iff there are objects to be read

hasValuesback to summary
public boolean hasValues()

Indicates whether or not there are values in the byte-encoding buffer waiting to be read.

Returns:boolean

true iff there are data values to be read

isEmptyback to summary
public boolean isEmpty()

Indicates whether the byte-encoding buffer is completely empty. Note that this is different from whether or not there is unread data in the byte-encoding buffer. A buffer which has been written and then later fully emptied by reading is not considered "empty".

Returns:boolean

true iff there is no data at all stored in the byte buffer

objectCapacityback to summary
public int objectCapacity()

The capacity, in objects, of the Object buffer.

Returns:int

the capacity of the Object buffer

peekByteback to summary
public 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. The read and saved positions are not used or modified in any way by this method

Parameters
i:int

the absolute byte location to return from the byte-encoding array

Returns:byte

the byte stored at the indicated location in the byte array

peekObjectback to summary
public 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. The read and saved positions are not used or modified in any way by this method

Parameters
i:int

the absolute index to return from the Object array

Returns:Object

the Object stored at the indicated index

putBooleanback to summary
public void putBoolean(boolean b)

Encode a boolean value and write it to the end of the byte-encoding array

Parameters
b:boolean

the boolean value to be written

putByteback to summary
public void putByte(byte b)

Write a byte value to the end of the byte-encoding array

Parameters
b:byte

the byte value to be written

putCharback to summary
public void putChar(char c)

Encode a char value and write it to the end of the byte-encoding array

Parameters
c:char

the char value to be written

putDoubleback to summary
public void putDouble(double d)

Encode a double value and write it to the end of the byte-encoding array

Parameters
d:double

the double value to be written

putFloatback to summary
public void putFloat(float f)

Encode a float value and write it to the end of the byte-encoding array

Parameters
f:float

the float value to be written

putIntback to summary
public void putInt(int i)

Encode an int value and write it to the end of the byte-encoding array

Parameters
i:int

the int value to be written

putLongback to summary
public void putLong(long l)

Encode a long value and write it to the end of the byte-encoding array

Parameters
l:long

the long value to be written

putObjectback to summary
public void putObject(Object o)

Write an Object to the end of the object array

Parameters
o:Object

the Object to be written

putShortback to summary
public void putShort(short s)

Encode a short value and write it to the end of the byte-encoding array

Parameters
s:short

the short value to be written

readObjectPositionback to summary
public int readObjectPosition()

The location of the next object to be read from the object buffer. This must always be less than or equal to the writeObjectPosition().

Returns:int

the position of the next object to be read.

readValuePositionback to summary
public int readValuePosition()

The location of the next byte to be read from the encoded value buffer. This must always be less than or equal to the writeValuePosition().

Returns:int

the byte position of the next byte data to be read.

resetback to summary
public 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. Note that the Object array is cleared to nulls here and those objects will finally become collectable by the garbage collector.

restoreback to summary
public void restore()

Restore the read positions of both the byte-encoding buffer and the Object buffer to their last saved positions.

returnBufferback to summary
public static synchronized void returnBuffer(GrowableDataBuffer retgdb)

Return the indicated 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.

saveback to summary
public void save()

Save aside the current read positions of both the byte-encoding buffer and the Object buffer for a later restore() operation.

valueCapacityback to summary
public int valueCapacity()

The capacity, in bytes, of the byte-encoding buffer.

Returns:int

the capacity of the byte-encoding buffer

writeObjectPositionback to summary
public int writeObjectPosition()

The location of the next object to be written to the object buffer.

Returns:int

the position of the next object to be written.

writeValuePositionback to summary
public int writeValuePosition()

The location of the next byte to be written to the encoded value buffer.

Returns:int

the byte position of the next byte data to be written.