-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
209 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/de/siegmar/fastcsv/reader/CountingStatusListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package de.siegmar.fastcsv.reader; | ||
|
||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* Simple implementation of {@link StatusListener} to count read rows and bytes. | ||
*/ | ||
public class CountingStatusListener implements StatusListener { | ||
|
||
protected volatile long totalSize; | ||
protected final AtomicLong rowCnt = new AtomicLong(); | ||
protected final AtomicLong byteCnt = new AtomicLong(); | ||
|
||
@SuppressWarnings("checkstyle:HiddenField") | ||
@Override | ||
public void initialize(final long totalSize) { | ||
this.totalSize = totalSize; | ||
} | ||
|
||
@Override | ||
public void readRow() { | ||
rowCnt.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public void readBytes(final int bytes) { | ||
byteCnt.addAndGet(bytes); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final long byteCntVal = this.byteCnt.longValue(); | ||
final double percentage = byteCntVal * 100.0 / totalSize; | ||
return String.format("Read %,d rows and %,d of %,d bytes (%.2f %%)", | ||
rowCnt.longValue(), byteCntVal, totalSize, percentage); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.