📄 httprequest.java
字号:
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; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -