KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > mcast > ByteArrayPool


1 /*
2  * ByteArrayPool.java
3  *
4  * Created on November 3, 2005, 10:02 PM
5  */

6
7 package org.sapia.ubik.mcast;
8
9 import org.sapia.ubik.net.Pool;
10
11 /**
12  * This class implements a pool of byte arrays.
13  * @author yduchesne
14  */

15 public class ByteArrayPool extends Pool{
16   
17   private int _bufSize;
18   
19   /** Creates a new instance of ByteArrayPool */
20   public ByteArrayPool(int bufSize) {
21     _bufSize = bufSize;
22   }
23   
24   public void setBufSize(int bufSize){
25     _bufSize = bufSize;
26   }
27   
28   public int getBufSize(){
29     return _bufSize;
30   }
31   
32   protected Object JavaDoc onAcquire(Object JavaDoc o) throws Exception JavaDoc {
33     byte[] bytes = (byte[])o;
34     if(bytes.length != _bufSize){
35       return new byte[_bufSize];
36     }
37     else{
38       return o;
39     }
40   }
41   
42   protected Object JavaDoc doNewObject() throws Exception JavaDoc{
43     return new byte[_bufSize];
44   }
45   
46 }
47
Popular Tags