• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading chunked data from socket.  RSS feed

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

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);
outputBuffer.append(s);
}
 
Alexandre de Paula
Greenhorn
Posts: 8
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!