aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/files/ProgressInputStream.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/files/ProgressInputStream.java')
-rw-r--r--main/src/cgeo/geocaching/files/ProgressInputStream.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/files/ProgressInputStream.java b/main/src/cgeo/geocaching/files/ProgressInputStream.java
new file mode 100644
index 0000000..a42a6fd
--- /dev/null
+++ b/main/src/cgeo/geocaching/files/ProgressInputStream.java
@@ -0,0 +1,40 @@
+package cgeo.geocaching.files;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class ProgressInputStream extends FilterInputStream {
+
+ private int progress = 0;
+
+ protected ProgressInputStream(InputStream in) {
+ super(in);
+ }
+
+ @Override
+ public int read() throws IOException {
+ final int read = super.read();
+ progress += read;
+ return read;
+ }
+
+ @Override
+ public int read(byte[] buffer) throws IOException {
+ final int read = super.read(buffer);
+ progress += read;
+ return read;
+ }
+
+ @Override
+ public int read(byte[] buffer, int offset, int count) throws IOException {
+ final int read = super.read(buffer, offset, count);
+ progress += read;
+ return read;
+ }
+
+ int getProgress() {
+ return progress / 2;
+ }
+
+}