### Question:
BoundedInputStream extends InputStream { @Override public int read() throws IOException { if (max >= 0 && pos >= max) { return EOF; } final int result = in.read(); pos++; return result; } BoundedInputStream(final InputStream in, final long size);  BoundedInputStream(final InputStream in); @Override int read(); @Override int read(final byte[] b); @Override int read(final byte[] b, final int off, final int len); @Override long skip(final long n); @Override int available(); @Override String toString(); @Override void close(); @Override synchronized void reset(); @Override synchronized void mark(final int readlimit); @Override boolean markSupported(); boolean isPropagateClose(); void setPropagateClose(final boolean propagateClose);  }### Answer:
@Test public void testReadSingle() throws Exception { BoundedInputStream bounded; final byte[] helloWorld = "Hello World".getBytes(); final byte[] hello = "Hello".getBytes(); bounded = new BoundedInputStream(new ByteArrayInputStream(helloWorld), helloWorld.length); for (int i = 0; i < helloWorld.length; i++) { assertEquals("limit = length byte[" + i + "]", helloWorld[i], bounded.read()); } assertEquals("limit = length end", -1, bounded.read()); bounded = new BoundedInputStream(new ByteArrayInputStream(helloWorld), helloWorld.length + 1); for (int i = 0; i < helloWorld.length; i++) { assertEquals("limit > length byte[" + i + "]", helloWorld[i], bounded.read()); } assertEquals("limit > length end", -1, bounded.read()); bounded = new BoundedInputStream(new ByteArrayInputStream(helloWorld), hello.length); for (int i = 0; i < hello.length; i++) { assertEquals("limit < length byte[" + i + "]", hello[i], bounded.read()); } assertEquals("limit < length end", -1, bounded.read()); }