Package org.apache.mina.util.byteaccess
Class CompositeByteArrayRelativeReader
- java.lang.Object
-
- org.apache.mina.util.byteaccess.CompositeByteArrayRelativeReader
-
- All Implemented Interfaces:
IoRelativeReader
public class CompositeByteArrayRelativeReader extends Object implements IoRelativeReader
Provides restricted, relative, read-only access to the bytes in aCompositeByteArray
. Using this interface has the advantage that it can be automatically determined when a componentByteArray
can no longer be read, and thus components can be automatically freed. This makes it easier to use pooling for underlyingByteArray
s.- Author:
- Apache MINA Project
-
-
Field Summary
Fields Modifier and Type Field Description protected CompositeByteArray
cba
The underlyingCompositeByteArray
.protected ByteArray.Cursor
cursor
A cursor of the underlyingCompositeByteArray
.
-
Constructor Summary
Constructors Constructor Description CompositeByteArrayRelativeReader(CompositeByteArray cba, boolean autoFree)
Creates a new instance of CompositeByteArrayRelativeReader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(ByteArray ba)
Make aByteArray
available for access at the end of this object.protected void
cursorPassedFirstComponent()
Called whenever the cursor has passed from thecba
's first component.void
free()
Free all resources associated with this object.byte
get()
void
get(IoBuffer bb)
places the data starting at current position into the suppliedIoBuffer
char
getChar()
double
getDouble()
float
getFloat()
int
getIndex()
int
getInt()
long
getLong()
int
getRemaining()
short
getShort()
boolean
hasRemaining()
int
last()
ByteOrder
order()
void
skip(int length)
Advances the reader by the given number of bytes.ByteArray
slice(int length)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.mina.util.byteaccess.IoRelativeReader
getRemaining, hasRemaining, order
-
-
-
-
Field Detail
-
cba
protected final CompositeByteArray cba
The underlyingCompositeByteArray
.
-
cursor
protected final ByteArray.Cursor cursor
A cursor of the underlyingCompositeByteArray
. This cursor is never moved directly; its position only changes through calls to relative read or write methods.
-
-
Constructor Detail
-
CompositeByteArrayRelativeReader
public CompositeByteArrayRelativeReader(CompositeByteArray cba, boolean autoFree)
Creates a new instance of CompositeByteArrayRelativeReader.- Parameters:
cba
- The backing ByteArrayautoFree
- If data should be freed once it has been passed in the list
-
-
Method Detail
-
cursorPassedFirstComponent
protected void cursorPassedFirstComponent()
Called whenever the cursor has passed from thecba
's first component. As the first component is no longer used, this provides a good opportunity for subclasses to perform some action on it (such as freeing it).
-
skip
public void skip(int length)
Advances the reader by the given number of bytes.- Specified by:
skip
in interfaceIoRelativeReader
- Parameters:
length
- the number of bytes to skip
-
slice
public ByteArray slice(int length)
- Specified by:
slice
in interfaceIoRelativeReader
- Parameters:
length
- The number of bytes to get- Returns:
- an array with a view of part of this array.
-
get
public byte get()
- Specified by:
get
in interfaceIoRelativeReader
- Returns:
- the byte at the current position in the buffer
-
get
public void get(IoBuffer bb)
places the data starting at current position into the suppliedIoBuffer
- Specified by:
get
in interfaceIoRelativeReader
- Parameters:
bb
- The IoBuffer that will contain the read bytes
-
getShort
public short getShort()
- Specified by:
getShort
in interfaceIoRelativeReader
- Returns:
- a
short
and advances the reader.
-
getInt
public int getInt()
- Specified by:
getInt
in interfaceIoRelativeReader
- Returns:
- an
int
and advances the reader.
-
getLong
public long getLong()
- Specified by:
getLong
in interfaceIoRelativeReader
- Returns:
- a
long
and advances the reader.
-
getFloat
public float getFloat()
- Specified by:
getFloat
in interfaceIoRelativeReader
- Returns:
- a
float
and advances the reader.
-
getDouble
public double getDouble()
- Specified by:
getDouble
in interfaceIoRelativeReader
- Returns:
- a
double
and advances the reader.
-
getChar
public char getChar()
- Specified by:
getChar
in interfaceIoRelativeReader
- Returns:
- a
char
and advances the reader.
-
getRemaining
public final int getRemaining()
- Returns:
- The number of remaining bytes
-
hasRemaining
public final boolean hasRemaining()
- Returns:
- TRUE if there are some more bytes
-
order
public ByteOrder order()
- Returns:
- The used byte order (little of big indian)
-
append
public final void append(ByteArray ba)
Make aByteArray
available for access at the end of this object.- Parameters:
ba
- The ByteArray to append
-
free
public final void free()
Free all resources associated with this object.
-
getIndex
public final int getIndex()
- Returns:
- the index that will be used for the next access.
-
last
public final int last()
- Returns:
- the index after the last byte that can be accessed.
-
-