UnsyncByteArrayInputStream extends InputStream { @Override public int read() { if (_index < _capacity) { return _buffer[_index++] & 0xff; } return -1; } UnsyncByteArrayInputStream(byte[] buffer);  UnsyncByteArrayInputStream(byte[] buffer, int offset, int length); @Override int available(); @Override void mark(int readAheadLimit); @Override boolean markSupported(); @Override int read(); @Override int read(byte[] bytes); @Override int read(byte[] bytes, int offset, int length); @Override void reset(); @Override long skip(long skip);  }
@Test public void testBlockRead() { UnsyncByteArrayInputStream unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(_BUFFER); int size = _SIZE * 2 / 3; byte[] buffer = new byte[size]; int read = unsyncByteArrayInputStream.read(buffer); Assert.assertEquals(size, read); for (int i = 0; i < read; i++) { Assert.assertEquals(i, buffer[i]); } read = unsyncByteArrayInputStream.read(buffer); Assert.assertEquals(_SIZE - size, read); for (int i = 0; i < read; i++) { Assert.assertEquals(i + size, buffer[i]); } unsyncByteArrayInputStream = new UnsyncByteArrayInputStream( new byte[0]); Assert.assertEquals(-1, unsyncByteArrayInputStream.read(buffer)); }
@Test public void testRead() { UnsyncByteArrayInputStream unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(_BUFFER); for (int i = 0; i < _SIZE; i++) { Assert.assertEquals(i, unsyncByteArrayInputStream.read()); } Assert.assertEquals(-1, unsyncByteArrayInputStream.read()); }