Build 1.0_r1(from source)

java.nio
Class ReadWriteHeapByteBuffer

java.lang.Object
  extended by java.nio.Buffer
      extended by java.nio.ByteBuffer
          extended by java.nio.BaseByteBuffer
              extended by java.nio.HeapByteBuffer
                  extended by java.nio.ReadWriteHeapByteBuffer
All Implemented Interfaces:
Comparable<ByteBuffer>

final class ReadWriteHeapByteBuffer
extends HeapByteBuffer

HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose the implementation of array based byte buffers.

ReadWriteHeapByteBuffer extends HeapByteBuffer with all the write methods.

This class is marked final for runtime performance.


Field Summary
 
Fields inherited from class java.nio.HeapByteBuffer
backingArray, offset
 
Fields inherited from class java.nio.ByteBuffer
order
 
Fields inherited from class java.nio.Buffer
_elementSizeShift, capacity, limit, mark, position, UNSET_MARK
 
Constructor Summary
ReadWriteHeapByteBuffer(byte[] backingArray)
           
ReadWriteHeapByteBuffer(byte[] backingArray, int capacity, int arrayOffset)
           
ReadWriteHeapByteBuffer(int capacity)
           
 
Method Summary
 ByteBuffer asReadOnlyBuffer()
          Returns a readonly buffer that shares content with this buffer.
 ByteBuffer compact()
          Compacts this byte buffer.
(package private) static ReadWriteHeapByteBuffer copy(HeapByteBuffer other, int markOfOther)
           
 ByteBuffer duplicate()
          Returns a duplicated buffer that shares content with this buffer.
 boolean isReadOnly()
          Returns whether this buffer is readonly or not.
protected  byte[] protectedArray()
          Child class implements this method to realize array().
protected  int protectedArrayOffset()
          Child class implements this method to realize arrayOffset().
protected  boolean protectedHasArray()
          Child class implements this method to realize hasArray().
 ByteBuffer put(byte b)
          Writes the given byte to the current position and increase the position by 1.
 ByteBuffer put(byte[] src, int off, int len)
          Writes bytes in the given byte array, starting from the specified offset, to the current position and increase the position by the number of bytes written.
 ByteBuffer put(int index, byte b)
          Write a byte to the specified index of this buffer and the position is not changed.
 ByteBuffer putDouble(double value)
          Writes the given double to the current position and increase the position by 8.
 ByteBuffer putDouble(int index, double value)
          Write a double to the specified index of this buffer.
 ByteBuffer putFloat(float value)
          Writes the given float to the current position and increase the position by 4.
 ByteBuffer putFloat(int index, float value)
          Write a float to the specified index of this buffer.
 ByteBuffer putInt(int value)
          Writes the given int to the current position and increase the position by 4.
 ByteBuffer putInt(int index, int value)
          Write a int to the specified index of this buffer.
 ByteBuffer putLong(int index, long value)
          Write a long to the specified index of this buffer.
 ByteBuffer putLong(long value)
          Writes the given long to the current position and increase the position by 8.
 ByteBuffer putShort(int index, short value)
          Write a short to the specified index of this buffer.
 ByteBuffer putShort(short value)
          Writes the given short to the current position and increase the position by 2.
 ByteBuffer slice()
          Returns a sliced buffer that shares content with this buffer.
 
Methods inherited from class java.nio.HeapByteBuffer
get, get, get, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getShort, getShort, isDirect, loadInt, loadLong, loadShort, store, store, store
 
Methods inherited from class java.nio.BaseByteBuffer
asCharBuffer, asDoubleBuffer, asFloatBuffer, asIntBuffer, asLongBuffer, asShortBuffer, getChar, getChar, putChar, putChar
 
Methods inherited from class java.nio.ByteBuffer
_array, _arrayOffset, allocate, allocateDirect, array, arrayOffset, compareTo, equals, get, hasArray, hashCode, order, order, orderImpl, put, put, toString, wrap, wrap
 
Methods inherited from class java.nio.Buffer
capacity, clear, flip, hasRemaining, limit, limit, mark, position, position, remaining, reset, rewind
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReadWriteHeapByteBuffer

ReadWriteHeapByteBuffer(byte[] backingArray)

ReadWriteHeapByteBuffer

ReadWriteHeapByteBuffer(int capacity)

ReadWriteHeapByteBuffer

ReadWriteHeapByteBuffer(byte[] backingArray,
                        int capacity,
                        int arrayOffset)
Method Detail

copy

static ReadWriteHeapByteBuffer copy(HeapByteBuffer other,
                                    int markOfOther)

asReadOnlyBuffer

public ByteBuffer asReadOnlyBuffer()
Description copied from class: ByteBuffer
Returns a readonly buffer that shares content with this buffer.

The returned buffer is guaranteed to be a new instance, even this buffer is readonly itself. The new buffer's position, limit, capacity and mark are the same as this buffer.

The new buffer shares content with this buffer, which means this buffer's change of content will be visible to the new buffer. The two buffer's position, limit and mark are independent.

Specified by:
asReadOnlyBuffer in class ByteBuffer
Returns:
A readonly version of this buffer.

compact

public ByteBuffer compact()
Description copied from class: ByteBuffer
Compacts this byte buffer.

The remaining bytes will be moved to the head of the buffer, staring from position zero. Then the position is set to remaining(); the limit is set to capacity; the mark is cleared.

Specified by:
compact in class ByteBuffer
Returns:
This buffer

duplicate

public ByteBuffer duplicate()
Description copied from class: ByteBuffer
Returns a duplicated buffer that shares content with this buffer.

The duplicated buffer's position, limit, capacity and mark are the same as this buffer. The duplicated buffer's readonly property and byte order are same as this buffer too.

The new buffer shares content with this buffer, which means either buffer's change of content will be visible to the other. The two buffer's position, limit and mark are independent.

Specified by:
duplicate in class ByteBuffer
Returns:
A duplicated buffer that shares content with this buffer.

isReadOnly

public boolean isReadOnly()
Description copied from class: Buffer
Returns whether this buffer is readonly or not.

Specified by:
isReadOnly in class Buffer
Returns:
Whether this buffer is readonly or not.

protectedArray

protected byte[] protectedArray()
Description copied from class: ByteBuffer
Child class implements this method to realize array().

Specified by:
protectedArray in class ByteBuffer
Returns:
see array()

protectedArrayOffset

protected int protectedArrayOffset()
Description copied from class: ByteBuffer
Child class implements this method to realize arrayOffset().

Specified by:
protectedArrayOffset in class ByteBuffer
Returns:
see arrayOffset()

protectedHasArray

protected boolean protectedHasArray()
Description copied from class: ByteBuffer
Child class implements this method to realize hasArray().

Specified by:
protectedHasArray in class ByteBuffer
Returns:
see hasArray()

put

public ByteBuffer put(byte b)
Description copied from class: ByteBuffer
Writes the given byte to the current position and increase the position by 1.

Specified by:
put in class ByteBuffer
Parameters:
b - The byte to write
Returns:
This buffer

put

public ByteBuffer put(int index,
                      byte b)
Description copied from class: ByteBuffer
Write a byte to the specified index of this buffer and the position is not changed.

Specified by:
put in class ByteBuffer
Parameters:
index - The index, must be no less than zero and less than the limit
b - The byte to write
Returns:
This buffer

put

public ByteBuffer put(byte[] src,
                      int off,
                      int len)
Description copied from class: ByteBuffer
Writes bytes in the given byte array, starting from the specified offset, to the current position and increase the position by the number of bytes written.

Overrides:
put in class ByteBuffer
Parameters:
src - The source byte array
off - The offset of byte array, must be no less than zero and no greater than src.length
len - The number of bytes to write, must be no less than zero and no greater than src.length - off
Returns:
This buffer

putDouble

public ByteBuffer putDouble(double value)
Description copied from class: ByteBuffer
Writes the given double to the current position and increase the position by 8.

The double is converted to bytes using the current byte order.

Specified by:
putDouble in class ByteBuffer
Parameters:
value - The double to write
Returns:
This buffer

putDouble

public ByteBuffer putDouble(int index,
                            double value)
Description copied from class: ByteBuffer
Write a double to the specified index of this buffer.

The double is converted to bytes using the current byte order. The position is not changed.

Specified by:
putDouble in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 8
value - The double to write
Returns:
This buffer

putFloat

public ByteBuffer putFloat(float value)
Description copied from class: ByteBuffer
Writes the given float to the current position and increase the position by 4.

The float is converted to bytes using the current byte order.

Specified by:
putFloat in class ByteBuffer
Parameters:
value - The float to write
Returns:
This buffer

putFloat

public ByteBuffer putFloat(int index,
                           float value)
Description copied from class: ByteBuffer
Write a float to the specified index of this buffer.

The float is converted to bytes using the current byte order. The position is not changed.

Specified by:
putFloat in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 4
value - The float to write
Returns:
This buffer

putInt

public ByteBuffer putInt(int value)
Description copied from class: ByteBuffer
Writes the given int to the current position and increase the position by 4.

The int is converted to bytes using the current byte order.

Specified by:
putInt in class ByteBuffer
Parameters:
value - The int to write
Returns:
This buffer

putInt

public ByteBuffer putInt(int index,
                         int value)
Description copied from class: ByteBuffer
Write a int to the specified index of this buffer.

The int is converted to bytes using the current byte order. The position is not changed.

Specified by:
putInt in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 4
value - The int to write
Returns:
This buffer

putLong

public ByteBuffer putLong(int index,
                          long value)
Description copied from class: ByteBuffer
Write a long to the specified index of this buffer.

The long is converted to bytes using the current byte order. The position is not changed.

Specified by:
putLong in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 8
value - The long to write
Returns:
This buffer

putLong

public ByteBuffer putLong(long value)
Description copied from class: ByteBuffer
Writes the given long to the current position and increase the position by 8.

The long is converted to bytes using the current byte order.

Specified by:
putLong in class ByteBuffer
Parameters:
value - The long to write
Returns:
This buffer

putShort

public ByteBuffer putShort(int index,
                           short value)
Description copied from class: ByteBuffer
Write a short to the specified index of this buffer.

The short is converted to bytes using the current byte order. The position is not changed.

Specified by:
putShort in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 2
value - The short to write
Returns:
This buffer

putShort

public ByteBuffer putShort(short value)
Description copied from class: ByteBuffer
Writes the given short to the current position and increase the position by 2.

The short is converted to bytes using the current byte order.

Specified by:
putShort in class ByteBuffer
Parameters:
value - The short to write
Returns:
This buffer

slice

public ByteBuffer slice()
Description copied from class: ByteBuffer
Returns a sliced buffer that shares content with this buffer.

The sliced buffer's capacity will be this buffer's remaining(), and its zero position will correspond to this buffer's current position. The new buffer's position will be 0, limit will be its capacity, and its mark is unset. The new buffer's readonly property and byte order are same as this buffer.

The new buffer shares content with this buffer, which means either buffer's change of content will be visible to the other. The two buffer's position, limit and mark are independent.

Specified by:
slice in class ByteBuffer
Returns:
A sliced buffer that shares content with this buffer.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature