Build 1.0_r1(from source)

java.nio
Class ReadOnlyDirectByteBuffer

java.lang.Object
  extended by java.nio.Buffer
      extended by java.nio.ByteBuffer
          extended by java.nio.BaseByteBuffer
              extended by java.nio.DirectByteBuffer
                  extended by java.nio.ReadOnlyDirectByteBuffer
All Implemented Interfaces:
Comparable<ByteBuffer>, org.apache.harmony.nio.internal.DirectBuffer

final class ReadOnlyDirectByteBuffer
extends DirectByteBuffer

DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer compose the implementation of platform memory based byte buffers.

ReadOnlyDirectByteBuffer extends DirectByteBuffer with all the write methods throwing read only exception.

This class is marked final for runtime performance.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.nio.DirectByteBuffer
DirectByteBuffer.SafeAddress
 
Field Summary
 
Fields inherited from class java.nio.DirectByteBuffer
offset, safeAddress
 
Fields inherited from class java.nio.ByteBuffer
order
 
Fields inherited from class java.nio.Buffer
_elementSizeShift, capacity, limit, mark, position, UNSET_MARK
 
Constructor Summary
protected ReadOnlyDirectByteBuffer(DirectByteBuffer.SafeAddress address, int capacity, int offset)
           
protected ReadOnlyDirectByteBuffer(org.apache.harmony.luni.platform.PlatformAddress address, int capacity, int offset)
           
 
Method Summary
 ByteBuffer asReadOnlyBuffer()
          Returns a readonly buffer that shares content with this buffer.
 ByteBuffer compact()
          Compacts this byte buffer.
(package private) static ReadOnlyDirectByteBuffer copy(DirectByteBuffer 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.
 ByteBuffer put(byte value)
          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(ByteBuffer buf)
          Writes all the remaining bytes of the src byte buffer to this buffer's current position, and increase both buffers' position by the number of bytes copied.
 ByteBuffer put(int index, byte value)
          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.DirectByteBuffer
addressValidityCheck, free, get, get, get, getBaseAddress, getByteCapacity, getDouble, getDouble, getEffectiveAddress, getFloat, getFloat, getInt, getInt, getLong, getLong, getShort, getShort, isAddressValid, isDirect, protectedArray, protectedArrayOffset, protectedHasArray
 
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, 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

ReadOnlyDirectByteBuffer

protected ReadOnlyDirectByteBuffer(DirectByteBuffer.SafeAddress address,
                                   int capacity,
                                   int offset)

ReadOnlyDirectByteBuffer

protected ReadOnlyDirectByteBuffer(org.apache.harmony.luni.platform.PlatformAddress address,
                                   int capacity,
                                   int offset)
Method Detail

copy

static ReadOnlyDirectByteBuffer copy(DirectByteBuffer 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.

put

public ByteBuffer put(byte value)
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:
value - The byte to write
Returns:
This buffer

put

public ByteBuffer put(int index,
                      byte value)
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
value - 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

put

public ByteBuffer put(ByteBuffer buf)
Description copied from class: ByteBuffer
Writes all the remaining bytes of the src byte buffer to this buffer's current position, and increase both buffers' position by the number of bytes copied.

Overrides:
put in class ByteBuffer
Parameters:
buf - The source byte buffer
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