FileDocCategorySizeDatePackage
ReadWriteDirectByteBuffer.javaAPI DocAndroid 1.5 API10649Wed May 06 22:41:04 BST 2009java.nio

ReadWriteDirectByteBuffer

public final class ReadWriteDirectByteBuffer extends DirectByteBuffer
DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer compose the implementation of platform memory based byte buffers.

ReadWriteDirectByteBuffer extends DirectByteBuffer with all the write methods.

This class is marked final for runtime performance.

Fields Summary
Constructors Summary
ReadWriteDirectByteBuffer(int capacity)

        super(capacity);
    
ReadWriteDirectByteBuffer(int pointer, int capacity)

        this(PlatformAddressFactory.on(pointer, capacity),capacity,0);
    
ReadWriteDirectByteBuffer(SafeAddress address, int capacity, int offset)

        super(address, capacity, offset);
    
ReadWriteDirectByteBuffer(org.apache.harmony.luni.platform.PlatformAddress address, int aCapacity, int anOffset)

        super(new SafeAddress(address), aCapacity, anOffset);
    
Methods Summary
public java.nio.ByteBufferasReadOnlyBuffer()

        return ReadOnlyDirectByteBuffer.copy(this, mark);
    
public java.nio.ByteBuffercompact()

        PlatformAddress effectiveAddress = getEffectiveAddress();
        effectiveAddress.offsetBytes(position).moveTo(effectiveAddress,
                remaining());
        position = limit - position;
        limit = capacity;
        mark = UNSET_MARK;
        return this;
    
static java.nio.ReadWriteDirectByteBuffercopy(java.nio.DirectByteBuffer other, int markOfOther)

        ReadWriteDirectByteBuffer buf = new ReadWriteDirectByteBuffer(
                other.safeAddress, other.capacity(), other.offset);
        buf.limit = other.limit();
        buf.position = other.position();
        buf.mark = markOfOther;
        buf.order(other.order());
        return buf;
    
public java.nio.ByteBufferduplicate()

        return copy(this, mark);
    
intgetAddress()

        return this.safeAddress.address.toInt();
    
public booleanisReadOnly()

        return false;
    
public java.nio.ByteBufferput(byte value)

        if (position == limit) {
            throw new BufferOverflowException();
        }
        getBaseAddress().setByte(offset + position++, value);
        return this;
    
public java.nio.ByteBufferput(int index, byte value)

        if (index < 0 || index >= limit) {
            throw new IndexOutOfBoundsException();
        }
        getBaseAddress().setByte(offset + index, value);
        return this;
    
public java.nio.ByteBufferput(byte[] src, int off, int len)

        int length = src.length;
        if (off < 0 || len < 0 || (long)off + (long)len > length) {
            throw new IndexOutOfBoundsException();
        }
        if (len > remaining()) {
            throw new BufferOverflowException();
        }
        if (isReadOnly()) {
            throw new ReadOnlyBufferException();
        }
        getBaseAddress().setByteArray(offset + position, src, off,
                len);
        position += len;
        return this;
    
java.nio.ByteBufferput(short[] src, int off, int len)
Writes shorts in the given short array, starting from the specified offset, to the current position and increase the position by the number of shorts written.

param
src The source short array
param
off The offset of short array, must be no less than zero and no greater than src.length
param
len The number of shorts to write, must be no less than zero and no greater than src.length - off
return
This buffer
exception
BufferOverflowException If remaining() is less than len
exception
IndexOutOfBoundsException If either off or len is invalid
exception
ReadOnlyBufferException If no changes may be made to the contents of this buffer

        int length = src.length;
        if (off < 0 || len < 0 || (long)off + (long)len > length) {
            throw new IndexOutOfBoundsException();
        }
        if (len << 1 > remaining()) {
            throw new BufferOverflowException();
        }
        if (isReadOnly()) {
            throw new ReadOnlyBufferException();
        }
        boolean swap = order() != ByteOrder.nativeOrder();
        getBaseAddress().setShortArray(offset + position, src, off, len, swap);
        position += len << 1;
        return this;
    
java.nio.ByteBufferput(int[] src, int off, int len)
Writes ints in the given int array, starting from the specified offset, to the current position and increase the position by the number of ints written.

param
src The source int array
param
off The offset of int array, must be no less than zero and no greater than src.length
param
len The number of ints to write, must be no less than zero and no greater than src.length - off
return
This buffer
exception
BufferOverflowException If remaining() is less than len
exception
IndexOutOfBoundsException If either off or len is invalid
exception
ReadOnlyBufferException If no changes may be made to the contents of this buffer

        int length = src.length;
        if (off < 0 || len < 0 || (long)off + (long)len > length) {
            throw new IndexOutOfBoundsException();
        }
        if (len << 2 > remaining()) {
            throw new BufferOverflowException();
        }
        if (isReadOnly()) {
            throw new ReadOnlyBufferException();
        }
        boolean swap = order() != ByteOrder.nativeOrder();
        getBaseAddress().setIntArray(offset + position, src, off, len, swap);
        position += len << 2;
        return this;
    
public java.nio.ByteBufferputDouble(double value)

        int newPosition = position + 8;
        if (newPosition > limit) {
            throw new BufferOverflowException();
        }
        getBaseAddress().setDouble(offset + position, value, order);
        position = newPosition;
        return this;
    
public java.nio.ByteBufferputDouble(int index, double value)

        if (index < 0 || (long)index + 8 > limit) {
            throw new IndexOutOfBoundsException();
        }
        getBaseAddress().setDouble(offset + index, value, order);
        return this;
    
public java.nio.ByteBufferputFloat(float value)

        int newPosition = position + 4;
        if (newPosition > limit) {
            throw new BufferOverflowException();
        }
        getBaseAddress().setFloat(offset + position, value, order);
        position = newPosition;
        return this;
    
public java.nio.ByteBufferputFloat(int index, float value)

        if (index < 0 || (long)index + 4 > limit) {
            throw new IndexOutOfBoundsException();
        }
        getBaseAddress().setFloat(offset + index, value, order);
        return this;
    
public java.nio.ByteBufferputInt(int value)

        int newPosition = position + 4;
        if (newPosition > limit) {
            throw new BufferOverflowException();
        }
        getBaseAddress().setInt(offset + position, value, order);
        position = newPosition;
        return this;
    
public java.nio.ByteBufferputInt(int index, int value)

        if (index < 0 || (long)index + 4 > limit) {
            throw new IndexOutOfBoundsException();
        }
        getBaseAddress().setInt(offset + index, value, order);
        return this;
    
public java.nio.ByteBufferputLong(long value)

        int newPosition = position + 8;
        if (newPosition > limit) {
            throw new BufferOverflowException();
        }
        getBaseAddress().setLong(offset + position, value, order);
        position = newPosition;
        return this;
    
public java.nio.ByteBufferputLong(int index, long value)

        if (index < 0 || (long)index + 8 > limit) {
            throw new IndexOutOfBoundsException();
        }
        getBaseAddress().setLong(offset + index, value, order);
        return this;
    
public java.nio.ByteBufferputShort(short value)

        int newPosition = position + 2;
        if (newPosition > limit) {
            throw new BufferOverflowException();
        }
        getBaseAddress().setShort(offset + position, value, order);
        position = newPosition;
        return this;
    
public java.nio.ByteBufferputShort(int index, short value)

        if (index < 0 || (long)index + 2 > limit) {
            throw new IndexOutOfBoundsException();
        }
        getBaseAddress().setShort(offset + index, value, order);
        return this;
    
public java.nio.ByteBufferslice()

        ReadWriteDirectByteBuffer buf = new ReadWriteDirectByteBuffer(
                safeAddress, remaining(), offset + position);
        buf.order = order;
        return buf;