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

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 "";
       }    
     }
davidslee9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

functionpointerCommented:
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
boxy73Commented:
Change it from String compression to File compression, it works when using the same data
0
davidslee9Author Commented:
boxy73-->

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

thanks
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

boxy73Commented:
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
boxy73Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
davidslee9Author Commented:
used a ZipOutputStream .. almost there ... thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.