java Transfer-Encoding 解析!

private ByteArrayOutputStream readChunked(byte[] bytes, boolean isChunked) throws IOException{ if(!isChunked){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(bytes, 0, bytes.length); return baos; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); int mark = 0; int pos = 0; int orginLength = bytes.length; while((pos+2) < orginLength){ if((int)bytes[pos+1] == 13 && (int)bytes[pos+2] == 10){ byte[] length2Byte = new byte[pos - mark + 1]; System.arraycopy(bytes, mark, length2Byte, 0, pos - mark + 1); int length2Int = Integer.parseInt(new String(length2Byte), 16); if(length2Int == 0) return baos; pos += 3 ; mark = pos; baos.write(bytes, mark, length2Int); pos += (length2Int - 1)+3; mark = pos; }else{ pos++; } } return baos; }

你可能感兴趣的:(java,String,byte)