ByteBufferInputStream extends InputStream { @Override public int read() throws IOException { if (bb.remaining() == 0) { return -1; } return bb.get() & 0xff; } ByteBufferInputStream(ByteBuffer bb); @Override int read(); @Override int available(); @Override int read(byte[] b, int off, int len); @Override int read(byte[] b); @Override long skip(long n); static void byteBuffer2Record(ByteBuffer bb, Record record);  }
@Test public void testReadArrayOffsetLength() throws Exception { assertEquals(1, in.read(bs, 2, 1)); byte[] expected = new byte[] { (byte) 1, (byte) 2, DATA_BYTES[0], (byte) 4 }; assertArrayEquals(expected, bs); }
@Test(expected=IndexOutOfBoundsException.class) public void testReadArrayOffsetLength_LengthTooLarge() throws Exception { in.read(bs, 2, 3); }
@Test public void testReadArrayOffsetLength_HitEndOfStream() throws Exception { for (int i = 0; i < DATA_BYTES.length - 1; i++) { in.read(); } assertEquals(1, in.read(bs, 2, 2)); byte[] expected = new byte[] { (byte) 1, (byte) 2, DATA_BYTES[DATA_BYTES.length - 1], (byte) 4 }; assertArrayEquals(expected, bs); }