org.objectweb.jonathan.resources.api
Class Chunk
A chunk represents a part of an array of bytes. Chunks are linked to form
messages that may be sent from an adress space to another. Their use avoids
unnecessarily copying arrays of bytes, and helps recovering these arrays
without resorting to garbage collection (thanks to
chunk factories
).
Chunks should not be used concurrently.
byte[] | data - The associated array of bytes.
|
Chunk | next - The next chunk in the chain
|
int | offset - The index of the first valid (written) byte in this chunk.
|
int | top - Index of the last valid (written) byte in this chunk + 1.
|
Chunk(byte[] data, int offset, int top) - Constructs a new chunk with the specified data and offsets.
|
Chunk | duplicate() - Duplicates the whole chunk.
|
Chunk | duplicate(int offset, int top) - Partially duplicates this chunk.
|
void | release() - Releases the chunk.
|
String | toString() - Returns a string representation of the target chunk.
|
data
public byte[] data
The associated array of bytes.
next
public Chunk next
The next chunk in the chain
offset
public int offset
The index of the first valid (written) byte in this chunk.
top
public int top
Index of the last valid (written) byte in this chunk + 1.
Chunk
public Chunk(byte[] data,
int offset,
int top)
Constructs a new chunk with the specified data and offsets.
data
- the byte array containing the data.offset
- the offset of the first valid byte in the chunk.top
- offset + the number of valid bytes in the chunk.
duplicate
public Chunk duplicate()
throws JonathanException
Duplicates the whole chunk.
The default implementation copies the buffer,
and creates a new chunk with it.
- a copy of this chunk.
duplicate
public Chunk duplicate(int offset,
int top)
throws JonathanException
Partially duplicates this chunk. 'offset' must be greater than
the target chunk's offset, 'top' must be less or equal than the target's top.
The default implementation copies the appropriate portion of the buffer,
and creates a new chunk with it.
offset
- the offset of the chunk copy.top
- the top of the chunk copy.
- a chunk containing the specified part of the target chunk.
release
public void release()
Releases the chunk. The data of a chunk may be obtained from managed
buffers. It may thus be necessary to tell when the data encapsulated by a
chunk may be reused.
The default implementation resets offset and top to 0.
toString
public String toString()
Returns a string representation of the target chunk.
- a string representation of the target chunk.