BinCatResponse.java示例代码片段:
package com.anbai.sec.server.servlet;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.URLEncoder;
import java.util.*;
public class BinCatResponse implements HttpServletResponse {
private final Socket socket;
private final Map<String, String> header;
private final ByteArrayOutputStream out;
private int status = 404;
private String statusMessage = "Not Found";
private String charset = "UTF-8";
private int contentLength = 0;
private String contentType = "text/html; charset=UTF-8";
private String location;
public BinCatResponse(Socket socket, Map<String, String> header, ByteArrayOutputStream out) {
this.socket = socket;
this.header = header;
this.out = out;
}
// 此处省略HttpServletResponse接口中的大部分方法,仅保留几个示例方法...
public void setHeader(String name, String value) {
this.header.put(name, value);
}
public String getHeader(String name) {
return header.get(name);
}
public PrintWriter getWriter() throws IOException {
return new PrintWriter(out);
}
}