@Test public void testRead() throws Exception { final int size = 5; final InputStream input = new TestNullInputStream(size); for (int i = 0; i < size; i++) { assertEquals("Check Size [" + i + "]", size - i, input.available()); assertEquals("Check Value [" + i + "]", i, input.read()); } assertEquals("Available after contents all read", 0, input.available()); assertEquals("End of File", -1, input.read()); assertEquals("Available after End of File", 0, input.available()); try { final int result = input.read(); fail("Should have thrown an IOException, byte=[" + result + "]"); } catch (final IOException e) { assertEquals("Read after end of file", e.getMessage()); } input.close(); assertEquals("Available after close", size, input.available()); }
@Override public int read() throws IOException { if (eof) { throw new IOException("Read after end of file"); } if (position == size) { return doEndOfFile(); } position++; return processByte(); }
NullInputStream extends InputStream { @Override public int read() throws IOException { if (eof) { throw new IOException("Read after end of file"); } if (position == size) { return doEndOfFile(); } position++; return processByte(); } }
NullInputStream extends InputStream { @Override public int read() throws IOException { if (eof) { throw new IOException("Read after end of file"); } if (position == size) { return doEndOfFile(); } position++; return processByte(); } NullInputStream(final long size);  NullInputStream(final long size, final boolean markSupported, final boolean throwEofException); }
NullInputStream extends InputStream { @Override public int read() throws IOException { if (eof) { throw new IOException("Read after end of file"); } if (position == size) { return doEndOfFile(); } position++; return processByte(); } NullInputStream(final long size);  NullInputStream(final long size, final boolean markSupported, final boolean throwEofException); long getPosition(); long getSize(); @Override int available(); @Override void close(); @Override synchronized void mark(final int readlimit); @Override boolean markSupported(); @Override int read(); @Override int read(final byte[] bytes); @Override int read(final byte[] bytes, final int offset, final int length); @Override synchronized void reset(); @Override long skip(final long numberOfBytes); }
NullInputStream extends InputStream { @Override public int read() throws IOException { if (eof) { throw new IOException("Read after end of file"); } if (position == size) { return doEndOfFile(); } position++; return processByte(); } NullInputStream(final long size);  NullInputStream(final long size, final boolean markSupported, final boolean throwEofException); long getPosition(); long getSize(); @Override int available(); @Override void close(); @Override synchronized void mark(final int readlimit); @Override boolean markSupported(); @Override int read(); @Override int read(final byte[] bytes); @Override int read(final byte[] bytes, final int offset, final int length); @Override synchronized void reset(); @Override long skip(final long numberOfBytes);  }