BinCatResponse.java示例代码片段:

    1. package com.anbai.sec.server.servlet;
    2. import javax.servlet.ServletOutputStream;
    3. import javax.servlet.http.Cookie;
    4. import javax.servlet.http.HttpServletResponse;
    5. import java.io.ByteArrayOutputStream;
    6. import java.io.IOException;
    7. import java.io.PrintWriter;
    8. import java.net.Socket;
    9. import java.net.URLEncoder;
    10. import java.util.*;
    11. public class BinCatResponse implements HttpServletResponse {
    12. private final Socket socket;
    13. private final Map<String, String> header;
    14. private final ByteArrayOutputStream out;
    15. private int status = 404;
    16. private String statusMessage = "Not Found";
    17. private String charset = "UTF-8";
    18. private int contentLength = 0;
    19. private String contentType = "text/html; charset=UTF-8";
    20. private String location;
    21. public BinCatResponse(Socket socket, Map<String, String> header, ByteArrayOutputStream out) {
    22. this.socket = socket;
    23. this.header = header;
    24. this.out = out;
    25. }
    26. // 此处省略HttpServletResponse接口中的大部分方法,仅保留几个示例方法...
    27. public void setHeader(String name, String value) {
    28. this.header.put(name, value);
    29. }
    30. public String getHeader(String name) {
    31. return header.get(name);
    32. }
    33. public PrintWriter getWriter() throws IOException {
    34. return new PrintWriter(out);
    35. }
    36. }