private void getContentlen_Chucked(String tempStr) //获得长度 CONTENT-LENGTH 或 是否为CHUNKED型 { String ss1="CONTENT-LENGTH:"; String ss2=new String("TRANSFER-ENCODING: CHUNKED"); int clIndex = tempStr.indexOf(ss1); int chuckIndex = tempStr.indexOf(ss2); //为CHUNKED型 byte requst[]= tempStr.getBytes(); if(clIndex!=-1) { //从clIndex+1起至\r\n StringBuffer sb=new StringBuffer(); for(int i=(clIndex+16);;i++) { if(requst[i]!=(byte)13 && requst[i]!=(byte)10 ) { sb.append((char)requst[i]); } else break; } CONTENT_LENGTH=Integer.parseInt(sb.toString()); //正式的HTML文件的大小 //System.out.println("CONTENT_LENGTH== "+CONTENT_LENGTH); } if(chuckIndex!=-1) beChucked=true; } private int getChuckSize() //Chuck大小 { byte[] crlf = new byte[1]; StringBuffer sb1 = new StringBuffer(); int crlfNum= 0; //已经连接的回车换行数 crlfNum=4为头部结束 try{ while(input.read(crlf)!=-1) //读取头部 { if(crlf[0]==crlf13 || crlf[0]==crlf10) { crlfNum++; } else { crlfNum=0; } //不是则清 sb1.append((char)crlf[0]); request=request.append(new String(crlf,0,1)); //byte数组相加 if(crlfNum==2) break; } }catch(IOException e){ System.out.println("Read Http Package Error!"); return 0; } return Integer.parseInt((sb1.toString()).trim(),16); //16进控制 } //通过此来进行过滤,是否为发至目标服务器的HTTP包 private String parseUri(String requestString) { int index1, index2; index1 = requestString.indexOf(' '); if (index1 != -1) { index2 = requestString.indexOf(' ', index1 + 1); if (index2 > index1) return requestString.substring(index1 + 1, index2); } return null; } |