### Question:
ByteBufferInputStream extends InputStream { @Override public int read() { return myBuffer.hasRemaining() ? myBuffer.get() & 0xFF : -1; } ByteBufferInputStream(ByteBuffer buffer); @Override int available(); @Override synchronized void mark(int readlimit); @Override boolean markSupported(); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] array, int offset, int length); @Override synchronized void reset(); @Override long skip(long n);  }### Answer:
@Test public void testRead() { ByteBuffer buf = createBuffer(); ByteBufferInputStream bbis = new ByteBufferInputStream(buf); for (int index = OFFSET; index < LIMIT; ++index) { Assert.assertEquals(buf.get(index) & 0xFF, bbis.read()); } }
@Test public void testReadByteArray() { ByteBuffer buf = createBuffer(); ByteBufferInputStream bbis = new ByteBufferInputStream(buf); byte[] arr = new byte[5]; Assert.assertEquals(arr.length, bbis.read(arr)); for (int index = 0; index < arr.length; ++index) { Assert.assertEquals(buf.get(index + OFFSET), arr[index]); } }
@Test public void testReadByteArrayIntInt() { ByteBuffer buf = createBuffer(); ByteBufferInputStream bbis = new ByteBufferInputStream(buf); byte[] arr = new byte[7]; Assert.assertEquals(5, bbis.read(arr, 2, 5)); for (int index = 0; index < arr.length - 2; ++index) { Assert.assertEquals(buf.get(index + OFFSET), arr[index + 2]); } }