@Test public void testCancel() throws IOException { IndicatingInputStream iis = new IndicatingInputStream(file, new ProgressIndicatorBase() { @Override public void setFraction(final double fraction) { cancel(); } }); byte[] buf = new byte[5]; Assert.assertEquals(5, iis.read(buf)); try { iis.read(buf); Assert.fail("Should have failed"); } catch (CanceledException e) { } Assert.assertEquals("1234\n", new String(buf)); }
private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } }
IndicatingInputStream extends FileInputStream { private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } } }
IndicatingInputStream extends FileInputStream { private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } } IndicatingInputStream(File file, ProgressIndicator indicator); }
IndicatingInputStream extends FileInputStream { private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } } IndicatingInputStream(File file, ProgressIndicator indicator); void addObserver(OutputStream observer); int read(); int read(byte[] bytes); int read(byte[] bytes, int ofs, int len); }
IndicatingInputStream extends FileInputStream { private void cancel() throws IOException { if(indicator != null && indicator.isCanceled()) { throw new CanceledException(); } } IndicatingInputStream(File file, ProgressIndicator indicator); void addObserver(OutputStream observer); int read(); int read(byte[] bytes); int read(byte[] bytes, int ofs, int len);  }