FileDocCategorySizeDatePackage
LongToByteBufferAdapter.javaAPI DocAndroid 1.5 API5996Wed May 06 22:41:04 BST 2009java.nio

LongToByteBufferAdapter

public final class LongToByteBufferAdapter extends LongBuffer implements org.apache.harmony.nio.internal.DirectBuffer
This class wraps a byte buffer to be a long buffer.

Implementation notice:

  • After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the adapter any more.
  • The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position and limit.

Fields Summary
private final ByteBuffer
byteBuffer
Constructors Summary
LongToByteBufferAdapter(ByteBuffer byteBuffer)

        super((byteBuffer.capacity() >> 3));
        this.byteBuffer = byteBuffer;
        this.byteBuffer.clear();
    
Methods Summary
public voidaddressValidityCheck()

        if (byteBuffer instanceof DirectBuffer) {
            ((DirectBuffer)byteBuffer).addressValidityCheck();
        } else {
            assert false : byteBuffer;
        }
    
public java.nio.LongBufferasReadOnlyBuffer()

        LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer
                .asReadOnlyBuffer());
        buf.limit = limit;
        buf.position = position;
        buf.mark = mark;
        return buf;
    
public java.nio.LongBuffercompact()

        if (byteBuffer.isReadOnly()) {
            throw new ReadOnlyBufferException();
        }
        byteBuffer.limit(limit << 3);
        byteBuffer.position(position << 3);
        byteBuffer.compact();
        byteBuffer.clear();
        position = limit - position;
        limit = capacity;
        mark = UNSET_MARK;
        return this;
    
public java.nio.LongBufferduplicate()

        LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer
                .duplicate());
        buf.limit = limit;
        buf.position = position;
        buf.mark = mark;
        return buf;
    
public voidfree()

        if (byteBuffer instanceof DirectBuffer) {
            ((DirectBuffer)byteBuffer).free();
        } else {
            assert false : byteBuffer;
        }   
    
public longget()

        if (position == limit) {
            throw new BufferUnderflowException();
        }
        return byteBuffer.getLong(position++ << 3);
    
public longget(int index)

        if (index < 0 || index >= limit) {
            throw new IndexOutOfBoundsException();
        }
        return byteBuffer.getLong(index << 3);
    
public org.apache.harmony.luni.platform.PlatformAddressgetBaseAddress()

        if (byteBuffer instanceof DirectBuffer) {
            return ((DirectBuffer)byteBuffer).getBaseAddress();
        } else {
            assert false : byteBuffer;
            return null;
        }
    
public intgetByteCapacity()

        if (byteBuffer instanceof DirectBuffer) {
            return ((DirectBuffer)byteBuffer).getByteCapacity();
        } else {
            assert false : byteBuffer;
            return -1;
        }            
    
public org.apache.harmony.luni.platform.PlatformAddressgetEffectiveAddress()

        if (byteBuffer instanceof DirectBuffer) {
            return ((DirectBuffer)byteBuffer).getEffectiveAddress();
        } else {
            assert false : byteBuffer;
            return null;
        }
    
public booleanisAddressValid()

        if (byteBuffer instanceof DirectBuffer) {
            return ((DirectBuffer)byteBuffer).isAddressValid();
        } else {
            assert false : byteBuffer;
            return false;
        }
    
public booleanisDirect()

        return byteBuffer.isDirect();
    
public booleanisReadOnly()

        return byteBuffer.isReadOnly();
    
public java.nio.ByteOrderorder()

        return byteBuffer.order();
    
protected long[]protectedArray()

        throw new UnsupportedOperationException();
    
protected intprotectedArrayOffset()

        throw new UnsupportedOperationException();
    
protected booleanprotectedHasArray()

        return false;
    
public java.nio.LongBufferput(long c)

        if (position == limit) {
            throw new BufferOverflowException();
        }
        byteBuffer.putLong(position++ << 3, c);
        return this;
    
public java.nio.LongBufferput(int index, long c)

        if (index < 0 || index >= limit) {
            throw new IndexOutOfBoundsException();
        }
        byteBuffer.putLong(index << 3, c);
        return this;
    
public java.nio.LongBufferslice()

        byteBuffer.limit(limit << 3);
        byteBuffer.position(position << 3);
        LongBuffer result = new LongToByteBufferAdapter(byteBuffer.slice());
        byteBuffer.clear();
        return result;
    
static java.nio.LongBufferwrap(java.nio.ByteBuffer byteBuffer)

        return new LongToByteBufferAdapter(byteBuffer.slice());