I am compressing a string using gzip, then uncompress the result, however I got the following exception, why?
output: Exception in thread "main" java.util.zip.ZipException: oversubscribed dynamic bit lengths tree at java.util.zip.InflaterInputStream.read(Unknown Source) at java.util.zip.GZIPInputStream.read(Unknown Source) at Test.main(Test.java:25)
public class Test {
public static void main(String[]args) throws IOException{
String s="helloworldthisisatestandtestonlydsafsdafdsfdsafadsfdsfsdfdsfdsfdsfdsfsadfdsfdasfassdfdfdsfdsdssdfdsfdsfd";
byte[]bs=s.getBytes();
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
GZIPOutputStream gzipOut = new GZIPOutputStream(outstream);
gzipOut.write(bs);
gzipOut.finish();
String out=outstream.toString();
System.out.println(out);
System.out.println(out.length());
ByteArrayInputStream in = new ByteArrayInputStream(out.getBytes());
GZIPInputStream gzipIn=new GZIPInputStream(in);
byte[]uncompressed = new byte[100000];
int len=10, offset=0, totalLen=0;
while((len = gzipIn.read(uncompressed, offset, len)) >0){ // this line
offset+=len;
totalLen+=len;
}
String uncompressedString=new String(uncompressed,0,totalLen);
System.out.println(uncompressedString);
}
}