FileDocCategorySizeDatePackage
ByteBufferImpl.javaAPI DocphoneME MR2 API (J2ME)9927Wed May 02 18:00:48 BST 2007java.nio

ByteBufferImpl

public class ByteBufferImpl extends ByteBuffer
A Buffer storing byte data.

Fields Summary
Constructors Summary
ByteBufferImpl(int capacity, byte[] array, int arrayOffset, ByteBuffer directParent)

        this.array = array;
        this.arrayOffset = arrayOffset;

        this.capacity = capacity;
        this.limit = capacity;
        this.position = 0;

        this.isDirect = array == null;
        this.directParent = directParent;
    
Methods Summary
static native int_allocNative(int capacity)

static native void_copyBytes(int srcAddress, int dstAddress, int bytes)

static native byte_getByte(int address)

static native void_getBytes(int address, byte[] dst, int offset, int length)

static native float_getFloat(int address)

static native void_getFloats(int address, float[] dst, int offset, int length)

static native int_getInt(int address)

static native void_getInts(int address, int[] dst, int offset, int length)

static native short_getShort(int address)

static native void_getShorts(int address, short[] dst, int offset, int length)

static native void_putByte(int address, byte value)

static native void_putBytes(int address, byte[] dst, int offset, int length)

static native void_putFloat(int address, float value)

static native void_putFloats(int address, float[] dst, int offset, int length)

static native void_putInt(int address, int value)

static native void_putInts(int address, int[] dst, int offset, int length)

static native void_putShort(int address, short value)

static native void_putShorts(int address, short[] dst, int offset, int length)

public java.nio.FloatBufferasFloatBuffer()

        int pos = position + (isDirect ? arrayOffset : 0);
        return new FloatBufferImpl(this, remaining() >> 2,
                                   null, pos, isDirect);
    
public java.nio.IntBufferasIntBuffer()

        int pos = position + (isDirect ? arrayOffset : 0);
        return new IntBufferImpl(this, remaining() >> 2,
                                 null, pos, isDirect);
    
public java.nio.ShortBufferasShortBuffer()

        int pos = position + (isDirect ? arrayOffset : 0);
        return new ShortBufferImpl(this, remaining() >> 1,
                                   null, pos, isDirect);
    
public voiddispose()

        // Need revisit
        this.disposed = true;
    
private native voidfinalize()

public byteget()

        if (position >= limit) {
            throw new BufferUnderflowException();
        }
	return get(position++);
    
public byteget(int index)

        if (index < 0 || index >= limit) {
            throw new IndexOutOfBoundsException();
        }
	if (isDirect) {
	    return _getByte(arrayOffset + index);
	} else {
	   return array[arrayOffset + index]; 
	}
    
public floatgetFloat()

        return Float.intBitsToFloat(getInt());
    
public floatgetFloat(int index)

        return Float.intBitsToFloat(getInt(index));
    
public intgetInt()

        if (position >= limit - 3) {
            throw new BufferUnderflowException();
        }
        int x = getInt(position);
        position += 4;
        return x;
    
public intgetInt(int index)

        if (index < 0 || index >= limit - 3) {
            throw new IndexOutOfBoundsException();
        }
        int x0, x1, x2, x3;
	if (isDirect) {
            index += arrayOffset;
	    x0 = _getByte(index++);
	    x1 = _getByte(index++);
	    x2 = _getByte(index++);
	    x3 = _getByte(index);
	} else {
            index += arrayOffset;
            x0 =  array[index++]; 
            x1 =  array[index++]; 
            x2 =  array[index++]; 
            x3 =  array[index++]; 
	}

        if (GLConfiguration.IS_BIG_ENDIAN) {
            return (( x0         << 24) |
                    ((x1 & 0xff) << 16) |
                    ((x2 & 0xff) <<  8) |
                     (x3 & 0xff));
        } else {
            return (( x3         << 24) |
                    ((x2 & 0xff) << 16) |
                    ((x1 & 0xff) <<  8) |
                     (x0 & 0xff));
        }
    
public shortgetShort()

        if (position >= limit - 1) {
            throw new BufferUnderflowException();
        }
        short s = getShort(position);
        position += 2;
        return s;
    
public shortgetShort(int index)

        if (index < 0 || index >= limit - 1) {
            throw new IndexOutOfBoundsException();
        }
        int x0, x1;
	if (isDirect) {
            index += arrayOffset;
	    x0 = _getByte(index++);
	    x1 = _getByte(index++);
	} else {
            index += arrayOffset;
            x0 =  array[index++]; 
            x1 =  array[index++]; 
	}

        if (GLConfiguration.IS_BIG_ENDIAN) {
            return (short)(((x0 & 0xff) << 8) | (x1 & 0xff));
        } else {
            return (short)(((x1 & 0xff) << 8) | (x0 & 0xff));
        }
    
public static booleanisBigEndian()

        return GLConfiguration.IS_BIG_ENDIAN;
    
public booleanisDirect()

	return isDirect;
    
public intnativeAddress()

	return arrayOffset;
    
public java.nio.ByteBufferput(byte b)

        if (position >= limit) {
            throw new BufferOverflowException();
        }
	return put(position++, b);
    
public java.nio.ByteBufferput(int index, byte b)

        if (index < 0 || index >= limit) {
            throw new IndexOutOfBoundsException();
        }
        if (isDirect) {
	    _putByte(arrayOffset + index, b);
	} else {
	    array[arrayOffset + index] = b;
	}
	return this;
    
public java.nio.ByteBufferputFloat(float value)

        return putInt(Float.floatToIntBits(value));
    
public java.nio.ByteBufferputFloat(int index, float value)

        return putInt(index, Float.floatToIntBits(value));
    
public java.nio.ByteBufferputInt(int value)

        if (position >= limit - 3) {
            throw new BufferOverflowException();
        }
        putInt(position, value);
        position += 4;
        return this;
    
public java.nio.ByteBufferputInt(int index, int value)

        if (index < 0 || index >= limit - 3) {
            throw new IndexOutOfBoundsException();
        }

        byte x0, x1, x2, x3;
        if (GLConfiguration.IS_BIG_ENDIAN) {
            x0 = (byte)(value >> 24);
            x1 = (byte)(value >> 16);
            x2 = (byte)(value >> 8);
            x3 = (byte)(value);
        } else {
            x3 = (byte)(value >> 24);
            x2 = (byte)(value >> 16);
            x1 = (byte)(value >> 8);
            x0 = (byte)(value);
        }

	if (isDirect) {
            index += arrayOffset;
	    _putByte(index++, x0);
	    _putByte(index++, x1);
	    _putByte(index++, x2);
	    _putByte(index,   x3);
	} else {
            index += arrayOffset;
            array[index++] = x0;
            array[index++] = x1;
            array[index++] = x2;
            array[index  ] = x3;
	}
        
        return this;
    
public java.nio.ByteBufferputShort(short value)

        if (position >= limit - 1) {
            throw new BufferOverflowException();
        }
        putShort(position, value);
        position += 2;
        return this;
    
public java.nio.ByteBufferputShort(int index, short value)

        if (index < 0 || index >= limit - 1) {
            throw new IndexOutOfBoundsException();
        }

        byte x0, x1;
        if (GLConfiguration.IS_BIG_ENDIAN) {
            x0 = (byte)(value >> 8);
            x1 = (byte)(value);
        } else {
            x1 = (byte)(value >> 8);
            x0 = (byte)(value);
        }

	if (isDirect) {
            index += arrayOffset;
	    _putByte(index++, x0);
	    _putByte(index,   x1);
	} else {
            index += arrayOffset;
            array[index++] = x0;
            array[index  ] = x1;
	}
        
        return this;
    
public java.nio.ByteBufferslice()

        return new ByteBufferImpl(limit - position, array,
                arrayOffset + position, this);