UnsyncBufferedInputStream extends UnsyncFilterInputStream { @Override public int read() throws IOException { if (inputStream == null) { throw new IOException("Input stream is null"); } if (_index >= _firstInvalidIndex) { _fillInBuffer(); if (_index >= _firstInvalidIndex) { return -1; } } return _buffer[_index++] & 0xff; } UnsyncBufferedInputStream(InputStream inputStream);  UnsyncBufferedInputStream(InputStream inputStream, int size); @Override int available(); @Override void close(); @Override void mark(int readLimit); @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 testRead() throws IOException { int size = 10; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( _BUFFER); UnsyncBufferedInputStream unsyncBufferedInputStream = new UnsyncBufferedInputStream(byteArrayInputStream, size); Assert.assertEquals(_SIZE, byteArrayInputStream.available()); Assert.assertEquals(_SIZE, unsyncBufferedInputStream.available()); Assert.assertEquals(0, unsyncBufferedInputStream.read()); Assert.assertEquals(_SIZE - size, byteArrayInputStream.available()); Assert.assertEquals(_SIZE - 1, unsyncBufferedInputStream.available()); for (int i = 1; i < (size + 1); i++) { Assert.assertEquals(i, unsyncBufferedInputStream.read()); } Assert.assertEquals( _SIZE - (size * 2), byteArrayInputStream.available()); Assert.assertEquals( _SIZE - size - 1, unsyncBufferedInputStream.available()); for (int i = size + 1; i < _SIZE; i++) { Assert.assertEquals( (byte)i, (byte)unsyncBufferedInputStream.read()); } Assert.assertEquals(-1, unsyncBufferedInputStream.read()); }