RandomAccessFileOutputStream extends OutputStream { @Override public void write(int b) throws IOException { raf.write(b); } RandomAccessFileOutputStream(File outputFile, long expectedSize); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); @Override void flush(); @Override void close();  }
@Test public void testWrite() throws IOException { stream = new RandomAccessFileOutputStream(tempFile, 1L); stream.write(7); stream.flush(); stream.close(); FileInputStream in = null; try { in = new FileInputStream(tempFile); Assert.assertEquals(7, in.read()); } finally { try { in.close(); } catch (Exception ignored) { } } }