|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.ibm.wbi.util.ByteBufferUnsynchronized
This class is something like java.lang.StringBuffer, except
that it provides a buffer of bytes instead of char
s. The provided append methods automatically allocate
storage (when the internal capacity is exceeded) before adding data.
It's useful for building up arbitrary length byte arrays.
| Field Summary | |
static int |
DEFAULT_SIZE
The default initial capacity. |
| Constructor Summary | |
ByteBufferUnsynchronized()
Constructs a ByteBufferUnsynchronized that is initially empty. |
|
ByteBufferUnsynchronized(int cap)
Constructs a ByteBufferUnsynchronized with specified initial capacity. |
|
| Method Summary | |
void |
append(byte val)
Appends the given byte argument to this buffer. |
void |
append(byte[] bytes)
Appends the given byte array argument to this string buffer. |
void |
append(byte[] bytes,
int offset,
int length)
Appends the given byte subarray of the bytes array argument
to this buffer. |
void |
append(long val)
Appends the given long argument to this buffer. |
byte |
byteAt(int index)
Returns the byte at a specific index in this buffer. |
int |
capacity()
Returns the current capacity. |
void |
ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum. |
byte[] |
getByteArrayRef()
Return a reference to the byte array inside the buffer. |
byte[] |
getBytes()
Return a byte array of the current buffer size containing the bytes. |
void |
getBytes(int srcBegin,
int srcEnd,
byte[] dst,
int dstBegin)
Bytes are copied from this buffer into the destination byte array dst. |
void |
insert(int offset,
byte val)
Inserts the given byte argument into this buffer. |
void |
insert(int offset,
byte[] bytes)
Inserts the given byte array argument into this buffer. |
int |
length()
Returns the length (byte count). |
long |
longAt(int index)
Returns the long at a specific index in this buffer. |
void |
purge()
The current contents are released and an empty ByteBufferUnsynchronized with a default capacity of is created. |
void |
purge(int capacity)
The current contents are released and an empty ByteBufferUnsynchronized with the specified capacity is created. |
void |
setByteAt(int index,
byte val)
The byte at the specified index of this buffer is set to val
. |
void |
setLength(int newLength)
Sets the length of this buffer. |
int |
size()
Returns the length (byte count). |
void |
write(java.io.OutputStream stream)
Writes the bytes contained in the buffer to an OutputStream. |
void |
write(java.io.OutputStream stream,
int offset,
int length)
Writes some of the bytes contained in the buffer to an OutputStream. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int DEFAULT_SIZE
| Constructor Detail |
public ByteBufferUnsynchronized()
public ByteBufferUnsynchronized(int cap)
cap - Initial capacity.| Method Detail |
public void purge()
purge in interface ByteStorepublic void purge(int capacity)
purge in interface ByteStorecapacity - The initial capacity.public int length()
length in interface ByteStorepublic int size()
size in interface ByteStorepublic int capacity()
capacity in interface ByteStorepublic void ensureCapacity(int minimumCapacity)
minimumCapacity argument.2.minimumCapacity argument is nonpositive, this
method takes no action and simply returns.ensureCapacity in interface ByteStoreminimumCapacity - The minimum desired capacity.
public void setLength(int newLength)
throws java.lang.StringIndexOutOfBoundsException
newLength
argument is less than the current length of the buffer, the
buffer is truncated to contain exactly the number of characters
given by the newLength argument.
If the newLength argument is greater than or equal to the
current length, sufficient null bytes will be appended to the byte
buffer so that length becomes equal to the newLength
argument.
The newLength argument must be greater than or equal
to 0.
setLength in interface ByteStorenewLength - The new length of the buffer.java.lang.StringIndexOutOfBoundsException - The newLength
argument is invalid
public byte byteAt(int index)
throws java.lang.ArrayIndexOutOfBoundsException
The first byte of the buffer is considered to be at index
0, the next at index 1, and so on, for
array indexing.
The index argument must be greater than or equal to
0, and less than the length of this buffer.
byteAt in interface ByteStoreindex - The index of the desired byte.java.lang.ArrayIndexOutOfBoundsException - The index is invalid.
public long longAt(int index)
throws java.lang.ArrayIndexOutOfBoundsException
The first byte of the buffer is considered to be at index
0, the next at index 1, and so on, for
array indexing.
The index argument must be greater than or equal to
0, and less than the length of this buffer.
The long must be in the buffer in the format used by
our append(long val) method.
index - The index of the first byte of the desired long.java.lang.ArrayIndexOutOfBoundsException - The index is invalid.public byte[] getBytes()
getBytes in interface ByteStorepublic byte[] getByteArrayRef()
getByteArrayRef in interface ByteStore
public void getBytes(int srcBegin,
int srcEnd,
byte[] dst,
int dstBegin)
throws java.lang.ArrayIndexOutOfBoundsException
dst. The first byte to be copied is at index
srcBegin; the last byte to be copied is at index
srcEnd-1. The total number of bytes to be copied is
srcEnd-srcBegin. The bytes are copied into the subarray of
dst starting at index dstBegin and ending at
index:
dstbegin + (srcEnd-srcBegin) - 1
getBytes in interface ByteStoresrcBegin - Start copying at this offset in the buffer.srcEnd - Stop copying at this offset in the buffer.dst - The array to copy the data into.dstBegin - Offset into dst.java.lang.ArrayIndexOutOfBoundsException - There is an invalid index
into the buffer.
public void setByteAt(int index,
byte val)
throws java.lang.ArrayIndexOutOfBoundsException
val
.setByteAt in interface ByteStoreindex - The index of the byte to overwrite.val - The new byte value.java.lang.ArrayIndexOutOfBoundsException - The index is invalid.public void append(byte val)
The argument is appended to the contents of this buffer.
The length of this buffer increases by 1.
append in interface ByteStoreval - A byte value.public void append(long val)
The argument is appended to the contents of this buffer.
The length of this buffer increases by 8.
This long can be retrieved with the longAt() method.
val - A long value.public void append(byte[] bytes)
The bytes of the array argument are appended, in order, to the contents of this buffer. The length of this ByteBuffer increases by the length of the argument.
append in interface ByteStorebytes - The bytes to be appended.
public void append(byte[] bytes,
int offset,
int length)
bytes array argument
to this buffer.
Bytes of the byte array bytes, starting at index
offset, are appended, in order, to the contents of this
byte buffer. The length of this buffer increases by the value of
length.
append in interface ByteStorebytes - The bytes to be appended.offset - The index of the first byte to append.length - The number of bytes to append.
public void insert(int offset,
byte[] bytes)
throws java.lang.ArrayIndexOutOfBoundsException
The bytes of the array argument are inserted into the
contents of this buffer at the position indicated by
offset. The length of this buffer increases by
the length of the argument.
insert in interface ByteStoreoffset - The offset.bytes - A byte array.java.lang.ArrayIndexOutOfBoundsException - There is an invalid index
into the buffer.
public void insert(int offset,
byte val)
The second argument is inserted into the contents of this byte
buffer at the position indicated by offset. The length
of this buffer increases by one.
The offset argument must be greater than or equal to
0, and less than or equal to the length of this
ByteBuffer.
insert in interface ByteStoreoffset - The offset.val - The byte value.
public void write(java.io.OutputStream stream)
throws java.io.IOException,
java.lang.ArrayIndexOutOfBoundsException
stream - OutputStream to which bytes should be written.java.io.IOException - The write() failed.java.lang.ArrayIndexOutOfBoundsException - The index is invalid.
public void write(java.io.OutputStream stream,
int offset,
int length)
throws java.io.IOException,
java.lang.ArrayIndexOutOfBoundsException
offset and length will be written before
return.stream - OutputStream to which bytes should be written.offset - Offset of the first byte from the buffer to be written.length - Number of bytes from the buffer to be written.java.io.IOException - The write() failed.java.lang.ArrayIndexOutOfBoundsException - The index is invalid.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||