Methods Summary |
---|
public void | append(int value)
ensureCapacityHelper(elementCount + 4);
doAppend( value ) ;
|
public void | append(java.lang.String value)
byte[] data = value.getBytes() ;
ensureCapacityHelper( elementCount + data.length + 4 ) ;
doAppend( data.length ) ;
System.arraycopy( data, 0, elementData, elementCount, data.length ) ;
elementCount += data.length ;
|
public void | append(byte value)
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = value;
|
public int | capacity()Returns the current capacity of this ByteBuffer.
return elementData.length;
|
private void | doAppend(int value)
int current = value ;
for (int ctr=0; ctr<4; ctr++) {
elementData[elementCount+ctr] = (byte)(current & 255) ;
current = current >> 8 ;
}
elementCount += 4 ;
|
private void | ensureCapacityHelper(int minCapacity)This implements the unsynchronized semantics of ensureCapacity.
Synchronized methods in this class can internally call this
method for ensuring capacity without incurring the cost of an
extra synchronization.
int oldCapacity = elementData.length;
if (minCapacity > oldCapacity) {
byte oldData[] = elementData;
int newCapacity = (capacityIncrement > 0) ?
(oldCapacity + capacityIncrement) : (oldCapacity * 2);
if (newCapacity < minCapacity) {
newCapacity = minCapacity;
}
elementData = new byte[newCapacity];
System.arraycopy(oldData, 0, elementData, 0, elementCount);
}
|
public boolean | isEmpty()Tests if this ByteBuffer has no components.
return elementCount == 0;
|
public int | size()Returns the number of components in this ByteBuffer.
return elementCount;
|
public byte[] | toArray()Returns an array containing all of the elements in this ByteBuffer
in the correct order.
return elementData ;
|
public void | trimToSize()Trims the capacity of this ByteBuffer to be the ByteBuffer's current
size. If the capacity of this cector is larger than its current
size, then the capacity is changed to equal the size by replacing
its internal data array, kept in the field elementData,
with a smaller one. An application can use this operation to
minimize the storage of a ByteBuffer.
int oldCapacity = elementData.length;
if (elementCount < oldCapacity) {
byte oldData[] = elementData;
elementData = new byte[elementCount];
System.arraycopy(oldData, 0, elementData, 0, elementCount);
}
|