@Test public void testReporting() throws IOException { final LinkedList<Double> fractions = new LinkedList<Double>(); fractions.add(0.25); fractions.add(0.75); fractions.add(0.80); fractions.add(1.0); handler.async(4); IndicatingInputStream iis = new IndicatingInputStream(file, new ProgressIndicatorBase() { @Override public void setFraction(final double fraction) { handler.done(new Runnable() { @Override public void run() { Assert.assertEquals(fractions.removeFirst(), (Double)fraction); } }); } }); byte[] buf = new byte[10]; Assert.assertEquals(5, iis.read(buf, 0, 5)); Assert.assertEquals(10, iis.read(buf)); Assert.assertEquals('5', iis.read()); Assert.assertEquals(4, iis.read(buf)); }
public int read() throws IOException { cancel(); int i = super.read(); if(i != -1) { for(OutputStream observer: observers) { observer.write(i); } report(1); } return i; }
IndicatingInputStream extends FileInputStream { public int read() throws IOException { cancel(); int i = super.read(); if(i != -1) { for(OutputStream observer: observers) { observer.write(i); } report(1); } return i; } }
IndicatingInputStream extends FileInputStream { public int read() throws IOException { cancel(); int i = super.read(); if(i != -1) { for(OutputStream observer: observers) { observer.write(i); } report(1); } return i; } IndicatingInputStream(File file, ProgressIndicator indicator); }
IndicatingInputStream extends FileInputStream { public int read() throws IOException { cancel(); int i = super.read(); if(i != -1) { for(OutputStream observer: observers) { observer.write(i); } report(1); } return i; } 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 { public int read() throws IOException { cancel(); int i = super.read(); if(i != -1) { for(OutputStream observer: observers) { observer.write(i); } report(1); } return i; } IndicatingInputStream(File file, ProgressIndicator indicator); void addObserver(OutputStream observer); int read(); int read(byte[] bytes); int read(byte[] bytes, int ofs, int len);  }