Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-02-27
6
Medium Priority
?
4,154 Views
Last Modified: 2011-09-20
I'm trying to inflate a compressed string that was compressed using the Deflater,however, I'm getting this error: java.util.zip.ZipException:invalid bit length repeat.

Any help would be great !!!  PLEASE !!!

Here is the sample code:

   public static String decompress(String trg)
     {
     try
       {
          byte[] buf;
          int l;
          Inflater decomp=new Inflater(true);          
          decomp.setInput(trg.getBytes());
          buf=new byte[trg.length()];
          l=decomp.inflate(buf);
          return new String(buf,0,l);
       }
     catch(Exception e)
       {
          System.out.println("decompress: " + e);
          e.printStackTrace();
          return "";
       }    
     }
0
Comment
Question by:davidslee9
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:functionpointer
ID: 8039620
One thing is certain.
Do not trust the value returned by the .inflate(buf) method.  
It lies. Plain and simple. It lies. Any thing less than buf.length is not trustworthy.
We ran into this problem debugging a compressed, CBC-encrypted file and it kicked our butts pretty hard. Its in the native library ( at least 1.4 Win ). Not much you can do about it.
If you have less than the full buffer, run a quick check on the last buf you fill. See for yourself where it stopped filling the buffer and go from there.
BTW, you cant really allocate your uncompressed buffer to the same size as your compressed String, can you? Wrap this in a while loop and write your bytes to a ByteArrayOutputStream, checking anything less that buf.length.  Good luck.
0
 
LVL 4

Expert Comment

by:boxy73
ID: 8040190
Change it from String compression to File compression, it works when using the same data
0
 

Author Comment

by:davidslee9
ID: 8041519
boxy73-->

How do you simply change this from string to file compression ??

thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:boxy73
ID: 8041884
I said that if you could use File instead of String in your function, it could work. I don't know if that's possible because your inflating a compressed File.

0
 
LVL 4

Accepted Solution

by:
boxy73 earned 100 total points
ID: 8042747
I said that if you could use File instead of String in your function, it could work. I don't know if that's possible because your inflating a compressed File.

0
 

Author Comment

by:davidslee9
ID: 8044868
used a ZipOutputStream .. almost there ... thanks
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question