<commit_before>package org.qfox.jestful.server;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

/**
 * <p>
 * Description:
 * </p>
 * <p>
 * <p>
 * Company: 广州市俏狐信息科技有限公司
 * </p>
 *
 * @author Payne <EMAIL>
 * @date 2016年6月1日 下午10:03:56
 * @since 1.0.0
 */
public class JestfulHeadResponse extends HttpServletResponseWrapper {
    private final JestfulHeadResponseServletOutputStream out = new JestfulHeadResponseServletOutputStream();
    private PrintWriter writer;

    public JestfulHeadResponse(HttpServletResponse response) {
        super(response);
    }

    public void finish() {
        super.setContentLength(out.size);
    }

    @Override
    public ServletOutputStream getOutputStream() throws IOException {
        return out;
    }

    @Override
    public PrintWriter getWriter() throws UnsupportedEncodingException {
        if (writer == null) {
            String charset = getCharacterEncoding();
            OutputStreamWriter osw = new OutputStreamWriter(out, charset);
            writer = new PrintWriter(osw, true);
        }
        return writer;
    }

    private static class JestfulHeadResponseServletOutputStream extends ServletOutputStream {
        private int size = 0;<commit_msg>Make Framework Supports Servlet-API 3.0.1 or Later<commit_after>package org.qfox.jestful.server;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

/**
 * <p>
 * Description:
 * </p>
 * <p>
 * <p>
 * Company: 广州市俏狐信息科技有限公司
 * </p>
 *
 * @author Payne 6<PASSWORD> <EMAIL>
 * @date 2016年6月1日 下午10:03:56
 * @since 1.0.0
 */
public class JestfulHeadResponse extends HttpServletResponseWrapper {
    private JestfulHeadResponseServletOutputStream out;
    private PrintWriter writer;

    public JestfulHeadResponse(HttpServletResponse response) {
        super(response);
    }

    public void finish() {
        super.setContentLength(out != null ? out.size : 0);
    }

    @Override
    public ServletOutputStream getOutputStream() throws IOException {
        if (out == null) {
            out = new JestfulHeadResponseServletOutputStream();
        }
        return out;
    }

    @Override
    public PrintWriter getWriter() throws IOException {
        if (writer == null) {
            String charset = getCharacterEncoding();
            ServletOutputStream sos = getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(sos, charset);
            writer = new PrintWriter(osw, true);
        }
        return writer;
    }

    private static class JestfulHeadResponseServletOutputStream extends ServletOutputStream {
        private int size = 0;
{'fraction_non_alphanumeric': 0.08919098143236075, 'fraction_numerical': 0.01226790450928382, 'mean_word_length': 3.3535353535353534, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5328228', 'n_tokens_mistral': 873, 'n_tokens_neox': 845, 'n_words': 203}