public abstract class BufferByteArray extends Object
ByteArray
backed by a IoBuffer
. This class
is abstract. Subclasses need to override the free()
method. An
implementation backed by a heap IoBuffer
can be created with
a SimpleByteArrayFactory
.ByteArray.Cursor
Modifier and Type | Field and Description |
---|---|
protected IoBuffer |
bb
The backing
IoBuffer . |
Constructor and Description |
---|
BufferByteArray(IoBuffer bb)
Creates a new instance of BufferByteArray and uses the supplied
IoBuffer to back this class |
Modifier and Type | Method and Description |
---|---|
ByteArray.Cursor |
cursor()
Get a cursor starting at index 0 (which may not be the start of the array).
|
ByteArray.Cursor |
cursor(int index)
Get a cursor starting at the given index.
|
boolean |
equals(Object other)
A ByteArray is equal to another ByteArray if they start and end at the
same index, have the same byte order, and contain the same bytes at each
index.
|
int |
first()
Get the index of the first byte that can be accessed.
|
abstract 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 other)
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. |
float |
getFloat(int index)
Gets a
float from the given index. |
int |
getInt(int index)
Gets an
int from the given index. |
Iterable<IoBuffer> |
getIoBuffers()
Get the sequence of
IoBuffer s 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.
|
int |
length()
Gets the total number of bytes that can be accessed.
|
ByteOrder |
order()
Gets the order of the bytes.
|
void |
order(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 other)
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 |
slice(int index,
int length)
Creates an array with a view of part of this array.
|
public BufferByteArray(IoBuffer bb)
IoBuffer
to back this classbb
- The backing bufferpublic Iterable<IoBuffer> getIoBuffers()
IoBuffer
s that back this array.
Compared to getSingleIoBuffer()
, this method should be
relatively efficient for all implementations.public IoBuffer getSingleIoBuffer()
IoBuffer
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 slice(int index, int length)
free()
on the returned slice has no effect.public abstract void free()
public ByteArray.Cursor cursor()
public ByteArray.Cursor cursor(int index)
public int first()
public int last()
public byte get(int index)
byte
from the given index.public void put(int index, byte b)
byte
at the given index.public void get(int index, IoBuffer other)
IoBuffer
from the given index.public short getShort(int index)
short
from the given index.public void putShort(int index, short s)
short
at the given index.public int getInt(int index)
int
from the given index.public void putInt(int index, int i)
int
at the given index.public long getLong(int index)
long
from the given index.public void putLong(int index, long l)
long
at the given index.public float getFloat(int index)
float
from the given index.public void putFloat(int index, float f)
float
at the given index.public double getDouble(int index)
double
from the given index.public void putDouble(int index, double d)
double
at the given index.public char getChar(int index)
char
from the given index.public void putChar(int index, char c)
char
at the given index.public final int length()
length
in interface IoAbsoluteReader
Copyright © 2004–2015 Apache MINA Project. All rights reserved.