LimitInputStream extends FilterInputStream { @Override public synchronized void reset() throws IOException { if (!in.markSupported()) { throw new IOException("Mark not supported"); } if (mark == -1) { throw new IOException("Mark not set"); } in.reset(); left = mark; } LimitInputStream(InputStream in, long limit); @Override int available(); @Override synchronized void mark(int readLimit); @Override int read(); @Override int read(byte[] b, int off, int len); @Override synchronized void reset(); @Override long skip(long n);  }
@Test(expected = IOException.class) public void testResetWithoutMark() throws IOException { try (LimitInputStream limitInputStream = new LimitInputStream(new RandomInputStream(), 128)) { limitInputStream.reset(); } }