View Single Post
  #1 (permalink)  
Old 07-02-2008, 01:15 PM
hemanthjava hemanthjava is offline
Member
 
Join Date: Dec 2007
Posts: 16
hemanthjava is on a distinguished road
java.util.zip.ZipException: invalid bit length repeat EXCEPTION
My requirement is I need to compress a Big String and send it from server to Client. At the client end I need to decompress it back to get the original String

The size of my compressed String is 30447

When I uncompress it. I get this error

java.util.zip.ZipException: invalid bit length repeat

The following below is the code used for Compressing and Uncompressing a String.

Code:
private static void decompressString(byte[] baFileContentCompressed) { ByteArrayOutputStream baos; ByteArrayInputStream bais = new ByteArrayInputStream( baFileContentCompressed); GZIPInputStream zis = null; byte[] buffer = new byte[8192]; // the result byte[] baFileContentDecompressed = null; baos = new ByteArrayOutputStream(); try { buffer = new byte[1024]; try { zis = new GZIPInputStream(bais); for (int len; (len = zis.read(buffer, 0, 1024)) != -1;) { baos.write(buffer, 0, len); } zis.close(); bais.close(); baos.close(); baFileContentDecompressed = baos.toByteArray(); } catch (IOException e) { e.printStackTrace(); } System.out.println(new String(baFileContentDecompressed)); } catch (Exception e) { e.printStackTrace(); } } private static byte[] compressInputString(String testData) { byte[] baFileContent = testData.getBytes(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream zos; try { zos = new GZIPOutputStream(baos); zos.write(baFileContent); zos.close(); baos.close(); } catch (IOException e) { e.printStackTrace(); } byte[] baFileContentCompressed = baos.toByteArray(); return baFileContentCompressed; }


The exception is thrown when
Code:
len = zis.read(buffer, 0, 1024)
is invoked

Need some help here.

Regards,
Bob
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote
Sponsored Links