You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Mi...@t-systems.com on 2012/04/25 14:52:43 UTC

Consuming compressed content throws exception

Hi all,

when trying to consume deflate content coded responses I get "java.util.zip.ZipException: invalid stored block lengths" exception.

server mock looks like:

header is byte array 

Deflater def = new Deflater(Deflater.BEST_COMPRESSION);
def.setInput(content);
def.finish();
contentLength = def.deflate(compressedContent);

// concat header and content
System.arraycopy(header, 0, response, 0, header.length);
System.arraycopy(compressedContent, 0, response, header.length, contentLength);

// sending response to socket
OutputStream outputStream = null;
BufferedOutputStream bos = null;
outputStream = socket.getOutputStream();
bos = new BufferedOutputStream(outputStream);
bos.write(Utils.buildHttpResponseWithCompressedBody(messagedata.response));
bos.flush();
bos.close();
outputStream.close();
...
socket.close();

client side looks like:

...
response = client.execute(method);
entity = response.getEntity();
...
DeflateDecompressingEntity dde = new DeflateDecompressingEntity(entity);
...
         bais = (ByteArrayInputStream) entity.getContent();
-->
  java.util.zip.ZipException: invalid stored block lengths
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:147)
        at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:138)
        at java.io.FilterInputStream.read(FilterInputStream.java:116)
        at java.io.PushbackInputStream.read(PushbackInputStream.java:169)
        at java.io.FilterInputStream.read(FilterInputStream.java:90)
        at org.apache.http.client.entity.DeflateDecompressingEntity.getDecompressingInputStream(DeflateDecompressingEntity.java:104)
        at org.apache.http.client.entity.DecompressingEntity.getContent(DecompressingEntity.java:72)
...


What could cause this exception?

If I use gzipped content (with appropriate classes) I get a "No GZIP format" exception. When I decompress content directly after compression I get the right content. I guess there must be a general problem with my setup.

Kind regards,

Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org