@Test public void testCancel() throws IOException { IndicatingOutputStream ios = new IndicatingOutputStream(file, 20, new ProgressIndicatorBase() { @Override public void setFraction(final double fraction) { cancel(); } }); ios.write("1234\n".getBytes()); try { ios.write("123456789\n".getBytes()); Assert.fail("Should have failed"); } catch (CanceledException e) { } Assert.assertEquals("1234\n", FileUtils.readFileToString(file)); }
private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } }
IndicatingOutputStream extends FileOutputStream { private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } } }
IndicatingOutputStream extends FileOutputStream { private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } } IndicatingOutputStream(File file, int size, ProgressIndicator indicator); }
IndicatingOutputStream extends FileOutputStream { private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } } IndicatingOutputStream(File file, int size, ProgressIndicator indicator); void addObserver(OutputStream observer); void write(int i); void write(byte[] bytes); void write(byte[] bytes, int off, int len); }
IndicatingOutputStream extends FileOutputStream { private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } } IndicatingOutputStream(File file, int size, ProgressIndicator indicator); void addObserver(OutputStream observer); void write(int i); void write(byte[] bytes); void write(byte[] bytes, int off, int len);  }