Build 1.0_r1(from source)

java.nio
Class DirectByteBuffer

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

abstract class DirectByteBuffer
extends BaseByteBuffer
implements org.apache.harmony.nio.internal.DirectBuffer

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

DirectByteBuffer implements all the shared readonly methods and is extended by the other two classes.

All methods are marked final for runtime performance.


Nested Class Summary
(package private) static class DirectByteBuffer.SafeAddress
           
 
Field Summary
protected  int offset
           
protected  DirectByteBuffer.SafeAddress 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
DirectByteBuffer(DirectByteBuffer.SafeAddress address, int capacity, int offset)
           
DirectByteBuffer(int capacity)
           
 
Method Summary
 void addressValidityCheck()
           
 void free()
          Explicitly free the memory used by this direct byte buffer.
 byte get()
          Returns the byte at the current position and increase the position by 1.
 ByteBuffer get(byte[] dest, int off, int len)
          Reads bytes from the current position into the specified byte array, starting from the specified offset, and increase the position by the number of bytes read.
 byte get(int index)
          Returns a byte at the specified index, and the position is not changed.
 org.apache.harmony.luni.platform.PlatformAddress getBaseAddress()
           
 int getByteCapacity()
           
 double getDouble()
          Returns the double at the current position and increase the position by 8.
 double getDouble(int index)
          Returns the double at the specified index.
 org.apache.harmony.luni.platform.PlatformAddress getEffectiveAddress()
          Returns the platform address of the start of this buffer instance.
 float getFloat()
          Returns the float at the current position and increase the position by 4.
 float getFloat(int index)
          Returns the float at the specified index.
 int getInt()
          Returns the int at the current position and increase the position by 4.
 int getInt(int index)
          Returns the int at the specified index.
 long getLong()
          Returns the long at the current position and increase the position by 8.
 long getLong(int index)
          Returns the long at the specified index.
 short getShort()
          Returns the short at the current position and increase the position by 2.
 short getShort(int index)
          Returns the short at the specified index.
 boolean isAddressValid()
           
 boolean isDirect()
          Returns true if this buffer is direct.
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().
 
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, asReadOnlyBuffer, compact, compareTo, duplicate, equals, get, hasArray, hashCode, order, order, orderImpl, put, put, put, put, put, putDouble, putDouble, putFloat, putFloat, putInt, putInt, putLong, putLong, putShort, putShort, slice, toString, wrap, wrap
 
Methods inherited from class java.nio.Buffer
capacity, clear, flip, hasRemaining, isReadOnly, limit, limit, mark, position, position, remaining, reset, rewind
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

safeAddress

protected final DirectByteBuffer.SafeAddress safeAddress

offset

protected final int offset
Constructor Detail

DirectByteBuffer

DirectByteBuffer(int capacity)

DirectByteBuffer

DirectByteBuffer(DirectByteBuffer.SafeAddress address,
                 int capacity,
                 int offset)
Method Detail

get

public final ByteBuffer get(byte[] dest,
                            int off,
                            int len)
Description copied from class: ByteBuffer
Reads bytes from the current position into the specified byte array, starting from the specified offset, and increase the position by the number of bytes read.

Overrides:
get in class ByteBuffer
Parameters:
dest - The target byte array
off - The offset of the byte array, must be no less than zero and no greater than dest.length
len - The number of bytes to read, must be no less than zero and no greater than dest.length - off
Returns:
This buffer

get

public final byte get()
Description copied from class: ByteBuffer
Returns the byte at the current position and increase the position by 1.

Specified by:
get in class ByteBuffer
Returns:
The byte at the current position.

get

public final byte get(int index)
Description copied from class: ByteBuffer
Returns a byte at the specified index, and the position is not changed.

Specified by:
get in class ByteBuffer
Parameters:
index - The index, must be no less than zero and less than limit
Returns:
A byte at the specified index.

getDouble

public final double getDouble()
Description copied from class: ByteBuffer
Returns the double at the current position and increase the position by 8.

The 8 bytes start from the current position are composed into a double according to current byte order and returned. The position increases by 8.

Specified by:
getDouble in class ByteBuffer
Returns:
The double at the current position.

getDouble

public final double getDouble(int index)
Description copied from class: ByteBuffer
Returns the double at the specified index.

The 8 bytes start from the specified index are composed into a double according to current byte order and returned. The position is not changed.

Specified by:
getDouble in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 8
Returns:
The double at the specified index.

getFloat

public final float getFloat()
Description copied from class: ByteBuffer
Returns the float at the current position and increase the position by 4.

The 4 bytes start from the current position are composed into a float according to current byte order and returned. The position increases by 4.

Specified by:
getFloat in class ByteBuffer
Returns:
The float at the current position.

getFloat

public final float getFloat(int index)
Description copied from class: ByteBuffer
Returns the float at the specified index.

The 4 bytes start from the specified index are composed into a float according to current byte order and returned. The position is not changed.

Specified by:
getFloat in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 4
Returns:
The float at the specified index.

getInt

public final int getInt()
Description copied from class: ByteBuffer
Returns the int at the current position and increase the position by 4.

The 4 bytes start from the current position are composed into a int according to current byte order and returned. The position increases by 4.

Specified by:
getInt in class ByteBuffer
Returns:
The int at the current position.

getInt

public final int getInt(int index)
Description copied from class: ByteBuffer
Returns the int at the specified index.

The 4 bytes start from the specified index are composed into a int according to current byte order and returned. The position is not changed.

Specified by:
getInt in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 4
Returns:
The int at the specified index.

getLong

public final long getLong()
Description copied from class: ByteBuffer
Returns the long at the current position and increase the position by 8.

The 8 bytes start from the current position are composed into a long according to current byte order and returned. The position increases by 8.

Specified by:
getLong in class ByteBuffer
Returns:
The long at the current position.

getLong

public final long getLong(int index)
Description copied from class: ByteBuffer
Returns the long at the specified index.

The 8 bytes start from the specified index are composed into a long according to current byte order and returned. The position is not changed.

Specified by:
getLong in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 8
Returns:
The long at the specified index.

getShort

public final short getShort()
Description copied from class: ByteBuffer
Returns the short at the current position and increase the position by 2.

The 2 bytes start from the current position are composed into a short according to current byte order and returned. The position increases by 2.

Specified by:
getShort in class ByteBuffer
Returns:
The short at the current position.

getShort

public final short getShort(int index)
Description copied from class: ByteBuffer
Returns the short at the specified index.

The 2 bytes start from the specified index are composed into a short according to current byte order and returned. The position is not changed.

Specified by:
getShort in class ByteBuffer
Parameters:
index - The index, must be no less than zero and equal or less than limit - 2
Returns:
The short at the specified index.

isDirect

public final boolean isDirect()
Description copied from class: ByteBuffer
Returns true if this buffer is direct.

A byte buffer is direct, if it is based on a byte buffer and the byte buffer is direct.

Specified by:
isDirect in class ByteBuffer
Returns:
True if this buffer is direct.

isAddressValid

public final boolean isAddressValid()
Specified by:
isAddressValid in interface org.apache.harmony.nio.internal.DirectBuffer

addressValidityCheck

public final void addressValidityCheck()
Specified by:
addressValidityCheck in interface org.apache.harmony.nio.internal.DirectBuffer

getBaseAddress

public final org.apache.harmony.luni.platform.PlatformAddress getBaseAddress()
Specified by:
getBaseAddress in interface org.apache.harmony.nio.internal.DirectBuffer

getEffectiveAddress

public final org.apache.harmony.luni.platform.PlatformAddress getEffectiveAddress()
Returns the platform address of the start of this buffer instance. You must not attempt to free the returned address!! It may not be an address that was explicitly malloc'ed (i.e. if this buffer is the result of a split); and it may be memory shared by multiple buffers.

If you can guarantee that you want to free the underlying memory call the #free() method on this instance -- generally applications will rely on the garbage collector to autofree this memory.

Specified by:
getEffectiveAddress in interface org.apache.harmony.nio.internal.DirectBuffer
Returns:
the effective address of the start of the buffer.
Throws:
IllegalStateException - if this buffer address is known to have been freed previously.

free

public final void free()
Explicitly free the memory used by this direct byte buffer. If the memory has already been freed then this is a no-op. Once the memory has been freed then operations requiring access to the memory will throw an IllegalStateException.

Note this is is possible that the memory is freed by code that reaches into the address and explicitly frees it 'beneith' us -- this is bad form.

Specified by:
free in interface org.apache.harmony.nio.internal.DirectBuffer

protectedArray

protected final 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 final 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 final boolean protectedHasArray()
Description copied from class: ByteBuffer
Child class implements this method to realize hasArray().

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

getByteCapacity

public final int getByteCapacity()
Specified by:
getByteCapacity in interface org.apache.harmony.nio.internal.DirectBuffer

Build 1.0_r1(from source)

Please submit a feedback, bug or feature