KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > nio > util > ByteBufferPool


1 package org.sapia.ubik.net.nio.util;
2
3 import java.nio.ByteBuffer JavaDoc;
4
5 import org.sapia.ubik.net.Pool;
6
7 /**
8  * @author Yanick Duchesne
9  *
10  * <dl>
11  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
12  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
13  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
14  * </dl>
15  */

16 public class ByteBufferPool extends Pool{
17   
18   /**
19    * Holds the default buffer size (1024).
20    *
21    * @see #setBufSize(int)
22    */

23   public static final int DEFAULT_BUF_SIZE = 1024;
24   
25   private int _bufsz = DEFAULT_BUF_SIZE;
26   
27   /**
28    * @param numBytes sets the number of bytes that this instance
29    * will allocate to the <code>ByteBuffer</code>s it creates.
30    *
31    * @see #DEFAULT_BUF_SIZE
32    */

33   public void setBufSize(int numBytes){
34     _bufsz = numBytes;
35   }
36   
37   /**
38    * @return the size of the buffers that this instance creates.
39    */

40   public int getBufSize(){
41     return _bufsz;
42   }
43   
44   /**
45    * @see org.sapia.ubik.net.Pool#onRelease(java.lang.Object)
46    */

47   protected void onRelease(Object JavaDoc o) {
48     ((ByteBuffer JavaDoc)o).clear();
49   }
50   
51   /**
52    * @see org.sapia.ubik.net.Pool#doNewObject()
53    */

54   protected Object JavaDoc doNewObject() throws Exception JavaDoc {
55     return ByteBuffer.allocateDirect(_bufsz);
56   }
57
58 }
59
Popular Tags