package com.atlassian.stash.internal.web.util.web;

import javax.servlet.ServletOutputStream;
import java.io.IOException;

/**
 * Counts the number of bytes written through this ServletOutputStream
 *
 * @since 4.0
 */
public class CountingServletOutputStream extends FilterServletOutputStream {

    private long count;

    public CountingServletOutputStream(ServletOutputStream out) {
        super(out);
    }

    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        out.write(b, off, len);
        count += len;
    }

    @Override
    public void write(int b) throws IOException {
        out.write(b);
        count++;
    }

    public long getBytesWritten() {
        return count;
    }
}