FileDocCategorySizeDatePackage
BufferManager.javaAPI DocphoneME MR2 API (J2ME)4596Wed May 02 18:00:48 BST 2007com.sun.jsr239

BufferManager

public class BufferManager extends Object

Fields Summary
static Hashtable
bufferStrongReferences
static Hashtable
bufferWeakReferences
Constructors Summary
Methods Summary
public static native void_getBytes(int address, byte[] dst, int offset, int length)

public static voidgetBytes(java.nio.Buffer buf, int boffset, byte[] dst, int offset, int length)

        int address = GL10Impl._getNativeAddress(buf, 0);
        int capacity = buf.capacity();
        
        if (buf instanceof ByteBuffer) {
            ByteBuffer bbi = (ByteBuffer)buf;
            if (!bbi.isDirect()) {
                throw new IllegalArgumentException("!isDirect");
            }
        } else if (buf instanceof ShortBuffer) {
            ShortBuffer sbi = (ShortBuffer)buf;
            if (!sbi.isDirect()) {
                throw new IllegalArgumentException("!isDirect");
            }
            capacity *= 2;
        } else if (buf instanceof IntBuffer) {
            IntBuffer ibi = (IntBuffer)buf;
            if (!ibi.isDirect()) {
                throw new IllegalArgumentException("!isDirect");
            }
            capacity *= 4;
        } else if (buf instanceof FloatBuffer) {
            FloatBuffer fbi = (FloatBuffer)buf;
            if (!fbi.isDirect()) {
                throw new IllegalArgumentException("!isDirect");
            }
            capacity *= 4;
        } else {
            throw new IllegalArgumentException("Unknown buffer type!");
        }
        
        if (boffset < 0 || boffset + length > capacity) {
            throw new IllegalArgumentException("boffset out of bounds");
        }
        if (offset < 0 || offset + length > dst.length) {
            throw new IllegalArgumentException("offset out of bounds");
        }

        _getBytes(address + boffset, dst, offset, length);
    
public static synchronized voidnewBuffer(java.nio.Buffer b, int pointer)


    // Record the native address of this buffer along with a
    // weak reference.
            
        bufferWeakReferences.put(new WeakReference(b), new Integer(pointer));
    
public static synchronized voidreleaseBuffer(java.nio.Buffer b)

        if (b == null) {
            return;
        }

        Object o = bufferStrongReferences.get(b);
        int refs = (o == null) ? 0 : ((Integer)o).intValue();
        if (refs > 1) {
            bufferStrongReferences.put(b, new Integer(refs - 1));
        } else {
            bufferStrongReferences.remove(b);
        }
    
public static synchronized voiduseBuffer(java.nio.Buffer b)

        if (b == null) {
            return;
        }

        Object o = bufferStrongReferences.get(b);
        int refs = (o == null) ? 0 : ((Integer)o).intValue();
        bufferStrongReferences.put(b, new Integer(refs + 1));