?? httprequest.java
字號(hào):
package com.zhanghao.provision;import java.io.DataInputStream;import java.io.InputStream;import java.io.ByteArrayInputStream;public class HttpRequest { protected DataInputStream inputStream; protected boolean change = false; public HttpRequest() { } public HttpRequest(InputStream inputStream) { this.inputStream = new DataInputStream(inputStream); } public DataInputStream getInputStream() throws Exception{ try{ System.out.println("parseHeaders...."); parseHeaders(); return this.inputStream; } catch(Exception ex){ throw new Exception("取得InputStream失敗:"+ex.getMessage()); } } public void parseHeaders() throws Exception{ if(!saveChange()){ try{ String str = inputStream.readLine(); String strTemp = ""; strTemp = strTemp+str; int iLength = 0; while(!str.equals("")){ System.out.println(str); str = inputStream.readLine(); if(str.startsWith("Content-Length:")){ iLength = Integer.parseInt(str.substring(str.indexOf(" ")).trim()); } } byte[] bb = new byte[iLength]; inputStream.readFully(bb,0,iLength); java.io.ByteArrayInputStream binput = new ByteArrayInputStream(bb); inputStream = new DataInputStream(binput); } catch(Exception ex){ throw new Exception("解析HTTP包頭失敗:"+ex.getMessage()); } } saveChange(); } public boolean saveChange(){ if(!change){ change = true; return false; } return true; } public boolean getChange(){ return this.change; }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -