I'm trying to create my own ProgressFileInputStream
It has Listeners that get informed whenever a read is done with the number of bytes read.
I've extended FileInputStream and rewritten all the read methods and the skip method. After each read i inform the listeners of the number of bytes read.
Unfortunately when i add up all the bytes received by the listener it equals 362. When i do fileObject.length() i get 1121. Where have the other 759 bytes gone!!!
I know the filObject.length() is right as windows reports the size as 1,121 bytes.
This is my code in the ProgressFileInputStream class...
and my readNBytes just does this...Code: public int read() throws IOException { int value = super.read(); readNBytes(1); return value; } public int read(byte[] b) throws IOException { int value = super.read(b); readNBytes(value); return value; } public int read(byte[] b, int off, int len) throws IOException { int value = super.read(b, off, len); readNBytes(value); return value; } public long skip(long n) throws IOException { long value = super.skip(n); readNBytes(value); return value; }
oh and finally my FileInputProgressListener interface is...Code: private void readNBytes(long n) { for(int i=0; i<theFileInputProgressListeners.size(); i++) { ((FileInputProgressListener)theFileInputProgressListeners.get(i)).bytesLoaded(n); } }
Any idea what i'm doing wrong?Code:public abstract interface FileInputProgressListener { public void bytesLoaded(long number); }


Reply With Quote
