BinCatResponseHandler只是一个简单封装的用于向浏览器输出Http处理请求结果的对象。
    BinCatResponseHandler实现代码:

    1. package com.anbai.sec.server.handler;
    2. import com.anbai.sec.server.servlet.BinCatResponse;
    3. import java.io.ByteArrayOutputStream;
    4. import java.io.IOException;
    5. import java.io.OutputStream;
    6. import java.util.Map;
    7. public class BinCatResponseHandler {
    8. public void processResult(BinCatResponse response, Map<String, String> responseHeader, String serverName,
    9. OutputStream out, ByteArrayOutputStream baos) throws IOException {
    10. // 处理Http响应内容
    11. out.write(("HTTP/1.1 " + response.getStatus() + " " + response.getMessage() + "\n").getBytes());
    12. // 输出Web服务器信息
    13. out.write(("Server: " + serverName + "\n").getBytes());
    14. // 输出返回的消息类型
    15. out.write(("Content-Type: " + response.getContentType() + "\n").getBytes());
    16. // 输出返回字节数
    17. out.write(("Content-Length: " + baos.size() + "\n").getBytes());
    18. // 输出用户自定义的Header
    19. for (String key : responseHeader.keySet()) {
    20. out.write((key + ": " + responseHeader.get(key) + "\n").getBytes());
    21. }
    22. // 写入换行
    23. out.write("\n".getBytes());
    24. // 将读取到的数据写入到客户端Socket
    25. out.write(baos.toByteArray());
    26. }
    27. }