|
Extension SDK 10.1.2 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectoracle.ide.util.ByteBuffer
A byte buffer implements a mutable sequence of bytes. At any point in time it contains some particular sequence of bytes, but the length and content of the sequence can be changed through certain method calls.
| Constructor Summary | |
ByteBuffer()
Constructs a byte buffer with no bytes in it and an initial capacity of 16 bytes. |
|
ByteBuffer(byte[] bytes)
Constructs a byte buffer so that it represents the same sequence of bytes as the array argument; in other words, the initial contents of the byte buffer is a copy of the argument array. |
|
ByteBuffer(int length)
Constructs a byte buffer with no bytes in it and an initial capacity specified by the length argument. |
|
| Method Summary | |
ByteBuffer |
append(byte[] bytes)
Appends the contents of the byte array argument to this
byte buffer. |
ByteBuffer |
append(byte[] bytes,
int offset,
int len)
Appends a subarray of the byte array argument to this
byte buffer. |
byte |
byteAt(int index)
The specified byte of the sequence currently represented by the byte buffer, as indicated by the index argument,
is returned. |
int |
capacity()
Returns the current capacity of the byte buffer. |
ByteBuffer |
delete(int start,
int end)
Removes the bytes in a subarray of this ByteBuffer. |
ByteBuffer |
deleteByteAt(int index)
Removes the byte at the specified position in this ByteBuffer (shortening the ByteBuffer
by one byte). |
void |
ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum. |
void |
getBytes(int srcBegin,
int srcEnd,
byte[] dst,
int dstBegin)
Bytes are copied from this byte buffer into the destination byte array dst. |
ByteBuffer |
insert(int offset,
byte[] bytes)
Inserts the bytes of the bytes array argument into
this byte buffer. |
ByteBuffer |
insert(int index,
byte[] bytes,
int offset,
int len)
Inserts the bytes of a subarray of the bytes array
argument into this byte buffer. |
int |
length()
Returns the length (byte count) of this byte buffer. |
ByteBuffer |
replace(int start,
int end,
byte[] bytes)
Replaces the bytes in a subarray of this ByteBuffer
with bytes in the specified array. |
ByteBuffer |
reverse()
The byte sequence contained in this byte buffer is replaced by the reverse of the sequence. |
void |
setByteAt(int index,
byte ch)
The byte at the specified index of this byte buffer is set to ch. |
void |
setLength(int newLength)
Sets the length of this byte buffer. |
byte[] |
subarray(int start)
Returns a new byte array that contains a subsequence of bytes currently contained in this ByteBuffer.The
subarray begins at the specified index and extends to the end of the
ByteBuffer. |
byte[] |
subarray(int start,
int end)
Returns a new byte array that contains a subsequence of bytes currently contained in this ByteBuffer. |
byte[] |
toBytes()
Converts to a byte array copy of the data in this byte buffer. |
java.lang.String |
toString()
Converts to a string representing the data in this byte buffer. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public ByteBuffer()
public ByteBuffer(int length)
length argument.
length - the initial capacity.
java.lang.NegativeArraySizeException - if the length
argument is less than 0.public ByteBuffer(byte[] bytes)
16 plus the length of the array argument.
bytes - the initial contents of the buffer.| Method Detail |
public int length()
public int capacity()
public void ensureCapacity(int minimumCapacity)
minimumCapacity argument.
2.
minimumCapacity argument is nonpositive, this
method takes no action and simply returns.
minimumCapacity - the minimum desired capacity.public void setLength(int newLength)
newLength, the byte at
index k in the new byte sequence is the same as the
byte at index k in the old sequence if k is less
than the length of the old byte sequence; otherwise, it is the
null byte 0.
In other words, if the newLength argument is less than
the current length of the byte buffer, the byte buffer is
truncated to contain exactly the number of bytes given by the
newLength argument.
If the newLength argument is greater than or equal
to the current length, sufficient null bytes are appended to the
byte buffer so that length becomes the newLength
argument.
The newLength argument must be greater than or equal
to 0.
newLength - the new length of the buffer.
java.lang.IndexOutOfBoundsException - if the
newLength argument is negative.length()public byte byteAt(int index)
index argument,
is returned. The first byte of a byte buffer is 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 byte buffer.
index - the index of the desired byte.
java.lang.IndexOutOfBoundsException - if index is
negative or greater than or equal to length().length()
public void getBytes(int srcBegin,
int srcEnd,
byte[] dst,
int dstBegin)
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
srcBegin - start copying at this offset in the byte buffer.srcEnd - stop copying at this offset in the byte buffer.dst - the array to copy the data into.dstBegin - offset into dst.
java.lang.NullPointerException - if dst is
null.
java.lang.IndexOutOfBoundsException - if any of the following is true:
srcBegin is negative
dstBegin is negative
srcBegin argument is greater than
the srcEnd argument.
srcEnd is greater than
this.length(), the current length of this
byte buffer.
dstBegin+srcEnd-srcBegin is greater than
dst.length
public void setByteAt(int index,
byte ch)
ch. The byte buffer is altered to represent a new
byte sequence that is identical to the old byte sequence,
except that it contains the byte ch at position
index.
The offset argument must be greater than or equal to
0, and less than the length of this byte buffer.
index - the index of the byte to modify.ch - the new byte.
java.lang.IndexOutOfBoundsException - if index is
negative or greater than or equal to length().length()public ByteBuffer append(byte[] bytes)
byte array argument to this
byte buffer.
The bytes of the array argument are appended, in order, to the contents of this byte buffer. The length of this byte buffer increases by the length of the argument.
bytes - the bytes to be appended.
ByteBuffer object.
public ByteBuffer append(byte[] bytes,
int offset,
int len)
byte array argument to this
byte 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 byte buffer increases
by the value of len.
bytes - the bytes to be appended.offset - the index of the first byte to append.len - the number of bytes to append.
ByteBuffer object.
public ByteBuffer delete(int start,
int end)
ByteBuffer.
The subarray begins at the specified start and extends to
the byte at index end - 1 or to the end of the
ByteBuffer if no such byte exists. If
start is equal to end, no changes are made.
start - The beginning index, inclusive.end - The ending index, exclusive.
java.lang.ArrayIndexOutOfBoundsException - if start
is negative, greater than length(), or
greater than end.public ByteBuffer deleteByteAt(int index)
ByteBuffer (shortening the ByteBuffer
by one byte).
index - Index of byte to remove
java.lang.ArrayIndexOutOfBoundsException - if the index
is negative or greater than or equal to
length().
public ByteBuffer replace(int start,
int end,
byte[] bytes)
ByteBuffer
with bytes in the specified array. The subarray
begins at the specified start and extends to the byte
at index end - 1 or to the end of the
ByteBuffer if no such byte exists. First the
bytes in the subarray are removed and then the specified
array is inserted at start. (The
ByteBuffer will be lengthened to accommodate the
specified array if necessary.)
start - The beginning index, inclusive.end - The ending index, exclusive.bytes - Array that will replace previous contents.
java.lang.ArrayIndexOutOfBoundsException - if start
is negative, greater than length(), or
greater than end.public byte[] subarray(int start)
ByteBuffer.The
subarray begins at the specified index and extends to the end of the
ByteBuffer.
start - The beginning index, inclusive.
java.lang.ArrayIndexOutOfBoundsException - if start is
less than zero, or greater than the length of this
ByteBuffer.
public byte[] subarray(int start,
int end)
ByteBuffer. The
subarray begins at the specified start and
extends to the byte at index end - 1. An
exception is thrown if
start - The beginning index, inclusive.end - The ending index, exclusive.
java.lang.ArrayIndexOutOfBoundsException - if start
or end are negative or greater than
length(), or start is
greater than end.
public ByteBuffer insert(int index,
byte[] bytes,
int offset,
int len)
bytes array
argument into this byte buffer. The subarray begins at the
specified offset and extends len bytes.
The bytes of the subarray are inserted into this byte buffer at
the position indicated by index. The length of this
ByteBuffer increases by len bytes.
index - position at which to insert subarray.bytes - A byte array.offset - the index of the first byte in subarray to
to be inserted.len - the number of bytes in the subarray to
to be inserted.
java.lang.ArrayIndexOutOfBoundsException - if index
is negative or greater than length(), or
offset or len are negative, or
(offset+len) is greater than
bytes.length.
public ByteBuffer insert(int offset,
byte[] bytes)
bytes array argument into
this byte buffer.
The bytes of the array argument are inserted into the
contents of this byte buffer at the position indicated by
offset. The length of this byte buffer increases by
the length of the argument.
offset - the offset.bytes - a byte array.
ByteBuffer object.
java.lang.ArrayIndexOutOfBoundsException - if the offset is invalid.public ByteBuffer reverse()
Let n be the length of the old byte sequence, the one
contained in the byte buffer just prior to execution of the
reverse method. Then the byte at index k in
the new byte sequence is equal to the byte at index
n-k-1 in the old byte sequence.
public java.lang.String toString()
String object is allocated and initialized to
contain the byte sequence currently represented by this
byte buffer. This String is then returned. Subsequent
changes to the byte buffer do not affect the contents of the
String.
public byte[] toBytes()
|
Extension SDK | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
Copyright © 1997, 2004, Oracle. All rights reserved.