/** decide which seekable implementatino to use. * @param in a DataInputStream to read * @param length how many bytes to expect from in * @return an InputStream which also implements Seekable * @throws IOException if an IO problem occurs */ private static InputStream getSeekable(DataInputStream in, long length) throws IOException { if (length < MAX_INDIVIDUAL_BUFFER_SIZE) { byte[] buf = new byte[(int)length]; in.readFully(buf); in.close(); return new SeeakableByteArrayInputStream(buf); } return new MultiSeeakableByteArrayInputStream(in, length); }
/** decide which seekable implementatino to use. * @param in a DataInputStream to read * @param length how many bytes to expect from in * @return an InputStream which also implements Seekable * @throws IOException if an IO problem occurs */ private static InputStream getSeekable(DataInputStream in, long length) throws IOException { if (length < MAX_INDIVIDUAL_BUFFER_SIZE) { byte[] buf = new byte[(int)length]; in.readFully(buf); in.close(); return new SeeakableByteArrayInputStream(buf); } return new MultiSeeakableByteArrayInputStream(in, length); }
@Override public Object clone() throws CloneNotSupportedException { InputStream in = null; if (buf instanceof MultiSeeakableByteArrayInputStream) { in = new MultiSeeakableByteArrayInputStream( ((MultiSeeakableByteArrayInputStream)buf).data, ((MultiSeeakableByteArrayInputStream)buf).pos, ((MultiSeeakableByteArrayInputStream)buf).length); } else if (buf instanceof SeeakableByteArrayInputStream) { in = new SeeakableByteArrayInputStream(((SeeakableByteArrayInputStream)buf).getBuffer()); } try{ return new RandomDataInputMemory(in); } catch (IOException ioe) { throw new CloneNotSupportedException(ioe.getMessage()); } }
@Override public Object clone() throws CloneNotSupportedException { InputStream in = null; if (buf instanceof MultiSeeakableByteArrayInputStream) { in = new MultiSeeakableByteArrayInputStream( ((MultiSeeakableByteArrayInputStream)buf).data, ((MultiSeeakableByteArrayInputStream)buf).pos, ((MultiSeeakableByteArrayInputStream)buf).length); } else if (buf instanceof SeeakableByteArrayInputStream) { in = new SeeakableByteArrayInputStream(((SeeakableByteArrayInputStream)buf).getBuffer()); } try{ return new RandomDataInputMemory(in); } catch (IOException ioe) { throw new CloneNotSupportedException(ioe.getMessage()); } }
/** Construct a new RandomDataInputMemory object, backed by the specified buffer */ public RandomDataInputMemory(byte[] b) { super(new SeeakableByteArrayInputStream(b)); buf = (Seekable)super.in; }
/** Construct a new RandomDataInputMemory object, backed by the specified buffer */ public RandomDataInputMemory(byte[] b) { super(new SeeakableByteArrayInputStream(b)); buf = (Seekable)super.in; }