apoc.export.util.CountingReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apoc Show documentation
Show all versions of apoc Show documentation
A collection of useful Neo4j Procedures
package apoc.export.util;
import java.io.*;
/**
* @author mh
* @since 22.05.16
*/
public class CountingReader extends FilterReader implements SizeCounter {
public static final int BUFFER_SIZE = 1024 * 1024;
private final long total;
private long count=0;
private long newLines;
public CountingReader(File file) throws FileNotFoundException {
super(new BufferedReader(new FileReader(file), BUFFER_SIZE));
this.total = file.length();
}
public CountingReader(Reader reader, long total) throws FileNotFoundException {
super(new BufferedReader(reader, BUFFER_SIZE));
this.total = total;
}
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
int read = super.read(cbuf, off, len);
count+=read;
for (int i=off;i