FileDocCategorySizeDatePackage
ByteBufferFactory.javaAPI DocExample3963Tue May 29 16:57:14 BST 2007com.sun.xml.ws.transport.tcp.util

ByteBufferFactory

public final class ByteBufferFactory extends Object
Class was copied from GlassFish Grizzly sources to be available also for client side and don't require GlassFish to be installed 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);
        final 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);