Top Description Methods
org.glassfish.grizzly

public Interface Buffer

extends Comparable<Buffer>, WritableMessage
Known Direct Subinterfaces
org.glassfish.grizzly.memory.PooledMemoryManager.PoolBuffer
Known Direct Implementers
org.glassfish.grizzly.memory.ByteBufferWrapper, org.glassfish.grizzly.memory.CompositeBuffer, org.glassfish.grizzly.memory.HeapBuffer
Imports
java.nio.BufferOverflowException, .BufferUnderflowException, .ByteBuffer, .ByteOrder, .InvalidMarkException, .ReadOnlyBufferException, java.nio.charset.Charset, org.glassfish.grizzly.asyncqueue.WritableMessage, org.glassfish.grizzly.memory.BufferArray, .ByteBufferArray, .CompositeBuffer

JDK ByteBuffer was taken as base for Grizzly Buffer interface, but Buffer has several extensions: it's possible to prepend some data to a Buffer and release Buffer, when it's not required any more.
Author
Alexey Stashok

Method Summary

Modifier and TypeMethod and Description
public boolean
public void
allowBufferDispose(boolean allowBufferDispose)

public byte[]

Returns:

The array that backs this buffer
array
()

Returns the byte array that backs this buffer (optional operation).

public int

Returns:

The offset within this buffer's array of the first element of the buffer
arrayOffset
()

Returns the offset within this buffer's backing array of the first element of the buffer (optional operation).

public Buffer

Returns:

The new, read-only Buffer
asReadOnlyBuffer
()

Creates a new, read-only Buffer that shares this buffer's content.

public int

Returns:

The capacity of this buffer
capacity
()

Returns this buffer's capacity.

public Buffer

Returns:

This buffer
clear
()

Clears this buffer.

public Buffer

Returns:

This buffer
compact
()

Compacts this buffer  (optional operation).

public void
dispose()

Notify the allocator that the space for this Buffer is no longer needed.

public void
dumpHex(final Appendable
the Appendable to dump this Buffer's content to.
appendable
)

Generate a hex dump of this Buffer's content.

public Buffer

Returns:

The new Buffer
duplicate
()

Creates a new Buffer that shares this buffer's content.

public Buffer

Returns:

This buffer
flip
()

Flips this buffer.

public byte

Returns:

The byte at the buffer's current position
get
()

Relative get method.

public byte

Returns:

The byte at the given index
get
(int
The index from which the byte will be read
index
)

Absolute get method.

public Buffer

Returns:

This buffer
get
(byte[]
destination array to put the bytes into
dst
)

Relative bulk get method.

public Buffer

Returns:

This buffer
get
(byte[]
The array into which bytes are to be written
dst
,
int
The offset within the array of the first byte to be written; must be non-negative and no larger than dst.length
offset
,
int
The maximum number of bytes to be written to the given array; must be non-negative and no larger than dst.length - offset
length
)

Relative bulk get method.

public Buffer

Returns:

This buffer
get
(ByteBuffer
destination ByteBuffer to put the data into
dst
)

Relative bulk get method.

public Buffer

Returns:

This buffer
get
(ByteBuffer
The ByteBuffer into which bytes are to be written
dst
,
int
The offset within the ByteBuffer of the first byte to be written; must be non-negative and no larger than dst.remaining()
offset
,
int
The maximum number of bytes to be written to the given array; must be non-negative and no larger than dst.remaining() - offset
length
)

Relative bulk get method.

public char

Returns:

The char value at the buffer's current position
getChar
()

Relative get method for reading a char value.

public char

Returns:

The char value at the given index
getChar
(int
The index from which the bytes will be read
index
)

Absolute get method for reading a char value.

public double

Returns:

The double value at the buffer's current position
getDouble
()

Relative get method for reading a double value.

public double

Returns:

The double value at the given index
getDouble
(int
The index from which the bytes will be read
index
)

Absolute get method for reading a double value.

public float

Returns:

The float value at the buffer's current position
getFloat
()

Relative get method for reading a float value.

public float

Returns:

The float value at the given index
getFloat
(int
The index from which the bytes will be read
index
)

Absolute get method for reading a float value.

public int

Returns:

The int value at the buffer's current position
getInt
()

Relative get method for reading an int value.

public int

Returns:

The int value at the given index
getInt
(int
The index from which the bytes will be read
index
)

Absolute get method for reading an int value.

public long

Returns:

The long value at the buffer's current position
getLong
()

Relative get method for reading a long value.

public long

Returns:

The long value at the given index
getLong
(int
The index from which the bytes will be read
index
)

Absolute get method for reading a long value.

public short

Returns:

The short value at the buffer's current position
getShort
()

Relative get method for reading a short value.

public short

Returns:

The short value at the given index
getShort
(int
The index from which the bytes will be read
index
)

Absolute get method for reading a short value.

public boolean

Returns:

true if, and only if, this buffer is backed by an array and is not read-only
hasArray
()

Tells whether or not this buffer is backed by an accessible byte array.

public boolean

Returns:

true if, and only if, there is at least one element remaining in this buffer
hasRemaining
()

Redeclares org.glassfish.grizzly.asyncqueue.WritableMessage.hasRemaining.

Tells whether there are any elements between the current position and the limit.

public boolean
isComposite()

Returns: true if this Buffer represents a composite of individual Buffer instances.

public boolean

Returns:

true if, and only if, this buffer is direct
isDirect
()

Tells whether or not this buffer is direct.

public boolean

Returns:

true if, and only if, this buffer is read-only
isReadOnly
()

Tells whether or not this buffer is read-only.

public int

Returns:

The limit of this buffer
limit
()

Returns this buffer's limit.

public Buffer

Returns:

This buffer
limit
(int
The new limit value; must be non-negative and no larger than this buffer's capacity
newLimit
)

Sets this buffer's limit.

public Buffer

Returns:

This buffer
mark
()

Sets this buffer's mark at its position.

public ByteOrder

Returns:

This buffer's byte order
order
()

Retrieves this buffer's byte order.

public Buffer

Returns:

This buffer
order
(ByteOrder
The new byte order, either BIG_ENDIAN or LITTLE_ENDIAN
bo
)

Modifies this buffer's byte order.

public int

Returns:

The position of this buffer
position
()

Returns this buffer's position.

public Buffer

Returns:

This buffer
position
(int
The new position value; must be non-negative and no larger than the current limit
newPosition
)

Sets this buffer's position.

public Buffer

Returns:

the new buffer
prepend
(Buffer
the data to prepend
header
)

Prepend data from header.position() to header.limit() to the current buffer.

public Buffer

Returns:

This buffer
put
(byte
The byte to be written
b
)

Relative put method  (optional operation).

public Buffer

Returns:

This buffer
put
(int
The index at which the byte will be written
index
,
byte
The byte value to be written
b
)

Absolute put method  (optional operation).

public Buffer

Returns:

This buffer
put
(Buffer
The source buffer from which bytes are to be read; must not be this buffer
src
)

Relative bulk put method  (optional operation).

public Buffer

Returns:

This buffer
put
(Buffer
The source buffer from which bytes are to be read; must not be this buffer
src
,
int
starting position in the source buffer
position
,
int
number of bytes to be copied
length
)

Relative bulk put method  (optional operation).

public Buffer

Returns:

This buffer
put
(ByteBuffer
The source buffer from which bytes are to be read; must not be this buffer
src
)

Relative bulk put method  (optional operation).

public Buffer

Returns:

This buffer
put
(ByteBuffer
The source buffer from which bytes are to be read; must not be this buffer
src
,
int
starting position in the source buffer
position
,
int
number of bytes to be copied
length
)

Relative bulk put method  (optional operation).

public Buffer

Returns:

This buffer
put
(byte[]
source of bytes to put into the Buffer
src
)

Relative bulk put method  (optional operation).

public Buffer

Returns:

This buffer
put
(byte[]
The array from which bytes are to be read
src
,
int
The offset within the array of the first byte to be read; must be non-negative and no larger than array.length
offset
,
int
The number of bytes to be read from the given array; must be non-negative and no larger than array.length - offset
length
)

Relative bulk put method  (optional operation).

public Buffer

Returns:

This buffer
put8BitString
(String
The String from which bytes are to be read
s
)

Relative bulk put method  (optional operation).

public Buffer

Returns:

This buffer
putChar
(char
The char value to be written
value
)

Relative put method for writing a char value  (optional operation).

public Buffer

Returns:

This buffer
putChar
(int
The index at which the bytes will be written
index
,
char
The char value to be written
value
)

Absolute put method for writing a char value  (optional operation).

public Buffer

Returns:

This buffer
putDouble
(double
The double value to be written
value
)

Relative put method for writing a double value  (optional operation).

public Buffer

Returns:

This buffer
putDouble
(int
The index at which the bytes will be written
index
,
double
The double value to be written
value
)

Absolute put method for writing a double value  (optional operation).

public Buffer

Returns:

This buffer
putFloat
(float
The float value to be written
value
)

Relative put method for writing a float value  (optional operation).

public Buffer

Returns:

This buffer
putFloat
(int
The index at which the bytes will be written
index
,
float
The float value to be written
value
)

Absolute put method for writing a float value  (optional operation).

public Buffer

Returns:

This buffer
putInt
(int
The int value to be written
value
)

Relative put method for writing an int value  (optional operation).

public Buffer

Returns:

This buffer
putInt
(int
The index at which the bytes will be written
index
,
int
The int value to be written
value
)

Absolute put method for writing an int value  (optional operation).

public Buffer

Returns:

This buffer
putLong
(long
The long value to be written
value
)

Relative put method for writing a long value  (optional operation).

public Buffer

Returns:

This buffer
putLong
(int
The index at which the bytes will be written
index
,
long
The long value to be written
value
)

Absolute put method for writing a long value  (optional operation).

public Buffer

Returns:

This buffer
putShort
(short
The short value to be written
value
)

Relative put method for writing a short value  (optional operation).

public Buffer

Returns:

This buffer
putShort
(int
The index at which the bytes will be written
index
,
short
The short value to be written
value
)

Absolute put method for writing a short value  (optional operation).

public int

Returns:

The number of elements remaining in this buffer
remaining
()

Redeclares org.glassfish.grizzly.asyncqueue.WritableMessage.remaining.

Returns the number of elements between the current position and the limit.

public Buffer

Returns:

This buffer
reset
()

Resets this buffer's position to the previously-marked position.

public Buffer

Returns:

This buffer
rewind
()

Rewinds this buffer.

public void
shrink()

Disposes the buffer part, outside [position, limit] interval if possible.

public Buffer

Returns:

The new Buffer
slice
()

Creates a new Buffer whose content is a shared subsequence of this buffer's content.

public Buffer

Returns:

The new Buffer
slice
(int
the position of the start of the slice
position
,
int
the limit to take the slice up to
limit
)

Creates a new Buffer whose content is a shared subsequence of this buffer's content.

public Buffer

Returns:

the Buffer, which represents split part [splitPosition, capacity)
split
(int
position of split.
splitPosition
)

Split up the buffer into two parts: [0..splitPosition) and [splitPosition, capacity).

public BufferArray

Returns:

Returns a new BufferArray instance with this Buffer added as an element to the BufferArray.
toBufferArray
()

Returns a new BufferArray instance with this Buffer added as an element to the BufferArray.

public BufferArray

Returns:

Returns the specified BufferArray after adding this Buffer.
toBufferArray
(BufferArray
the base array to append to
array
)

Returns the specified BufferArray after adding this Buffer.

public BufferArray

Returns:

adds this Buffer and returns the specified BufferArray.
toBufferArray
(int
the new position for this Buffer
position
,
int
the new limit for this Buffer
limit
)

Updates this Buffer's position and limit and adds it to a new BufferArray instance.

public BufferArray

Returns:

adds this Buffer and returns the specified BufferArray.
toBufferArray
(BufferArray
the BufferArray to prepend to
array
,
int
the new position for this Buffer
position
,
int
the new limit for this Buffer
limit
)

Updates this Buffer's position and limit and adds it to the specified BufferArray.

public ByteBuffer

Returns:

this Buffer as a ByteBuffer.
toByteBuffer
()

Converts this Buffer to a ByteBuffer.

public ByteBuffer

Returns:

this Buffer as a ByteBuffer.
toByteBuffer
(int
the position for the starting subsequence for the returned ByteBuffer.
position
,
int
the limit for the ending of the subsequence of the returned ByteBuffer.
limit
)

Converts this Buffer to a ByteBuffer.

public ByteBufferArray

Returns:

Converts this Buffer to a ByteBuffer per toByteBuffer() and returns a ByteBufferArray containing the converted ByteBuffer.
toByteBufferArray
()

Converts this Buffer to a ByteBuffer per toByteBuffer() and returns a ByteBufferArray containing the converted ByteBuffer.

public ByteBufferArray

Returns:

returns the provided ByteBufferArray with the converted ByteBuffer added to provided array.
toByteBufferArray
(ByteBufferArray
this buffer as a ByteBufferArray
array
)

Converts this Buffer to a ByteBuffer per toByteBuffer() and adds the result to the provided ByteBufferArray.

public ByteBufferArray

Returns:

Converts this Buffer to a ByteBuffer per toByteBuffer(int, int) and returns a ByteBufferArray containing the converted ByteBuffer.
toByteBufferArray
(int
the start position within the source buffer
position
,
int
the limit, or number, of bytes to include in the resulting ByteBuffer
limit
)

Converts this Buffer to a ByteBuffer per toByteBuffer(int, int) and returns a ByteBufferArray containing the converted ByteBuffer.

public ByteBufferArray

Returns:

returns the provided ByteBufferArray with the converted ByteBuffer added to provided array.
toByteBufferArray
(ByteBufferArray
the ByteBufferArray to append this to
array
,
int
the start position within the source buffer
position
,
int
the limit, or number, of bytes to include in the resulting ByteBuffer
limit
)

Converts this Buffer to a ByteBuffer per toByteBuffer(int, int) and adds the result to the provided ByteBufferArray.

public String

Returns:

String representation of this Buffer content.
toStringContent
()

Returns Buffer content as String, using default Charset

public String

Returns:

String representation of this Buffer content.
toStringContent
(Charset
the Charset, which will be use for byte[] -> String transformation.
charset
)

Returns Buffer content as String

public String

Returns:

String representation of part of this Buffer.
toStringContent
(Charset
the Charset, which will be use for byte[] -> String transformation.
charset
,
int
the first byte offset in the Buffer (inclusive)
position
,
int
the last byte offset in the Buffer (exclusive)
limit
)

Returns Buffer's chunk content as String

public void
trim()

Trim the buffer by reducing capacity to position, if possible.

public boolean

Returns:

true if successfully disposed
tryDispose
()

Try to dispose Buffer if it's allowed.

public Object

Returns:

the underlying buffer
underlying
()

Return the underlying buffer

Inherited from java.lang.Comparable:
compareTo
Inherited from org.glassfish.grizzly.asyncqueue.WritableMessage:
isExternalrelease