ByteCountingServletOutputStream.java 1.48 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.servlet.ServletOutputStream
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.dam.s7imaging.impl.ps.access_log;

import java.io.IOException;
import javax.servlet.ServletOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class ByteCountingServletOutputStream
extends ServletOutputStream {
    private static final Logger LOGGER = LoggerFactory.getLogger(ByteCountingServletOutputStream.class);
    private final ServletOutputStream delegate;
    private long count = 0;

    ByteCountingServletOutputStream(ServletOutputStream delegate) {
        this.delegate = delegate;
    }

    public long count() {
        return this.count;
    }

    public void write(int b) throws IOException {
        this.delegate.write(b);
        ++this.count;
    }

    public void write(byte[] bytes) throws IOException {
        this.delegate.write(bytes);
        this.count += (long)bytes.length;
    }

    public void write(byte[] bytes, int ofs, int len) throws IOException {
        this.delegate.write(bytes, ofs, len);
        this.count += (long)len;
    }

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

    public void close() {
        try {
            this.delegate.close();
        }
        catch (IOException e) {
            LOGGER.warn("Failed to close output stream: " + (Object)((Object)this), (Throwable)e);
        }
    }
}