Class CompositeByteArray
java.lang.Object
org.apache.mina.util.byteaccess.AbstractByteArray
org.apache.mina.util.byteaccess.CompositeByteArray
- All Implemented Interfaces:
ByteArray, IoAbsoluteReader, IoAbsoluteWriter
A ByteArray composed of other ByteArrays. Optimized for fast relative access
via cursors. Absolute access methods are provided, but may perform poorly.
TODO: Write about laziness of cursor implementation - how movement doesn't
happen until actual get/put.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classstatic interfaceAllows for efficient detection of component boundaries when using a cursor.Nested classes/interfaces inherited from interface ByteArray
ByteArray.Cursor -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteArrayListStores the underlyingByteArrays.private final ByteArrayFactoryMay be used ingetSingleIoBuffer.private ByteOrderThe byte order for data in the buffer -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of CompositeByteArray.CompositeByteArray(ByteArrayFactory byteArrayFactory) Creates a new instance of CompositeByteArray. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specifiedByteArrayto the first position in the listprivate voidThis method should be called prior to adding any componentByteArrayto a composite.voidAdds the specifiedByteArrayto the end of the listcursor()cursor(int index) cursor(int index, CompositeByteArray.CursorListener listener) Get a cursor starting at the given index and with the given listener.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.intfirst()voidfree()Remove any resources associated with this object.byteget(int index) voidGets enough bytes to fill theIoBufferfrom the given index.chargetChar(int index) doublegetDouble(int index) getFirst()floatgetFloat(int index) intgetInt(int index) longgetLong(int index) shortgetShort(int index) inthashCode()intlast()order()voidSet the byte order of the array.voidput(int index, byte b) Puts abyteat the given index.voidPuts bytes from theIoBufferat the given index.voidputChar(int index, char c) Puts acharat the given index.voidputDouble(int index, double d) Puts adoubleat the given index.voidputFloat(int index, float f) Puts afloatat the given index.voidputInt(int index, int i) Puts anintat the given index.voidputLong(int index, long l) Puts alongat the given index.voidputShort(int index, short s) Puts ashortat the given index.Remove the firstByteArrayin the listRemoves the lastByteArrayin the listremoveTo(int index) Remove componentByteArrays to the given index (splitting them if necessary) and returning them in a singleByteArray.slice(int index, int length) Creates an array with a view of part of this array.Methods inherited from class AbstractByteArray
equals, length
-
Field Details
-
bas
Stores the underlyingByteArrays. -
order
The byte order for data in the buffer -
byteArrayFactory
May be used ingetSingleIoBuffer. Optional.
-
-
Constructor Details
-
CompositeByteArray
public CompositeByteArray()Creates a new instance of CompositeByteArray. -
CompositeByteArray
Creates a new instance of CompositeByteArray.- Parameters:
byteArrayFactory- The factory used to create the ByteArray objects
-
-
Method Details
-
getFirst
-
addFirst
-
removeFirst
-
removeTo
Remove componentByteArrays to the given index (splitting them if necessary) and returning them in a singleByteArray. The caller is responsible for freeing the returned object. TODO: Document free behaviour more thoroughly.- Parameters:
index- The index from where we will remove bytes- Returns:
- The resulting byte aaay
-
addLast
-
removeLast
-
free
public void free()Remove any resources associated with this object. Using the object after this method is called may result in undefined behaviour. -
getIoBuffers
-
getSingleIoBuffer
- Returns:
- a single
IoBufferthat 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.
-
cursor
- Returns:
- a cursor starting at index 0 (which may not be the start of the array).
-
cursor
- Parameters:
index- The starting point- Returns:
- a cursor starting at the given index.
-
cursor
Get a cursor starting at index 0 (which may not be the start of the array) and with the given listener.- Parameters:
listener- The listener to use- Returns:
- a new
ByteArray.Cursorinstance
-
cursor
Get a cursor starting at the given index and with the given listener.- Parameters:
index- The position of the array to start the Cursor atlistener- The listener for the Cursor that is returned- Returns:
- The created Cursor
-
slice
Creates an array with a view of part of this array.- Parameters:
index- The starting positionlength- The number of bytes to copy- Returns:
- The ByteArray that is a view on the original array
-
get
public byte get(int index) - Parameters:
index- The starting position- Returns:
- a
bytefrom the given index.
-
put
public void put(int index, byte b) Puts abyteat the given index.- Parameters:
index- The positionb- The byte to put
-
get
Gets enough bytes to fill theIoBufferfrom the given index.- Parameters:
index- The starting positionbb- The IoBuffer that will be filled with the bytes
-
put
Puts bytes from theIoBufferat the given index.- Parameters:
index- The positionbb- The bytes to put
-
first
public int first()- Returns:
- the index of the first byte that can be accessed.
-
last
public int last()- Returns:
- the index after the last byte that can be accessed.
-
addHook
This method should be called prior to adding any componentByteArrayto a composite.- Parameters:
ba- The component to add.
-
order
- Returns:
- the order of the bytes.
-
order
Set the byte order of the array.- Parameters:
order- The ByteOrder to use
-
getShort
public short getShort(int index) - Parameters:
index- The starting position- Returns:
- a
shortfrom the given index.
-
putShort
public void putShort(int index, short s) Puts ashortat the given index.- Parameters:
index- The positions- The short to put
-
getInt
public int getInt(int index) - Parameters:
index- The starting position- Returns:
- an
intfrom the given index.
-
putInt
public void putInt(int index, int i) Puts anintat the given index.- Parameters:
index- The positioni- The int to put
-
getLong
public long getLong(int index) - Parameters:
index- The starting position- Returns:
- a
longfrom the given index.
-
putLong
public void putLong(int index, long l) Puts alongat the given index.- Parameters:
index- The positionl- The long to put
-
getFloat
public float getFloat(int index) - Parameters:
index- The starting position- Returns:
- a
floatfrom the given index.
-
putFloat
public void putFloat(int index, float f) Puts afloatat the given index.- Parameters:
index- The positionf- The float to put
-
getDouble
public double getDouble(int index) - Parameters:
index- The starting position- Returns:
- a
doublefrom the given index.
-
putDouble
public void putDouble(int index, double d) Puts adoubleat the given index.- Parameters:
index- The positiond- The doubvle to put
-
getChar
public char getChar(int index) - Parameters:
index- The starting position- Returns:
- a
charfrom the given index.
-
putChar
public void putChar(int index, char c) Puts acharat the given index.- Parameters:
index- The positionc- The char to put
-
hashCode
public int hashCode()- Specified by:
hashCodein classAbstractByteArray
-