FileDocCategorySizeDatePackage
ByteBufferFactory.javaAPI DocGlassfish v2 API3695Fri May 04 22:37:04 BST 2007com.sun.enterprise.web.connector.grizzly

ByteBufferFactory

public class ByteBufferFactory extends Object
Factory class used to create views of a ByteBuffer. The ByteBuffer can by direct or not.
author
Jean-Francois Arcand

Fields Summary
public static int
defaultCapacity
The default capacity of the default view of a ByteBuffer
public static int
capacity
The default capacity of the ByteBuffer from which views will be created.
private static ByteBuffer
byteBuffer
The ByteBuffer used to create views.
Constructors Summary
private ByteBufferFactory()
Private constructor.

            
    
           
     
    
Methods Summary
public static synchronized java.nio.ByteBufferallocateView(int size, boolean direct)
Return a direct ByteBuffer view

param
size the Size of the ByteBuffer

        if (byteBuffer == null || 
               (byteBuffer.capacity() - byteBuffer.limit() < size)){
            if ( direct )
                byteBuffer = ByteBuffer.allocateDirect(capacity); 
            else
                byteBuffer = ByteBuffer.allocate(capacity);              
        }

        byteBuffer.limit(byteBuffer.position() + size);
        ByteBuffer view = byteBuffer.slice();
        byteBuffer.position(byteBuffer.limit());  
        
        return view;
    
public static synchronized java.nio.ByteBufferallocateView(boolean direct)
Return a direct ByteBuffer view using the default size.

        return allocateView(defaultCapacity, direct);