소스 검색

add makeHttpChunk utility

tags/2.0.1
Jonathan Cobb 5 년 전
부모
커밋
fcf50f03d1
1개의 변경된 파일14개의 추가작업 그리고 0개의 파일을 삭제
  1. +14
    -0
      src/main/java/org/cobbzilla/util/http/HttpUtil.java

+ 14
- 0
src/main/java/org/cobbzilla/util/http/HttpUtil.java 파일 보기

@@ -360,4 +360,18 @@ public class HttpUtil {

return meta;
}

public static final byte[] CHUNK_SEP = "\r\n".getBytes();
public static final int CHUNK_EXTRA_BYTES = 2 * CHUNK_SEP.length;
public static final byte[] CHUNK_END = "0\r\n".getBytes();

public static byte[] makeHttpChunk(byte[] buffer, int bytesRead) {
final byte[] httpChunkLengthBytes = Integer.toHexString(bytesRead).getBytes();
final byte[] httpChunk = new byte[bytesRead + httpChunkLengthBytes.length + CHUNK_EXTRA_BYTES];
System.arraycopy(httpChunkLengthBytes, 0, httpChunk, 0, httpChunkLengthBytes.length);
System.arraycopy(buffer, 0, httpChunk, httpChunkLengthBytes.length, bytesRead);
System.arraycopy(CHUNK_SEP, 0, httpChunk, httpChunkLengthBytes.length+bytesRead, CHUNK_SEP.length);
return httpChunk;
}

}

불러오는 중...
취소
저장