HttpResponseWrapper.java 2.32 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.util.callbacks.Option
 *  javax.servlet.ServletOutputStream
 *  javax.servlet.http.HttpServletResponse
 *  javax.servlet.http.HttpServletResponseWrapper
 */
package com.adobe.cq.dam.s7imaging.impl.ps.access_log;

import com.adobe.cq.dam.s7imaging.impl.ps.access_log.ByteCountingServletOutputStream;
import com.scene7.is.util.callbacks.Option;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

public final class HttpResponseWrapper
extends HttpServletResponseWrapper {
    private int status = 200;
    private int contentLength = -1;
    private Option<ByteCountingServletOutputStream> out = Option.none();
    private Option<PrintWriter> writer = Option.none();

    public HttpResponseWrapper(HttpServletResponse delegate) {
        super(delegate);
    }

    public int getStatus() {
        return this.status;
    }

    public long getContentWritten() throws IOException {
        return this.out().count();
    }

    public int getContentLength() {
        return this.contentLength;
    }

    public void setContentLength(int len) {
        super.setContentLength(len);
        this.contentLength = len;
    }

    public void setStatus(int sc, String sm) {
        this.status = sc;
        super.setStatus(sc, sm);
    }

    public void setStatus(int sc) {
        this.status = sc;
        super.setStatus(sc);
    }

    public ServletOutputStream getOutputStream() throws IOException {
        return this.out();
    }

    public PrintWriter getWriter() throws IOException {
        return this.writer();
    }

    private ByteCountingServletOutputStream out() throws IOException {
        if (this.out.isEmpty()) {
            this.out = Option.some((Object)((Object)new ByteCountingServletOutputStream(super.getOutputStream())));
        }
        return (ByteCountingServletOutputStream)((Object)this.out.get());
    }

    private PrintWriter writer() throws IOException {
        if (this.writer.isEmpty()) {
            this.writer = Option.some((Object)new PrintWriter((OutputStream)((Object)this.out())));
        }
        return (PrintWriter)this.writer.get();
    }
}