• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading chunked data from socket.  RSS feed

sudh sasi
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In http response header I am seeing "Transfer-Encoding: chunked". Each chunk comes with a header indicator on the length of chunk. While reading response from socket and appending it to string buffer, the chunk header is also getting in as part of response. How to avoid this unwanted part (Chunk length) from getting to my final response string.
Here is the code that I use to read response from socket.

byte[] buf = new byte[1024];
while ((i = in.read(buf)) > -1) {
String s = new String(buf, 0, i);
Alexandre de Paula
Posts: 8
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!