public final class CompositeByteArray extends AbstractByteArray
| Modifier and Type | Class and Description |
|---|---|
private class |
CompositeByteArray.CursorImpl |
static interface |
CompositeByteArray.CursorListener
Allows for efficient detection of component boundaries when using a cursor.
|
ByteArray.Cursor| Modifier and Type | Field and Description |
|---|---|
private ByteArrayList |
bas
Stores the underlying
ByteArrays. |
private ByteArrayFactory |
byteArrayFactory
May be used in
getSingleIoBuffer. |
private java.nio.ByteOrder |
order
The byte order for data in the buffer
|
| Constructor and Description |
|---|
CompositeByteArray()
Creates a new instance of CompositeByteArray.
|
CompositeByteArray(ByteArrayFactory byteArrayFactory)
Creates a new instance of CompositeByteArray.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addFirst(ByteArray ba)
Adds the specified
ByteArray to the first
position in the list |
private void |
addHook(ByteArray ba)
This method should be called prior to adding any component
ByteArray to a composite. |
void |
addLast(ByteArray ba)
Adds the specified
ByteArray to the end of the list |
private void |
checkBounds(int index,
int accessSize) |
ByteArray.Cursor |
cursor()
Get a cursor starting at index 0 (which may not be the start of the array).
|
ByteArray.Cursor |
cursor(CompositeByteArray.CursorListener listener)
Get a cursor starting at index 0 (which may not be the start of the
array) and with the given listener.
|
ByteArray.Cursor |
cursor(int index)
Get a cursor starting at the given index.
|
ByteArray.Cursor |
cursor(int index,
CompositeByteArray.CursorListener listener)
Get a cursor starting at the given index and with the given listener.
|
int |
first()
Get the index of the first byte that can be accessed.
|
void |
free()
Remove any resources associated with this object.
|
byte |
get(int index)
Gets a
byte from the given index. |
void |
get(int index,
IoBuffer bb)
Gets enough bytes to fill the
IoBuffer from the given index. |
char |
getChar(int index)
Gets a
char from the given index. |
double |
getDouble(int index)
Gets a
double from the given index. |
ByteArray |
getFirst()
Returns the first
ByteArray in the list |
float |
getFloat(int index)
Gets a
float from the given index. |
int |
getInt(int index)
Gets an
int from the given index. |
java.lang.Iterable<IoBuffer> |
getIoBuffers()
Get the sequence of
IoBuffers that back this array. |
long |
getLong(int index)
Gets a
long from the given index. |
short |
getShort(int index)
Gets a
short from the given index. |
IoBuffer |
getSingleIoBuffer()
Gets a single
IoBuffer that backs this array. |
int |
last()
Gets the index after the last byte that can be accessed.
|
java.nio.ByteOrder |
order()
Gets the order of the bytes.
|
void |
order(java.nio.ByteOrder order)
Set the byte order of the array.
|
void |
put(int index,
byte b)
Puts a
byte at the given index. |
void |
put(int index,
IoBuffer bb)
Puts bytes from the
IoBuffer at the given index. |
void |
putChar(int index,
char c)
Puts a
char at the given index. |
void |
putDouble(int index,
double d)
Puts a
double at the given index. |
void |
putFloat(int index,
float f)
Puts a
float at the given index. |
void |
putInt(int index,
int i)
Puts an
int at the given index. |
void |
putLong(int index,
long l)
Puts a
long at the given index. |
void |
putShort(int index,
short s)
Puts a
short at the given index. |
ByteArray |
removeFirst()
Remove the first
ByteArray in the list |
ByteArray |
removeLast()
Removes the last
ByteArray in the list |
ByteArray |
removeTo(int index)
Remove component
ByteArrays to the given index (splitting
them if necessary) and returning them in a single ByteArray. |
ByteArray |
slice(int index,
int length)
Creates an array with a view of part of this array.
|
equals, lengthprivate final ByteArrayList bas
ByteArrays.private java.nio.ByteOrder order
private final ByteArrayFactory byteArrayFactory
getSingleIoBuffer. Optional.public CompositeByteArray()
public CompositeByteArray(ByteArrayFactory byteArrayFactory)
byteArrayFactory - The factory used to create the ByteArray objectspublic ByteArray getFirst()
ByteArray in the listpublic void addFirst(ByteArray ba)
ByteArray to the first
position in the listba - The ByteArray to add to the listpublic ByteArray removeFirst()
ByteArray in the listpublic ByteArray removeTo(int index)
ByteArrays to the given index (splitting
them if necessary) and returning them in a single ByteArray.
The caller is responsible for freeing the returned object.
TODO: Document free behaviour more thoroughly.public void addLast(ByteArray ba)
ByteArray to the end of the listba - The ByteArray to add to the end of the listpublic ByteArray removeLast()
ByteArray in the listpublic void free()
ByteArrayprivate void checkBounds(int index,
int accessSize)
public java.lang.Iterable<IoBuffer> getIoBuffers()
ByteArrayIoBuffers that back this array.
Compared to getSingleIoBuffer(), this method should be
relatively efficient for all implementations.public IoBuffer getSingleIoBuffer()
ByteArrayIoBuffer that backs this array. Some
implementations may initially have data split across multiple buffers, so
calling this method may require a new buffer to be allocated and
populated.public ByteArray.Cursor cursor()
ByteArraypublic ByteArray.Cursor cursor(int index)
ByteArraypublic ByteArray.Cursor cursor(CompositeByteArray.CursorListener listener)
listener - Returns a new ByteArray.Cursor instancepublic ByteArray.Cursor cursor(int index, CompositeByteArray.CursorListener listener)
index - The position of the array to start the Cursor atlistener - The listener for the Cursor that is returnedpublic ByteArray slice(int index, int length)
IoAbsoluteReaderpublic byte get(int index)
IoAbsoluteReaderbyte from the given index.public void put(int index,
byte b)
IoAbsoluteWriterbyte at the given index.public void get(int index,
IoBuffer bb)
IoAbsoluteReaderIoBuffer from the given index.public void put(int index,
IoBuffer bb)
IoAbsoluteWriterIoBuffer at the given index.public int first()
IoAbsoluteReaderpublic int last()
IoAbsoluteReaderprivate void addHook(ByteArray ba)
ByteArray to a composite.ba - The component to add.public java.nio.ByteOrder order()
IoAbsoluteReaderpublic void order(java.nio.ByteOrder order)
ByteArraypublic short getShort(int index)
IoAbsoluteReadershort from the given index.public void putShort(int index,
short s)
IoAbsoluteWritershort at the given index.public int getInt(int index)
IoAbsoluteReaderint from the given index.public void putInt(int index,
int i)
IoAbsoluteWriterint at the given index.public long getLong(int index)
IoAbsoluteReaderlong from the given index.public void putLong(int index,
long l)
IoAbsoluteWriterlong at the given index.public float getFloat(int index)
IoAbsoluteReaderfloat from the given index.public void putFloat(int index,
float f)
IoAbsoluteWriterfloat at the given index.public double getDouble(int index)
IoAbsoluteReaderdouble from the given index.public void putDouble(int index,
double d)
IoAbsoluteWriterdouble at the given index.public char getChar(int index)
IoAbsoluteReaderchar from the given index.public void putChar(int index,
char c)
IoAbsoluteWriterchar at the given index.