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;
    }

}

@@ -515,32 +515,22 @@
         
-final int read =
+return
  super.r
@@ -554,46 +554,96 @@
     
-progress += read;%0A        return read;
+// don't increment here, this calls another read implementation which we already measure
 %0A   
@@ -904,12 +904,8 @@
 ress
- / 2
 ;%0A  

fix progress counting for GPX import