I've tested out the code that you wrote on my emulator with Android 2.2 and it works fine. The chunked url I was using was: uri = new URI("httpwatch.com/httpgallery/chunked/") I noticed that the BasicResponseHandler continues to try to read until it reaches the end of stream, and gives back then entire data all at once. The code could hang waiting for the stream to close.
Does your webservice end the stream? Or does it continue to give back chunks forever? I don't see a method to get back just the first chunked, but I did write a simple handler that just reads the first read from the input stream (which given a large enough buffer corresponds to the chunk).
In the case of the URI I used for testing, it returns each line of the HTML file as a chunk. You can see just the first one returned here If this works for you, then you could easily write a handler that returns instead of a string, returns an Enumeration or some other object where you could return each of the chunks. Or even your own class public class ChunkedResponseHandler implements ResponseHandler { public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { HttpEntity entity = response.getEntity(); InputStream in = entity.getContent(); StringBuffer out = new StringBuffer(); byte be = new byte4096; int n = in.
Read(b); out. Append(new String(b, 0, n)); return out.toString(); } }.
I've tested out the code that you wrote on my emulator with Android 2.2 and it works fine. The chunked url I was using was: uri = new URI("httpwatch.com/httpgallery/chunked/"); I noticed that the BasicResponseHandler continues to try to read until it reaches the end of stream, and gives back then entire data all at once. The code could hang waiting for the stream to close.
Does your webservice end the stream? Or does it continue to give back chunks forever? I don't see a method to get back just the first chunked, but I did write a simple handler that just reads the first read from the input stream (which given a large enough buffer corresponds to the chunk).
In the case of the URI I used for testing, it returns each line of the HTML file as a chunk. You can see just the first one returned here. If this works for you, then you could easily write a handler that returns instead of a string, returns an Enumeration or some other object where you could return each of the chunks.
Or even your own class. Public class ChunkedResponseHandler implements ResponseHandler { public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { HttpEntity entity = response.getEntity(); InputStream in = entity.getContent(); StringBuffer out = new StringBuffer(); byte be = new byte4096; int n = in. Read(b); out.
Append(new String(b, 0, n)); return out.toString(); } }.
Thanks - that works. The web service I am attached to is streaming continuously so that explains why the BasicResponseHandler does not help me. I have a "read-object" method to assemble/parse the data into the individual streaming objects.
Now to find out how to get ChunkedInputStream to work ... – mobibob Mar 1 at 18:18 In the debugger, you can see that the InputStream returned by getContent() is wrapped around the ChunkendInputStream if that helps at all. – christophercotton Mar 1 at 20:03 Hmmm ... early in my investigation, I put a getContent().getClass().toString() debug message and I recall it was something like EofInputStream. I will check again with the new code.
– mobibob Mar 1 at 20:59 1 It is an EofSensorInputStream, but in the debugger you can see it has a wrappedStream with a class of ChunkedInputStream. You can have the ResponseHandler subclass return your objects. Since the ResponseHandler does everything for you, and just need to read the available number of bytes using the InputStream#available() I haven't tested it completely, but in the chunked version I did it mapped correctly.
– christophercotton Mar 1 at 21:21 +1 for that comment! I will definitely be refactoring my code to use your suggestions. – mobibob Mar 17 at 20:32.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.