com.groovemanager.spi.asio
Class DoubleHalfBuffer

java.lang.Object
  extended by com.groovemanager.spi.asio.DoubleHalfBuffer

 class DoubleHalfBuffer
extends Object

This class can be used to concatenate two ByteBuffers into one. Since java.nio.ByteBuffer cannot be subclassed from outside the package, this class copies the most important methods from ByteBuffer.

Author:
Manu Robledo
See Also:
ByteBuffer

Field Summary
private  int capacity
          This buffer´s capacity
private  ByteBuffer firstBuffer
          The first buffer
private  int firstLimit
          The first buffer´s limit
private  int limit
          This buffer´s current limit
private  int position
          This buffer´s current limit
private  boolean readOnly
          Indicates whether this buffer is readOnly or not
private  ByteBuffer secondBuffer
          The first buffer
 
Constructor Summary
DoubleHalfBuffer(ByteBuffer first, ByteBuffer second)
          Create a new DoubleHalfBuffer out of the given buffers that will be read only if, and only if at least one of the given buffers is read only
DoubleHalfBuffer(ByteBuffer first, ByteBuffer second, boolean readOnly)
          Create a new DoubleHalfBuffer out of the given buffers
 
Method Summary
 DoubleHalfBuffer asReadOnlyBuffer()
          Creates a new, read-only buffer that shares this buffer's content.
 int capacity()
          Get his buffer´s total capacity
 DoubleHalfBuffer clear()
          Clear this buffer by resetting its position to zero and its limit to its capacity.
 DoubleHalfBuffer duplicate()
          Creates a new buffer that shares this buffer's content.
 DoubleHalfBuffer flip()
          Flips this buffer.
 byte get()
          Relative get method.
 DoubleHalfBuffer get(byte[] dst)
          Relative bulk get method.
 DoubleHalfBuffer get(byte[] dst, int offset, int length)
          Relative bulk get method.
 byte get(int position)
          Absolute get method.
 boolean hasRemaining()
          Tells whether there are any elements between the current position and the limit.
 boolean isReadOnly()
          Tells whether this buffer is read-only or not.
 int limit()
          Get this buffer´s current limit
 DoubleHalfBuffer limit(int limit)
          Set this buffer´s limit
 int position()
          Get his buffer´s current position
 DoubleHalfBuffer position(int pos)
          Set this buffer´s position
 DoubleHalfBuffer put(byte value)
          Relative put method.
 DoubleHalfBuffer put(byte[] src)
          Relative bulk put method.
 DoubleHalfBuffer put(byte[] src, int offset, int length)
          Relative bulk put method.
 DoubleHalfBuffer put(int position, byte value)
          Absolute put method.
 int remaining()
          Get the number of bytes remaining between this buffer´s current position and its limit
 DoubleHalfBuffer rewind()
          Set this buffer´s position to zero
 DoubleHalfBuffer slice()
          Creates a new buffer whose content is a shared subsequence of this buffer's content.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

firstBuffer

private final ByteBuffer firstBuffer
The first buffer


secondBuffer

private final ByteBuffer secondBuffer
The first buffer


readOnly

private boolean readOnly
Indicates whether this buffer is readOnly or not


limit

private int limit
This buffer´s current limit


position

private int position
This buffer´s current limit


capacity

private final int capacity
This buffer´s capacity


firstLimit

private final int firstLimit
The first buffer´s limit

Constructor Detail

DoubleHalfBuffer

public DoubleHalfBuffer(ByteBuffer first,
                        ByteBuffer second,
                        boolean readOnly)
Create a new DoubleHalfBuffer out of the given buffers

Parameters:
first - The first buffer
second - The second buffer
readOnly - true, if the resulting buffer should be read only, false otherwise

DoubleHalfBuffer

public DoubleHalfBuffer(ByteBuffer first,
                        ByteBuffer second)
Create a new DoubleHalfBuffer out of the given buffers that will be read only if, and only if at least one of the given buffers is read only

Parameters:
first - The first buffer
second - The second buffer
Method Detail

asReadOnlyBuffer

public DoubleHalfBuffer asReadOnlyBuffer()
Creates a new, read-only buffer that shares this buffer's content.

Returns:
The new buffer
See Also:
ByteBuffer.asReadOnlyBuffer()

duplicate

public DoubleHalfBuffer duplicate()
Creates a new buffer that shares this buffer's content.

Returns:
The new buffer
See Also:
ByteBuffer.duplicate()

get

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

Parameters:
position - The position fromo which the byte will be read
Returns:
The byte at the given position
See Also:
ByteBuffer.get(int)

get

public 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
See Also:
ByteBuffer.get()

get

public DoubleHalfBuffer get(byte[] dst)
Relative bulk get method. This method transfers bytes from this buffer into the given destination array. An invocation of this method of the form src.get(a) behaves in exactly the same way as the invocation of src.get(a, 0, a.length).

Parameters:
dst - The destination array to transfer the data to
Returns:
This buffer

get

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

Parameters:
dst - The destination array to transfer the data to
offset - The offset within the array of the first byte to be written; must be non-negative and no larger than dst.length
Returns:
This buffer

put

public DoubleHalfBuffer put(int position,
                            byte value)
Absolute put method. Writes the given byte into this buffer at the given position.

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

put

public DoubleHalfBuffer put(byte value)
Relative put method. Writes the given byte into this buffer at the current position, and then increments the position.

Parameters:
value - The byte to be written
Returns:
This buffer

put

public DoubleHalfBuffer put(byte[] src)
Relative bulk put method. This method transfers the entire content of the given source byte array into this buffer. An invocation of this method of the form dst.put(a) behaves in exactly the same way as the invocation dst.put(a, 0, a.length).

Parameters:
src - The array to copy the data from
Returns:
This buffer

put

public DoubleHalfBuffer put(byte[] src,
                            int offset,
                            int length)
Relative bulk put method. This method transfers length bytes from the given array starting at offset to this buffer starting at the current position.

Parameters:
src - The array to copy the data from
offset - Start position inside the given array
length - Number of bytes to put.
Returns:
This buffer

slice

public DoubleHalfBuffer slice()
Creates a new buffer whose content is a shared subsequence of this buffer's content. The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position and limit values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer. The new buffer will be read-only if, and only if, this buffer is read-only.

Returns:
The new buffer

capacity

public int capacity()
Get his buffer´s total capacity

Returns:
This buffer´s total capcity in bytes

clear

public DoubleHalfBuffer clear()
Clear this buffer by resetting its position to zero and its limit to its capacity.

Returns:
This buffer

flip

public DoubleHalfBuffer flip()
Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.

Returns:
This buffer

hasRemaining

public boolean hasRemaining()
Tells whether there are any elements between the current position and the limit.

Returns:
true, if there is at least one byte left in the buffer, false otherwise

isReadOnly

public boolean isReadOnly()
Tells whether this buffer is read-only or not.

Returns:
true, if this buffer is read-only, false otherwise

limit

public int limit()
Get this buffer´s current limit

Returns:
This buffer´s current limit

limit

public DoubleHalfBuffer limit(int limit)
Set this buffer´s limit

Parameters:
limit - The new limit
Returns:
This buffer

position

public int position()
Get his buffer´s current position

Returns:
This buffer´s current position

position

public DoubleHalfBuffer position(int pos)
Set this buffer´s position

Parameters:
pos - The new position
Returns:
This buffer

remaining

public int remaining()
Get the number of bytes remaining between this buffer´s current position and its limit

Returns:
The number of bytes remining in this buffer

rewind

public DoubleHalfBuffer rewind()
Set this buffer´s position to zero

Returns:
This buffer

toString

public String toString()
Overrides:
toString in class Object