Getting striped data

As you know, there is no content length for sending a chunked file in the HTTP header, so the program must wait 0 to understand that this file has ended.

--sample http header POST /some/path HTTP/1.1 Host: www.example.com Content-Type: text/plain Transfer-Encoding: chunked 25 This is the data in the first chunk 8 sequence 0 

You can use the following code to get this file.

 ResponseHandler<String> reshandler = new ResponseHandler<String>() { public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { HttpEntity entity = response.getEntity(); InputStream in = entity.getContent(); byte[] b = new byte[500]; StringBuffer out = new StringBuffer(); int len = in.read(b); out.append(new String(b, 0 , len)); return out.toString(); } }; 

but in my case, I am working with a streaming channel in another word, there is no 0 that indicates that the file has ended. Anyway, if I use this code, it seems like it is waiting forever to wait for 0, which will never happen. my question is is there a better approach to getting a file with a channel from a channel channel?

+4
source share
1 answer

Ok I could get the data using a simple approach (both the next one and without using a response handler). anyway, I'm still a bit confused about the apache ChunkedInputStream and how it can be used, while a normal input stream can process data with channels.

 is = entity.getContent(); StringBuffer out = new StringBuffer(); byte[] b = new byte[800]; int len = is.read(b); out.append(new String(b, 0 , len)); result = out.toString(); 
+1
source

All Articles