1 2 24 package com.sun.enterprise.web.connector.grizzly; 25 26 import java.nio.ByteBuffer ; 27 28 29 35 public class ByteBufferFactory{ 36 37 38 41 public static int defaultCapacity = 9000; 42 43 44 48 public static int capacity = 4000000; 49 50 51 54 private static ByteBuffer byteBuffer; 55 56 57 60 private ByteBufferFactory(){ 61 } 62 63 64 68 public synchronized static ByteBuffer allocateView(int size, boolean direct){ 69 if (byteBuffer == null || 70 (byteBuffer.capacity() - byteBuffer.limit() < size)){ 71 if ( direct ) 72 byteBuffer = ByteBuffer.allocateDirect(capacity); 73 else 74 byteBuffer = ByteBuffer.allocate(capacity); 75 } 76 77 byteBuffer.limit(byteBuffer.position() + size); 78 ByteBuffer view = byteBuffer.slice(); 79 byteBuffer.position(byteBuffer.limit()); 80 81 return view; 82 } 83 84 85 88 public synchronized static ByteBuffer allocateView(boolean direct){ 89 return allocateView(defaultCapacity, direct); 90 } 91 92 } 93 | Popular Tags |