@Test public void testSingleByteRead() throws IOException { final LimitedInputStream lis = new LimitedInputStream(bais, 4); assertEquals(0, lis.read()); assertEquals(1, lis.read()); assertEquals(2, lis.read()); assertEquals(3, lis.read()); assertEquals(-1, lis.read()); }
@Override public int read() throws IOException { if (bytesRead >= limit) { return -1; } final int val = in.read(); if (val > -1) { bytesRead++; } return val; }
LimitedInputStream extends InputStream { @Override public int read() throws IOException { if (bytesRead >= limit) { return -1; } final int val = in.read(); if (val > -1) { bytesRead++; } return val; } }
LimitedInputStream extends InputStream { @Override public int read() throws IOException { if (bytesRead >= limit) { return -1; } final int val = in.read(); if (val > -1) { bytesRead++; } return val; } LimitedInputStream(final InputStream in, final long limit); }
LimitedInputStream extends InputStream { @Override public int read() throws IOException { if (bytesRead >= limit) { return -1; } final int val = in.read(); if (val > -1) { bytesRead++; } return val; } LimitedInputStream(final InputStream in, final long limit); @Override int read(); @Override int read(final byte[] b); @Override int read(byte[] b, int off, int len); @Override long skip(final long n); @Override int available(); @Override void close(); @Override void mark(int readlimit); @Override boolean markSupported(); @Override void reset(); }
LimitedInputStream extends InputStream { @Override public int read() throws IOException { if (bytesRead >= limit) { return -1; } final int val = in.read(); if (val > -1) { bytesRead++; } return val; } LimitedInputStream(final InputStream in, final long limit); @Override int read(); @Override int read(final byte[] b); @Override int read(byte[] b, int off, int len); @Override long skip(final long n); @Override int available(); @Override void close(); @Override void mark(int readlimit); @Override boolean markSupported(); @Override void reset();  }