gzip - java.util.zip.ZipException: oversubscribed dynamic bit lengths tree -


I am compressing a string using gzip, then uncompress the result, but I got the following exception, Why?

Output: Exception in thread "main": java.util.zip.ZipException: javas.util.zip.InflaterInputStream.reads overbased dynamic bit length tree (Unknown source) source at Java.util.zip.GZIPInputStream.read (test.java:25)
  public level test {public static zero main (string [] args throws IOException { String s = "helloworldthisisatestandtestonlydsafsdafdsfdsafdsfdsfsdfdsfdsfdsfdsfdsfdasfassfdfdsfdsdssdfdsfdsfd"; Byte [] bs = s.getBytes (); Bytereon OutputStream Outstream = New Bytereanputstream (); GZIPOutputStream gzipOut = new GZIPOutputStream (outward); GzipOut.write (bs); GzipOut.finish (); String Out = Outstream.string (); Println (outside); Println (out.length ()); ByteArrayInputStream = New Bytereinputstream (out.getBytes ()); GZIP InputStream gzipIn = new GZIP InputStream (in); Byte [] uncompressed = new byte [100000]; Int len ​​= 10, offset = 0, totalen = 0; While ((len = gzipIn.read (uncompressed, offset, lane)) gt; 0) {// This line offset + = Lennon; TotalLen + = lane; } String uncompressed string = new string (uncompressed, 0, total lane); Println (uncompressedString); According to, one possible reason is that the zip file you are trying to read is corrupt (I know that this is not an exact match for your circumstances ... but I'm sure the exception message is indicated.)  

In your case, the problem is that you are converting the gzip stream into a single byte array and then back in a byte array. It is almost certainly a lossy operation, resulting in a corrupt GGIP stream.

If you want to change the string form and back an arbitrary byte array, you will need to use a string encoding format that purpose; Like Base64.

Alternatively, just replace it:

  string out = outstream. To string (); ByteArrayInputStream = New Bytereinputstream (out.getBytes ());  

To do this:

  byte [] out = outstream.toByteArray (); ByteArrayInputStream = new bytereinputstream (outside);  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -