How to read the content of "Transfer-Encoding: chunked" header

Can anybody tell me how to get or read the value of transfer encoding.

I got the HTTP Response header as "Transfer-Encoding: chunked".But i can't get the chunk size or the chunked data.

Without getting those details i cant read the content of the site.If Content-Length is in the HTTP header,i can read upto that length.But in this Transfer-Encoding case,i cant know any other details except the value "chunked".So suggest me to read the content of the site using Transfer-Encoding.

Message was edited by:

VeeraLakshmi

[551 byte] By [VeeraLakshmia] at [2007-11-27 0:43:38]
# 1
http://forum.java.sun.com/thread.jspa?threadID=5158331&messageID=9600740#9600740
Michael.Nazarov@sun.coma at 2007-7-11 23:03:25 > top of Java-index,Core,Core APIs...
# 2

I used HTTPURLConnection also.If i use that am getting the values in request headers only and not in Response headers.So i cant read the content.

Then i went through RFC 2616.There i can only understand about chunked transfer encoding.Still i cant get any idea to know the chunk-size and the chunked data of the transfer encoding.Because i am getting the HTTP Header Response as "Transfer-Encoding: chunked".Below that am not getting the size and data.If i know the size or data,i can proceed by converting the hex into bytes and i can read.

VeeraLakshmia at 2007-7-11 23:03:25 > top of Java-index,Core,Core APIs...
# 3
HttpURLConnection handles chunked encoded responses automatically - you should need to do anything except read from the input stream.
alan.batemana at 2007-7-11 23:03:25 > top of Java-index,Core,Core APIs...
# 4

Ok...but without reading from input stream how can i know the body of the message.

If the site has Content-Length header,i read from input stream upto that length and concatenate the header and body in a whole message.

But in this case,what should i do...Plz give me some suggestions.

VeeraLakshmia at 2007-7-11 23:03:25 > top of Java-index,Core,Core APIs...
# 5

If the response is streamed from the server as a chunked encoded response then the content length is not known and the getContentLength method will return -1. So you must read to EOF to read the entire body. You can't pre-size a buffer to store the entire body because the length is just not known in advance.

alan.batemana at 2007-7-11 23:03:25 > top of Java-index,Core,Core APIs...