| Method from java.nio.ByteBuffer Detail: |
public static ByteBuffer allocate(int capacity) {
return wrap(new byte[capacity], 0, capacity);
}
Allocates a new ByteBuffer object with a given capacity. |
public static ByteBuffer allocateDirect(int capacity) {
return DirectByteBufferImpl.allocate (capacity);
}
Allocates a new direct byte buffer. |
public final byte[] array() {
if (backing_buffer == null)
throw new UnsupportedOperationException ();
checkIfReadOnly();
return backing_buffer;
}
Returns the byte array that backs this buffer. |
public final int arrayOffset() {
if (backing_buffer == null)
throw new UnsupportedOperationException ();
checkIfReadOnly();
return array_offset;
}
Returns the offset within this buffer's backing array of the first element. |
abstract public CharBuffer asCharBuffer()
Creates a view of this byte buffer as a char buffer. |
abstract public DoubleBuffer asDoubleBuffer()
Creates a view of this byte buffer as a double buffer. |
abstract public FloatBuffer asFloatBuffer()
Creates a view of this byte buffer as a float buffer. |
abstract public IntBuffer asIntBuffer()
Creates a view of this byte buffer as an integer buffer. |
abstract public LongBuffer asLongBuffer()
Creates a view of this byte buffer as a long buffer. |
abstract public ByteBuffer asReadOnlyBuffer()
Creates a new read-only ByteBuffer that shares this
buffer's content. |
abstract public ShortBuffer asShortBuffer()
Creates a view of this byte buffer as a short buffer. |
abstract public ByteBuffer compact()
|
public int compareTo(Object obj) {
ByteBuffer other = (ByteBuffer) obj;
int num = Math.min(remaining(), other.remaining());
int pos_this = position();
int pos_other = other.position();
for (int count = 0; count < num; count++)
{
byte a = get(pos_this++);
byte b = other.get(pos_other++);
if (a == b)
continue;
if (a < b)
return -1;
return 1;
}
return remaining() - other.remaining();
}
Compares two ByteBuffer objects. |
abstract public ByteBuffer duplicate()
Creates a new ByteBuffer that shares this buffer's
content. |
public boolean equals(Object obj) {
if (obj instanceof ByteBuffer)
{
return compareTo (obj) == 0;
}
return false;
}
Checks if this buffer is equal to obj. |
abstract public byte get()
Reads the byte at this buffer's current position,
and then increments the position. |
public ByteBuffer get(byte[] dst) {
return get (dst, 0, dst.length);
}
This method transfers bytes from this buffer into the given
destination array. |
abstract public byte get(int index)
|
public ByteBuffer get(byte[] dst,
int offset,
int length) {
checkArraySize(dst.length, offset, length);
checkForUnderflow(length);
for (int i = offset; i < offset + length; i++)
{
dst [i] = get ();
}
return this;
}
This method transfers bytes from this buffer into the given
destination array. Before the transfer, it checks if there are fewer than
length bytes remaining in this buffer. |
abstract public char getChar()
Relative get method for reading a character value. |
abstract public char getChar(int index)
Absolute get method for reading a character value. |
abstract public double getDouble()
Relative get method for reading a double value. |
abstract public double getDouble(int index)
Absolute get method for reading a double value. |
abstract public float getFloat()
Relative get method for reading a float value. |
abstract public float getFloat(int index)
Absolute get method for reading a float value. |
abstract public int getInt()
Relative get method for reading an integer value. |
abstract public int getInt(int index)
Absolute get method for reading an integer value. |
abstract public long getLong()
Relative get method for reading a long value. |
abstract public long getLong(int index)
Absolute get method for reading a long value. |
abstract public short getShort()
Relative get method for reading a short value. |
abstract public short getShort(int index)
Absolute get method for reading a short value. |
public final boolean hasArray() {
return (backing_buffer != null
&& !isReadOnly ());
}
Tells whether ot not this buffer is backed by an accessible
byte array. |
public int hashCode() {
int hashCode = get(position()) + 31;
int multiplier = 1;
for (int i = position() + 1; i < limit(); ++i)
{
multiplier *= 31;
hashCode += (get(i) + 30)*multiplier;
}
return hashCode;
}
Calculates a hash code for this buffer.
This is done with int arithmetic,
where ** represents exponentiation, by this formula:
s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
(s[limit()-1]+30)*31**(limit()-1).
Where s is the buffer data. Note that the hashcode is dependent
on buffer content, and therefore is not useful if the buffer
content may change. |
abstract public boolean isDirect()
Tells whether or not this buffer is direct. |
public final ByteOrder order() {
return endian;
}
Returns the byte order of this buffer. |
public final ByteBuffer order(ByteOrder endian) {
this.endian = endian;
return this;
}
Modifies this buffer's byte order. |
public ByteBuffer put(ByteBuffer src) {
if (src == this)
throw new IllegalArgumentException ();
checkForOverflow(src.remaining());
if (src.remaining () > 0)
{
byte[] toPut = new byte [src.remaining ()];
src.get (toPut);
put (toPut);
}
return this;
}
Writes the content of the the ByteBUFFER src
into the buffer. Before the transfer, it checks if there is fewer than
src.remaining() space remaining in this buffer. |
public final ByteBuffer put(byte[] src) {
return put (src, 0, src.length);
}
Writes the content of the the byte array src
into the buffer. |
abstract public ByteBuffer put(byte b)
Writes the byte at this buffer's current position,
and then increments the position. |
abstract public ByteBuffer put(int index,
byte b)
|
public ByteBuffer put(byte[] src,
int offset,
int length) {
checkArraySize(src.length, offset, length);
checkForOverflow(length);
for (int i = offset; i < offset + length; i++)
put (src [i]);
return this;
}
Writes the content of the the byte array src
into the buffer. Before the transfer, it checks if there is fewer than
length space remaining in this buffer. |
abstract public ByteBuffer putChar(char value)
Relative put method for writing a character value. |
abstract public ByteBuffer putChar(int index,
char value)
Absolute put method for writing a character value. |
abstract public ByteBuffer putDouble(double value)
Relative put method for writing a double value. |
abstract public ByteBuffer putDouble(int index,
double value)
Absolute put method for writing a double value. |
abstract public ByteBuffer putFloat(float value)
Relative put method for writing a float value. |
abstract public ByteBuffer putFloat(int index,
float value)
Relative put method for writing a float value. |
abstract public ByteBuffer putInt(int value)
Relative put method for writing an integer value. |
abstract public ByteBuffer putInt(int index,
int value)
Absolute put method for writing an integer value. |
abstract public ByteBuffer putLong(long value)
Relative put method for writing a long value. |
abstract public ByteBuffer putLong(int index,
long value)
Absolute put method for writing a float value. |
abstract public ByteBuffer putShort(short value)
Relative put method for writing a short value. |
abstract public ByteBuffer putShort(int index,
short value)
Absolute put method for writing a short value. |
void shiftDown(int dst_offset,
int src_offset,
int count) {
for (int i = 0; i < count; i++)
put(dst_offset + i, get(src_offset + i));
}
|
abstract public ByteBuffer slice()
Creates a new ByteBuffer whose content is a shared
subsequence of this buffer's content. |
public String toString() {
return getClass ().getName () +
"[pos=" + position () +
" lim=" + limit () +
" cap=" + capacity () + "]";
}
Returns a string summarizing the state of this buffer. |
public static final ByteBuffer wrap(byte[] array) {
return wrap (array, 0, array.length);
}
Wraps a byte array into a ByteBuffer
object. |
public static final ByteBuffer wrap(byte[] array,
int offset,
int length) {
// FIXME: In GCJ and other implementations where arrays may not
// move we might consider, at least when offset==0:
// return new DirectByteBufferImpl(array,
// address_of_data(array) + offset,
// length, length, 0, false);
// This may be more efficient, mainly because we can then use the
// same logic for all ByteBuffers.
return new ByteBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
}
Wraps a byte array into a ByteBuffer
object. |