1 24 package org.objectweb.jalisto.se.storage.raf; 25 26 import java.io.ByteArrayInputStream ; 27 import java.util.ArrayList ; 28 29 public class DbByteArrayInputStream extends ByteArrayInputStream { 30 private DbByteArrayInputStream(byte[] data) { 31 super(data); 32 } 33 34 public byte[] getDataToRead() { 35 return super.buf; 36 } 37 38 public synchronized void reset() { 39 super.reset(); 40 instances.add(this); 41 } 42 43 44 45 private static ArrayList instances = new ArrayList (); 46 47 public static DbByteArrayInputStream getInstance(byte[] data) { 48 if (instances.isEmpty()) { 49 return new DbByteArrayInputStream(data); 50 } 51 try { 52 DbByteArrayInputStream in = (DbByteArrayInputStream) instances.remove(0); 53 in.buf = data; 54 in.count = data.length; 55 return in; 56 } catch (ArrayIndexOutOfBoundsException e) { 57 return new DbByteArrayInputStream(data); 58 } 59 } 60 } 61 | Popular Tags |