rebuild.comp.java.nio
Class ByteBuffer

java.lang.Object
  extended by rebuild.comp.java.nio.Buffer
      extended by rebuild.comp.java.nio.ByteBuffer

public abstract class ByteBuffer
extends Buffer

A skimmed down version of the ByteBuffer class for use in versions lower then 5.0. Based off J2SE java.nio.ByteBuffer class but no source code used for it.

Since:
BBX 1.2.0

Method Summary
static ByteBuffer allocateDirect(int capacity)
          Allocates a new direct byte buffer.
 byte[] array()
          Returns the byte array that backs this buffer.
 int arrayOffset()
          Returns the offset within this buffer's backing array of the first element of the buffer.
abstract  ShortBuffer asShortBuffer()
          Creates a view of this byte buffer as a short buffer.
abstract  byte get()
          Relative get method.
 ByteBuffer get(byte[] dst)
          Relative bulk get method.
 ByteBuffer get(byte[] dst, int offset, int length)
          This method transfers bytes from this buffer into the given destination array.
abstract  byte get(int index)
          Absolute get method.
abstract  int getInt()
          Relative get method for reading an int value.
abstract  short getShort()
          Relative get method for reading a short value.
abstract  short getShort(int index)
          Absolute get method for reading a short value.
 boolean hasArray()
          Tells whether or not this buffer is backed by an accessible byte array.
abstract  ByteBuffer put(byte b)
          Writes the given byte into this buffer at the current position, and then increments the position.
 ByteBuffer put(byte[] src)
          This method transfers the entire content of the given source byte array into this buffer.
 ByteBuffer put(byte[] src, int offset, int length)
          Relative bulk put method
 ByteBuffer put(ByteBuffer src)
          This method transfers the bytes remaining in the given source buffer into this buffer.
abstract  ByteBuffer put(int index, byte b)
          Writes the given byte into this buffer at the given index.
abstract  ByteBuffer putInt(int value)
          Relative put method for writing an int value.
abstract  ByteBuffer putInt(int index, int value)
          Absolute put method for writing an int value.
abstract  ByteBuffer putShort(short value)
          Relative put method for writing a short value.
abstract  ByteBuffer slice()
          Creates a new byte buffer whose content is a shared subsequence of this buffer's content.
static ByteBuffer wrap(byte[] array)
          Wraps a byte array into a buffer.
 
Methods inherited from class rebuild.comp.java.nio.Buffer
capacity, clear, flip, hasRemaining, limit, limit, position, position, remaining, rewind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

allocateDirect

public static ByteBuffer allocateDirect(int capacity)
Allocates a new direct byte buffer.

Parameters:
capacity - The new buffer's capacity, in bytes.
Returns:
The new byte buffer.

wrap

public static ByteBuffer wrap(byte[] array)
Wraps a byte array into a buffer.

Parameters:
array - The array that will back this buffer.
Returns:
The new byte buffer.

asShortBuffer

public abstract ShortBuffer asShortBuffer()
Creates a view of this byte buffer as a short buffer.

Returns:
A new short buffer.

put

public abstract ByteBuffer put(byte b)
Writes the given byte into this buffer at the current position, and then increments the position.

Parameters:
b - The byte to be written.
Returns:
This buffer.

put

public abstract ByteBuffer put(int index,
                               byte b)
Writes the given byte into this buffer at the given index.

Parameters:
index - The index at which the byte will be written.
b - The byte value to be written.
Returns:
This buffer.

put

public ByteBuffer put(ByteBuffer src)
This method transfers the bytes remaining in the given source buffer into this buffer.

Parameters:
src - The source buffer from which bytes are to be read; must not be this buffer.
Returns:
This buffer.

put

public final ByteBuffer put(byte[] src)
This method transfers the entire content of the given source byte array into this buffer.

Returns:
This buffer.

put

public ByteBuffer put(byte[] src,
                      int offset,
                      int length)
Relative bulk put method

Parameters:
src - The array from which bytes are to be read.
offset - The offset within the array of the first byte to be read; must be non-negative and no larger than array.length.
length - The number of bytes to be read from the given array; must be non-negative and no larger than array.length - offset.
Returns:
This buffer.

putShort

public abstract ByteBuffer putShort(short value)
Relative put method for writing a short value.

Parameters:
value - The short value to be written.
Returns:
This buffer.

putInt

public abstract ByteBuffer putInt(int value)
Relative put method for writing an int value.

Parameters:
value - The int value to be written.
Returns:
This buffer

putInt

public abstract ByteBuffer putInt(int index,
                                  int value)
Absolute put method for writing an int value.

Parameters:
index - The index at which the bytes will be written.
value - The int value to be written.
Returns:
This buffer.

get

public abstract byte get()
Relative get method. Reads the byte at this buffer's current position, and then increments the position.

Returns:
The byte at the buffer's current position.

get

public abstract byte get(int index)
Absolute get method. Reads the byte at the given index.

Parameters:
index - The index from which the byte will be read.
Returns:
The byte at the given index.

get

public ByteBuffer get(byte[] dst)
Relative bulk get method.

Returns:
This buffer.

get

public ByteBuffer get(byte[] dst,
                      int offset,
                      int length)
This method transfers bytes from this buffer into the given destination array.

Parameters:
dst - The array into which bytes are to be written.
offset - The offset within the array of the first byte to be written; must be non-negative and no larger than dst.length.
length - The maximum number of bytes to be written to the given array; must be non-negative and no larger than dst.length - offset.
Returns:
This buffer.

getShort

public abstract short getShort()
Relative get method for reading a short value.

Returns:
The short value at the buffer's current position

getShort

public abstract short getShort(int index)
Absolute get method for reading a short value.

Parameters:
index - The index from which the bytes will be read
Returns:
The short value at the given index

getInt

public abstract int getInt()
Relative get method for reading an int value.

Returns:
The int value at the buffer's current position

array

public final byte[] array()
Returns the byte array that backs this buffer.

Returns:
The array that backs this buffer.

hasArray

public final boolean hasArray()
Tells whether or not this buffer is backed by an accessible byte array.

Returns:
true if, and only if, this buffer is backed by an array and is not read-only.

arrayOffset

public final int arrayOffset()
Returns the offset within this buffer's backing array of the first element of the buffer.

Returns:
The offset within this buffer's array of the first element of the buffer.

slice

public abstract ByteBuffer slice()
Creates a new byte buffer whose content is a shared subsequence of this buffer's content.

Returns:
The new byte buffer.