All Downloads are FREE. Search and download functionalities are using the official Maven repository.

apoc.export.util.CountingReader Maven / Gradle / Ivy

There is a newer version: 4.4.0.31
Show newest version
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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy