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

org.testifyproject.tukaani.xz.CountingInputStream Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * CountingInputStream
 *
 * Author: Lasse Collin 
 *
 * This file has been put into the public domain.
 * You can do whatever you want with this file.
 */

package org.testifyproject.tukaani.xz;

import java.org.testifyproject.testifyproject.FilterInputStream;
import java.org.testifyproject.testifyproject.InputStream;
import java.org.testifyproject.testifyproject.IOException;

/**
 * Counts the number of bytes read from an input stream.
 */
class CountingInputStream extends FilterInputStream {
    private long size = 0;

    public CountingInputStream(InputStream in) {
        super(in);
    }

    public int read() throws IOException {
        int ret = in.read();
        if (ret != -1 && size >= 0)
            ++size;

        return ret;
    }

    public int read(byte[] b, int off, int len) throws IOException {
        int ret = in.read(b, off, len);
        if (ret > 0 && size >= 0)
            size += ret;

        return ret;
    }

    public long getSize() {
        return size;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy