StrictlyBoundedInputStream extends InputStream { @Override public int read() throws IOException { int i = in.read(); if (i >= 0) { incrementCounter(1); } return i; } StrictlyBoundedInputStream(InputStream in, long maxSize); long getMaxSize(); long getTotal(); @Override int read();  }
@Test public void should_be_read_when_maximum_size_is_less_or_equal_to_zero() throws Exception { byte[] bytes = { 0, 1, 2 }; InputStream inputStream = new StrictlyBoundedInputStream(new ByteArrayInputStream(bytes), -1); byte[] result = new byte[3]; inputStream.read(result, 0, 3); assertArrayEquals(bytes, result); }