package org.xbib.logging.ext.io;

import java.io.IOException;
import java.io.OutputStream;

public final class CountingOutputStream extends OutputStream {

    private final OutputStream delegate;

    public long currentSize;

    public CountingOutputStream(final OutputStream delegate) {
        this.delegate = delegate;
        currentSize = 0;
    }

    public void write(final int b) throws IOException {
        delegate.write(b);
        currentSize++;
    }

    public void write(final byte[] b) throws IOException {
        delegate.write(b);
        currentSize += b.length;
    }

    public void write(final byte[] b, final int off, final int len) throws IOException {
        delegate.write(b, off, len);
        currentSize += len;
    }

    public void flush() throws IOException {
        delegate.flush();
    }

    public void close() throws IOException {
        delegate.close();
    }
}
