@Override public void write(int b) throws IOException { out.write(b); counter.add(1); }
@Override public int read(byte b[], int off, int len) throws IOException { int nbRead = in.read(b, off, len); if(nbRead>0) counter.add(nbRead); return nbRead; }
@Override public void write(byte b[]) throws IOException { out.write(b); counter.add(b.length); }
@Override public void write(byte b[], int off, int len) throws IOException { out.write(b, off, len); counter.add(len); }
@Override public int read(byte b[]) throws IOException { int nbRead = in.read(b); if(nbRead>0) counter.add(nbRead); return nbRead; }
@Override public long skip(long n) throws IOException { long nbSkipped = in.skip(n); // Count skipped bytes only if this has been enabled if(countSkippedBytes && nbSkipped>0) counter.add(nbSkipped); return nbSkipped; }
@Override public int read() throws IOException { int i = in.read(); if(i>0) counter.add(1); return i; }
/** * Advances file index and resets current file's byte counters. This method should be called by subclasses * whenever the job starts processing a new file. */ @Override protected void nextFile(AbstractFile file) { totalByteCounter.add(currentFileByteCounter, true); totalSkippedByteCounter.add(currentFileSkippedByteCounter, true); // Reset some fields that need it currentFileSkipped = false; super.nextFile(file); }
/** * Increases the byte counter by the number of bytes contained in the specified counter (as returned by its * {@link #getByteCount()} method) and resets its byte counter after (if specified). * * @param counter the Bytecounter to add to this one, and reset after (if specified). * @param resetAfter if true, the specified counter will be reset after its byte count has been added to this ByteCounter */ public synchronized void add(ByteCounter counter, boolean resetAfter) { // Hold a lock on the provided counter to make sure that it is not modified or accessed // while this operation is carried out synchronized(counter) { add(counter.getByteCount()); if(resetAfter) counter.reset(); } }