This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have been trying for a week now to correctly use a socket to read the stream of a response from a server than simply parse out the GZIP response body portion and than place those bytes into the GZIPInputStream and get back my results as a string. I'm able to get it to unzip for certain responses however others fail? I think I'm incorrectly removing bytes from the stream maybe when I dechunk the response. The response is sent in a chunked format so I need to remove those bytes and put back together in order for the gzip file to be correct. So here is what I do first let me give you the gzipped test response I have created:
The contents of gzip.php which send that content gzipped up
Here is the response and the parsed content I get from the server,after parsing the content of response out and after cleaning up erroneous chunk data out:
I'm assuming I must be stripping out an important byte somewhere when I'm cleaning up the bytes here is how I get those bytes above:
To strip out the headers and body from response I do the following:
To me that process looks to be getting the correct content as shown by the bytes above chunked response body looks to be the content of response in bytes to me. Know because this particular response is chunked I need to remove the erronous chunked headers insinde that response body:
I have a sneaking suspicion this is where i'm stripping out maybe a byte or leaving a byte that should not be a part of the gzipped data. After this I send those bytes to the GZIP deflater below:
So whats happening is for a response like the one below after gzip deflates I get the following:
String after deflating and excetion thrown:
But a simple change of the s in Lights in response to Lighta like the following response:
I get back correctly unzipped with no exceptions? Can anyone give me any ideas about what may be wrong? I tried taking that same response content and place inside a file and gzip it and it unzipps just fine. I even tried to compare the bytes of the gzips from sever vs file and they are completely different for some reason. Even when the server one correctly unzips so I can't use that as a way to compare the bytes to see which byte from server may be missing?