RandomAccessFileInputStream extends InputStream { @Override public void mark(int readlimit) { try { mark = raf.getFilePointer(); } catch (IOException e) { throw new RuntimeException(e); } } RandomAccessFileInputStream(File file);  RandomAccessFileInputStream(File file, long rangeOffset, long rangeLength); void setRange(long rangeOffset, long rangeLength); @Override int available(); long getPosition(); @Override void close(); @Override int read(); @Override int read(byte[] b, int off, int len); @Override int read(byte[] b); @Override long skip(long n); @Override boolean markSupported(); @Override void mark(int readlimit); @Override void reset(); long length();  }
@Test public void testMark_IOExceptionInRaf() throws IOException { stream = new RandomAccessFileInputStream(tempFile, 0, testData.length) { @Override protected RandomAccessFile getRandomAccessFile(File file) throws IOException { return new RandomAccessFile(file, "r") { @Override public long getFilePointer() throws IOException { throw new IOException("Blah314159"); } }; } }; try { stream.mark(0); Assert.fail("Executed code that should have failed."); } catch (Exception e) { Assert.assertEquals("Blah314159", e.getCause().getMessage()); } }