davidslee9
asked on
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.getByt es());
buf=new byte[trg.length()];
l=decomp.inflate(buf);
return new String(buf,0,l);
}
catch(Exception e)
{
System.out.println("decomp ress: " + e);
e.printStackTrace();
return "";
}
}
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.getByt
buf=new byte[trg.length()];
l=decomp.inflate(buf);
return new String(buf,0,l);
}
catch(Exception e)
{
System.out.println("decomp
e.printStackTrace();
return "";
}
}
Change it from String compression to File compression, it works when using the same data
ASKER
boxy73-->
How do you simply change this from string to file compression ??
thanks
How do you simply change this from string to file compression ??
thanks
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
used a ZipOutputStream .. almost there ... thanks
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.