?
Solved

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

Posted on 2003-02-27
6
Medium Priority
?
3,793 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

801 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