private int readInput(byte[] b, int start, int len) throws IOException { int read = in.read(offset, b, start, len); if (read < 0) throw new EOFException(); offset += read; return read; }
@Override public void close() throws IOException { file.close(); }
public InputBuffer(Input in, long position) throws IOException { this.in = in; this.inLength = in.length(); this.offset = position; if (in instanceof InputBytes) { // use buffer directly this.buf = ((InputBytes)in).getBuffer(); this.limit = (int)in.length(); this.offset = limit; this.pos = (int)position; } else { // create new buffer this.buf = new byte[8192]; // big enough for primitives } }
@Test public void testRandomReads() throws Exception { Random random = new Random(19820210); int length = random.nextInt(SIZE) + 1; byte[] data = new byte[length]; random.nextBytes(data); Input in = new InputBytes(data); for (int i = 0; i < COUNT; i++) { int p = random.nextInt(length); int l = Math.min(random.nextInt(SIZE/10), length-p); byte[] buffer = new byte[l]; in.read(p, buffer, 0, l); Assert.assertArrayEquals(Arrays.copyOfRange(data, p, p+l), buffer); } } }
public InputBuffer(Input in, long position) throws IOException { this.in = in; this.inLength = in.length(); this.offset = position; if (in instanceof InputBytes) { // use buffer directly this.buf = ((InputBytes)in).getBuffer(); this.limit = (int)in.length(); this.offset = limit; } else { // create new buffer this.buf = new byte[8192]; // big enough for primitives } }
@Override public void close() throws IOException { file.close(); }
private int readInput(byte[] b, int start, int len) throws IOException { int read = in.read(offset, b, start, len); if (read < 0) throw new EOFException(); offset += read; return read; }
@Test public void testRandomReads() throws Exception { Random random = new Random(); int length = random.nextInt(SIZE); byte[] data = new byte[length]; random.nextBytes(data); Input in = new InputBytes(data); for (int i = 0; i < COUNT; i++) { int p = random.nextInt(length); int l = Math.min(random.nextInt(SIZE/10), length-p); byte[] buffer = new byte[l]; in.read(p, buffer, 0, l); Assert.assertArrayEquals(Arrays.copyOfRange(data, p, p+l), buffer); } } }