java 实现Http代理 (5)
来源:互联网 发布:mac用flash发热 编辑:程序博客网 时间:2024/05/21 19:25
这里是HttpResponse
/* * $RCSfile: HttpResponse.java,v $$ * $Revision: 1.1 $ * $Date: 2007-4-15 $ * * Copyright (C) 2008 Skin, Inc. All rights reserved. * * This software is the proprietary information of Skin, Inc. * Use is subject to license terms. */package com.skin.taurus.http;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.PrintWriter;import java.util.List;/** * <p>Title: HttpResponse</p> * <p>Description: </p> * @author xuesong.net * @version 1.0 */public class HttpResponse{ private String httpProtocol; private int status = 0; private String reasonPhrase; private String contentType; private HttpHeader httpHeader; private boolean commit = false; private int bufferSize = 8192; private InputStream inputStream; private OutputStream outputStream; private PrintWriter writer; public HttpResponse() { this.httpHeader = new HttpHeader(); } public void setCommit(boolean commit) { this.commit = commit; } public boolean getCommit() { return this.commit; } public void setBufferSize(int bufferSize) { this.bufferSize = bufferSize; } public int getBufferSize() { return this.bufferSize; } /** * @return HttpHeader */ public void setHttpHeader(HttpHeader httpHeader) { this.httpHeader = httpHeader; } /** * @return HttpHeader */ public HttpHeader getHttpHeader() { return this.httpHeader; } public void addHeader(String name, String value) { this.setHeader(name, value); } public void setHeader(String name, String value) { this.checkCommit(); this.httpHeader.setHeader(name, value); } public String getHeader(String name) { return this.httpHeader.getHeader(name); } public List<String> removeHeader(String name) { return this.httpHeader.removeHeader(name); } public int getContentLength() { int contentLength = -1; String value = this.getHeader("Content-Length"); if(value == null) { return contentLength; } try { contentLength = Integer.parseInt(value); } catch(NumberFormatException e) { } return contentLength; } public String getContentType() { return contentType; } public void setContentLength(long contentLength) { this.addHeader("Content-Length", Long.toString(contentLength)); } public void setContentType(String contentType) { this.contentType = contentType; this.addHeader("Content-Type", contentType); } public void setChunked(boolean chunked) { this.checkCommit(); if(chunked) { this.setHeader("Transfer-Encoding", "chunked"); } else { this.setHeader("Transfer-Encoding", null); } } public boolean getChunked() { String chunked = this.getHeader("Transfer-Encoding"); return (chunked != null && chunked.equals("chunked")); } public String getHttpProtocol() { return httpProtocol; } public void setHttpProtocol(String httpProtocol) { this.checkCommit(); this.httpProtocol = httpProtocol; } /** * @return the status */ public int getStatus() { return this.status; } /** * @param status the status to set */ public void setStatus(int status) { this.checkCommit(); this.status = status; } /** * @return the reasonPhrase */ public String getReasonPhrase() { return this.reasonPhrase; } /** * @param reasonPhrase the reasonPhrase to set */ public void setReasonPhrase(String reasonPhrase) { this.checkCommit(); this.reasonPhrase = reasonPhrase; } public InputStream getInputStream() { return inputStream; } public void setInputStream(InputStream inputStream) { this.inputStream = inputStream; } public OutputStream getOutputStream() { return outputStream; } public void setOutputStream(OutputStream outputStream) { this.outputStream = outputStream; } /** * @return PrintWriter */ public PrintWriter getWriter() { if(writer == null) { this.writer = new PrintWriter(this.outputStream); } return this.writer; } private void checkCommit() { if(this.commit) { throw new HttpStatusException("The Response alread Commit!"); } } public void close() throws IOException { } public void flush() throws IOException { if(this.writer != null) { this.writer.flush(); } this.outputStream.flush(); } public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(this.getHttpProtocol()).append(" ").append(this.getStatus()).append(" ").append(this.getReasonPhrase()).append("\r\n"); buffer.append(this.httpHeader.toString()); buffer.append("\r\n"); return buffer.toString(); }}
- java 实现Http代理 (5)
- java 实现Http代理 (1)
- java 实现Http代理 (2)
- java 实现Http代理 (3)
- java 实现Http代理 (4)
- java 实现Http代理 (6)
- java 实现Http代理 (7)
- java 实现Http代理 (8)
- java 实现Http代理 (9)
- HTTP透明代理的java实现
- VC++实现HTTP代理
- VC++实现HTTP代理
- Java Http 设置代理
- JAVA实现HTTP代理上网的测试程序
- Java实现Http的Post、Get、代理访问请求
- Atitit.http代理的实现 代码java php c# python
- HTTP中继(代理)、隧道相关介绍及简单Java实现
- Java实现Http的Post、Get、代理访问请求
- Rails的模型支持:Active Record
- 轻松实现一个操作ini文件的类
- java 实现Http代理 (4)
- 浅谈Object Pascal的指针
- SSI有什么用? http://bbs.chinahtml.com/15674
- java 实现Http代理 (5)
- asp.net面试集合
- 在 FROM 下打开水晶报表文件(代碼碎片)
- 日常用品英语翻译
- Linux下的ftp客户端使用笔记
- C#中键盘钩子的使用
- java 实现Http代理 (6)
- (转)用axis2+Tomcat5.5+Eclipse3.2部署和访问Web服务
- 足球笑话