Package org.apache.mina.util.byteaccess
Class BufferByteArray
- java.lang.Object
-
- org.apache.mina.util.byteaccess.AbstractByteArray
-
- org.apache.mina.util.byteaccess.BufferByteArray
-
- All Implemented Interfaces:
ByteArray,IoAbsoluteReader,IoAbsoluteWriter
public abstract class BufferByteArray extends AbstractByteArray
AByteArraybacked by aIoBuffer. This class is abstract. Subclasses need to override thefree()method. An implementation backed by a heapIoBuffercan be created with aSimpleByteArrayFactory.- Author:
- Apache MINA Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.mina.util.byteaccess.ByteArray
ByteArray.Cursor
-
-
Constructor Summary
Constructors Constructor Description BufferByteArray(IoBuffer bb)Creates a new instance of BufferByteArray and uses the suppliedIoBufferto back this class
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteArray.Cursorcursor()ByteArray.Cursorcursor(int index)intfirst()byteget(int index)voidget(int index, IoBuffer other)Gets enough bytes to fill theIoBufferfrom the given index.chargetChar(int index)doublegetDouble(int index)floatgetFloat(int index)intgetInt(int index)Iterable<IoBuffer>getIoBuffers()longgetLong(int index)shortgetShort(int index)IoBuffergetSingleIoBuffer()inthashCode()intlast()ByteOrderorder()voidorder(ByteOrder order)Set the byte order of the array.voidput(int index, byte b)Puts abyteat the given index.voidput(int index, IoBuffer other)Puts 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.ByteArrayslice(int index, int length)Creates an array with a view of part of this array.-
Methods inherited from class org.apache.mina.util.byteaccess.AbstractByteArray
equals, length
-
-
-
-
Field Detail
-
bb
protected IoBuffer bb
The backingIoBuffer.
-
-
Method Detail
-
getIoBuffers
public Iterable<IoBuffer> getIoBuffers()
- Returns:
- the sequence of
IoBuffers that back this array. Compared togetSingleIoBuffer(), this method should be relatively efficient for all implementations.
-
getSingleIoBuffer
public IoBuffer 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.
-
slice
public ByteArray slice(int index, int length)
Creates an array with a view of part of this array. Callingfree()on the returned slice has no effect.- Parameters:
index- The starting positionlength- The number of bytes to copy- Returns:
- The ByteArray that is a view on the original array
-
cursor
public ByteArray.Cursor cursor()
- Returns:
- a cursor starting at index 0 (which may not be the start of the array).
-
cursor
public ByteArray.Cursor cursor(int index)
- Parameters:
index- The starting point- Returns:
- a cursor starting at the given index.
-
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.
-
order
public ByteOrder order()
- Returns:
- the order of the bytes.
-
order
public void order(ByteOrder order)
Set the byte order of the array.- Parameters:
order- The ByteOrder to use
-
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
public void get(int index, IoBuffer other)Gets enough bytes to fill theIoBufferfrom the given index.- Parameters:
index- The starting positionother- The IoBuffer that will be filled with the bytes
-
put
public void put(int index, IoBuffer other)Puts bytes from theIoBufferat the given index.- Parameters:
index- The positionother- The bytes to put
-
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
-
-