aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/files/ProgressInputStream.java
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-10-12 16:04:37 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-10-12 16:04:37 +0200
commit0c6dc58076a81cb8bba31c3ecc414e264c03c7e2 (patch)
tree060e0d03cdb69f55c1523372c11d8beffa8b2289 /main/src/cgeo/geocaching/files/ProgressInputStream.java
parent863ca04913920a4473c127b6017aa84f04dd5b59 (diff)
downloadcgeo-0c6dc58076a81cb8bba31c3ecc414e264c03c7e2.zip
cgeo-0c6dc58076a81cb8bba31c3ecc414e264c03c7e2.tar.gz
cgeo-0c6dc58076a81cb8bba31c3ecc414e264c03c7e2.tar.bz2
fix wrong counting in progress stream
Diffstat (limited to 'main/src/cgeo/geocaching/files/ProgressInputStream.java')
-rw-r--r--main/src/cgeo/geocaching/files/ProgressInputStream.java18
1 files changed, 11 insertions, 7 deletions
diff --git a/main/src/cgeo/geocaching/files/ProgressInputStream.java b/main/src/cgeo/geocaching/files/ProgressInputStream.java
index 593949b..552aee0 100644
--- a/main/src/cgeo/geocaching/files/ProgressInputStream.java
+++ b/main/src/cgeo/geocaching/files/ProgressInputStream.java
@@ -4,6 +4,14 @@ import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+/**
+ * Stream to measure progress of reading automatically.
+ * <p>
+ * The method @link ProgressInputStream#read(byte[]) does not need to be overridden as it delegates to @link
+ * ProgressInputStream#read(byte[], int, int) anyway.
+ * </p>
+ *
+ */
public class ProgressInputStream extends FilterInputStream {
private int progress = 0;
@@ -15,17 +23,13 @@ public class ProgressInputStream extends FilterInputStream {
@Override
public int read() throws IOException {
final int read = super.read();
- progress += read;
+ if (read >= 0) {
+ progress++;
+ }
return read;
}
@Override
- public int read(byte[] buffer) throws IOException {
- return super.read(buffer);
- // don't increment here, this calls another read implementation which we already measure
- }
-
- @Override
public int read(byte[] buffer, int offset, int count) throws IOException {
final int read = super.read(buffer, offset, count);
progress += read;