CustomResponse.java 1.86 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.servlet.ServletOutputStream
 *  javax.servlet.ServletResponse
 *  org.apache.sling.api.SlingHttpServletResponse
 *  org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper
 */
package com.adobe.forms.common.submitutils;

import com.adobe.forms.common.submitutils.CustomServletOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletResponse;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;

public class CustomResponse
extends SlingHttpServletResponseWrapper {
    private PrintWriter writer;
    private CustomServletOutputStream outputStream;

    public CustomResponse(SlingHttpServletResponse response) throws IOException {
        super(response);
    }

    public ServletOutputStream getOutputStream() throws IOException {
        if (this.outputStream == null) {
            this.outputStream = new CustomServletOutputStream();
        }
        return this.outputStream;
    }

    public PrintWriter getWriter() throws IOException {
        if (this.writer == null) {
            this.writer = new PrintWriter(new OutputStreamWriter((OutputStream)this.getOutputStream(), this.getResponse().getCharacterEncoding()), true);
        }
        return this.writer;
    }

    public void flushBuffer() throws IOException {
        if (this.writer != null) {
            this.writer.flush();
        } else if (this.outputStream != null) {
            this.outputStream.flush();
        }
    }

    public byte[] getCopy() {
        if (this.outputStream != null) {
            return this.outputStream.getCopy();
        }
        return new byte[0];
    }
}