/******************************************************************
*
* CyberHTTP for Java
*
* Copyright (C) Satoshi Konno 2002-2004
*
* File: HTTPConnection.java
*
* Revision;
*
* 11/18/02
* - first revision.
* 09/02/03
* - Giordano Sassaroli <sassarol@cefriel.it>
* - Problem : The API is unable to receive responses from the Microsoft UPnP stack
* - Error : the Microsoft UPnP stack is based on ISAPI on IIS, and whenever IIS
* receives a post request, it answers with two responses: the first one has no
* body and it is a code 100 (continue) response, which has to be ignored. The
* second response is the actual one and should be parsed as the response.
* 02/09/04
* - Ralf G. R. Bergs" <Ralf@Ber.gs>
* - Why do you strip leading and trailing white space from the response body?
* - Disabled to trim the content string.
* 03/11/04
* - Added some methods about InputStream content.
* setContentInputStream(), getContentInputStream() and hasContentInputStream().
* 03/16/04
* - Thanks for Darrell Young
* - Added setVersion() and getVersion();
* 03/17/04
* - Added hasFirstLine();
* 05/26/04
* - Jan Newmarch <jan.newmarch@infotech.monash.edu.au> (05/26/04)
* - Changed setCacheControl() and getChcheControl();
* 08/25/04
* - Added the following methods.
* hasContentRange(), setContentRange(), getContentRange(),
* getContentRangeFirstPosition(), getContentRangeLastPosition() and getContentRangeInstanceLength()
* 08/26/04
* - Added the following methods.
* hasConnection(), setConnection(), getConnection(),
* isCloseConnection() and isKeepAliveConnection()
* 08/27/04
* - Added a updateWithContentLength paramger to setContent().
* - Changed to HTTPPacket::set() not to change the header of Content-Length.
* 08/28/04
* - Added init() and read().
* 09/19/04
* - Added a onlyHeaders parameter to set().
* 10/20/04
* - Brent Hills <bhills@openshores.com>
* - Changed hasContentRange() to check Content-Range and Range header.
* - Added support for Range header to getContentRange().
* 02/02/05
* - Mark Retallack <mretallack@users.sourceforge.net>
* - Fixed set() not to read over the content length when the stream is keep alive.
* 02/28/05
* - Added the following methods for chunked stream support.
* hasTransferEncoding(), setTransferEncoding(), getTransferEncoding(), isChunked().
* 03/02/05
* - Changed post() to suppot chunked stream.
* 06/11/05
* - Added setHost().
* 07/07/05
* - Lee Peik Feng <pflee@users.sourceforge.net>
* - Andrey Ovchar <AOvchar@consultitnow.com>
* - Fixed set() to parse the chunk size as a hex string.
* 11/02/05
* - Changed set() to use BufferedInputStream instead of BufferedReader to
* get the content as a byte stream.
* 11/06/05
* - Added getCharSet().
* - Changed getContentString() to return the content string using the charset.
*
*******************************************************************/
package org.cybergarage.http;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.util.Calendar;
import java.util.StringTokenizer;
import java.util.Vector;
import org.cybergarage.net.HostInterface;
import org.cybergarage.util.Debug;
import org.cybergarage.util.StringUtil;
/** HTTPPacket 三大属性 1:请求行, 2:消息头, 3内容 */
public class HTTPPacket
{
private final String tag = "HTTPPacket";
////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////
/** 创建一个HTTPPacket 对象 设置version的值为1.1 */
public HTTPPacket()
{
setVersion(HTTP.VERSION);
setContentInputStream(null);
}
public HTTPPacket(HTTPPacket httpPacket)
{
setVersion(HTTP.VERSION);
set(httpPacket);
setContentInputStream(null);
}
public HTTPPacket(InputStream in)
{
setVersion(HTTP.VERSION);
set(in);
setContentInputStream(null);
}
////////////////////////////////////////////////
// init
////////////////////////////////////////////////
/** 读取时的初始化 */
public void init()
{
//设置第一行的值为空字符串
setFirstLine("");
//清空httpHeaderList集合
clearHeaders();
//清空内容的节子数组
setContent(new byte[0], false);
setContentInputStream(null);
}
////////////////////////////////////////////////
// Version
////////////////////////////////////////////////
/** version http协议版本 */
private String version;
/** 设置version */
public void setVersion(String ver)
{
version = ver;
}
/** 获取version */
public String getVersion()
{
return version;
}
////////////////////////////////////////////////
// set
////////////////////////////////////////////////
/** 读取一行,返回该行的字符转 */
private String readLine(BufferedInputStream in)
{
//创建一个ByteArrayOutputStream
ByteArrayOutputStream lineBuf = new ByteArrayOutputStream();
//创建一个byte 数组
byte readBuf[] = new byte[1];
try {
int readLen = in.read(readBuf);
while (0 < readLen) {
//如果是换行符就结束循环
if (readBuf[0] == HTTP.LF){
break;
}
//如果不等于回车就写出
if (readBuf[0] != HTTP.CR){
lineBuf.write(readBuf[0]);
}
readLen = in.read(readBuf);
}
}
catch (InterruptedIOException e) {
//Ignoring warning because it's a way to break the HTTP connecttion
//TODO Create a new level of Logging and log the event
}
catch (IOException e) {
System.out.println("readLine Exception");
Debug.warning(e);
}
return lineBuf.toString();
}
/** 读取数据的方法 */
protected boolean set(InputStream in, boolean onlyHeaders)
{
try {
//创建一个BufferedInputStream
BufferedInputStream reader = new BufferedInputStream(in);
Debug.message("setsetsetsetset = ");
//if(in.available() == 0)return false;
//读取第一行
String firstLine = readLine(reader);
if (firstLine == null || firstLine.length() <= 0){
return false;
}
//设置第一行的值
setFirstLine(firstLine);
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/03/03)
//创建一个HTTPStatus
HTTPStatus httpStatus = new HTTPStatus(firstLine);
//获取状态码
int statCode = httpStatus.getStatusCode();
//状态码为100的操作 ,请求者应当继续提出请求。 服务器返回此代码表示已收到请求的第一部分,正在等待其余部分。
if (statCode == HTTPStatus.CONTINUE){
//ad hoc code for managing iis non-standard behaviour
//iis sends 100 code response and a 200 code response in the same
//stream, so the code should check the presence of the actual
//response in the stream.
//skip all header lines
//专案管理的:IIS不规范行为的非法入境者的代码发送100码的响应和200代码在同一个流的反应,这样的代码应该检查是否存在实际的响应流中的。
//跳过所有标题行
//读取没个消息头
String headerLine = readLine(reader);
while ((headerLine != null) && (0 < headerLine.length()) ) {
//创建消息头对象
HTTPHeader header = new HTTPHeader(headerLine);
if (header.hasName() == true){
//设置httpHeaderList中的header的值
setHeader(header);
}
headerLine = readLine(reader);
}
//look forward another first line
//期待着另一个第一行
String actualFirstLine = readLine(reader);
if ((actualFirstLine != null) && (0 < actualFirstLine.length()) ) {
//this is the actual first line
//这是实际的第一行
setFirstLine(actualFirstLine);
}else{
return true;
}
}
//读取头
String headerLine = readLine(reader);
while ((headerLine != null) && (0 < headerLine.length()) ) {
//创建一个HTTPHeader
HTTPHeader header = new HTTPHeader(headerLine);
if (header.hasName() == true){
setHeader(header);
}
headerLine = readLine(reader);
}
if (onlyHeaders == true) {
setContent("", false);
return true;
}
boolean isChunkedRequest = isChunked();
long contentLen = 0;
if (isChunkedRequest == true) {
没有合适的资源?快使用搜索试试~ 我知道了~
Android smb访问共享文件以及播放共享文件
共97个文件
class:38个
java:31个
png:9个
3星 · 超过75%的资源 需积分: 48 101 下载量 71 浏览量
2018-08-27
16:11:09
上传
评论 2
收藏 2.81MB RAR 举报
温馨提示
安卓访问服务器共享文件用于播放视频之类的等。或者访问共享所有类
资源推荐
资源详情
资源评论
收起资源包目录
smbPf.rar (97个子文件)
pf
playfile.rar 1.13MB
playfile
.project 844B
project.properties 361B
proguard.cfg 1KB
src
demo
playfile
service
PlayFileService.java 796B
PlayfileActivity.java 7KB
util
FileItem.java 886B
FileServer.java 4KB
HTTPRequestListener.java 199B
FileUtil.java 2KB
org
cybergarage
http
Parameter.java 1KB
HTTPServer.java 7KB
HTTPServerList.java 4KB
HTTPPacket.java 27KB
HTTPRequest.java 15KB
HTTPResponse.java 3KB
ParameterList.java 1KB
HTTPServerThread.java 2KB
HTTP.java 7KB
HTTPStatus.java 5KB
HTML.java 425B
HTTPRequestListener.java 463B
HTTPSocket.java 9KB
Date.java 4KB
HTTPHeader.java 4KB
util
Mutex.java 1KB
StringUtil.java 3KB
Debug.java 2KB
FileUtil.java 2KB
ListenerList.java 654B
TimerUtil.java 807B
ThreadCore.java 2KB
net
HostInterface.java 9KB
AndroidManifest.xml 878B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 3KB
layout
main.xml 957B
drawable-xhdpi
values
strings.xml 164B
.settings
org.eclipse.jdt.core.prefs 177B
org.eclipse.core.resources.prefs 164B
assets
gen
demo
playfile
BuildConfig.java 155B
R.java 832B
libs
android-support-v4.jar 341KB
jcifs-1.3.17.jar 387KB
.classpath 535B
bin
playfile.apk 340KB
resources.ap_ 11KB
classes
demo
playfile
R$layout.class 379B
service
PlayFileService.class 1KB
BuildConfig.class 335B
R$drawable.class 392B
PlayfileActivity.class 7KB
R$attr.class 325B
PlayfileActivity$SearchTask.class 4KB
util
FileServer.class 5KB
FileUtil.class 2KB
HTTPRequestListener.class 208B
FileItem.class 1KB
R$id.class 420B
R.class 496B
R$string.class 412B
PlayfileActivity$1.class 2KB
org
cybergarage
http
Date.class 3KB
Parameter.class 985B
HTTPServer.class 5KB
HTTP.class 5KB
HTTPSocket.class 5KB
HTTPPacket.class 16KB
HTTPRequest.class 10KB
HTTPHeader.class 3KB
HTTPServerThread.class 1KB
HTTPRequestListener.class 210B
HTTPServerList.class 3KB
HTTPStatus.class 3KB
ParameterList.class 1KB
HTTPResponse.class 3KB
HTML.class 379B
util
StringUtil.class 2KB
ListenerList.class 529B
Debug.class 2KB
FileUtil.class 2KB
TimerUtil.class 704B
Mutex.class 749B
ThreadCore.class 1KB
net
HostInterface.class 6KB
AndroidManifest.xml 878B
dexedLibs
android-support-v4-472c5e3186bf34d5be1cbea37d4ac826.jar 132KB
jcifs-1.3.17-436cd18ab7240dc0e2df3ddda5190ea7.jar 175KB
jarlist.cache 120B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 2KB
crunch
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 2KB
classes.dex 1.07MB
共 97 条
- 1
魈痕
- 粉丝: 4
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页