Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 877673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:38:55+00:00 2026-05-15T11:38:55+00:00

I am compressing a string using gzip, then uncompress the result, however I got

  • 0

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);
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:38:56+00:00Added an answer on May 15, 2026 at 11:38 am

    According to this page, a likely cause is that the ZIP file you are trying to read is corrupted. (I know it is not an exact match to your circumstances … but I’m sure that the exception message is indicative.)

    In your case, the problem is that you are converting the gzip stream from a byte array into a String and then back to a byte array. This is almost certainly a lossy operation, resulting a corrupted GZIP stream.

    If you want to convert an arbitrary byte array to a string form and back, you will need to use one of the string encoding formats designed for that purpose; e.g. base64.

    Alternatively, just change this:

        String out = outstream.toString();
        ByteArrayInputStream in = new ByteArrayInputStream(out.getBytes());
    

    to this:

        byte[] out = outstream.toByteArray();
        ByteArrayInputStream in = new ByteArrayInputStream(out);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm compressing a string with Gzip using this code: public static String Compress(String decompressed)
I need an example for compressing a string using GZip in android. I want
I am compressing an image using following class.. <?php class SimpleImage { var $image;
I'm having a problem de-compressing a ZIP file using Java. The method is below.
i´m using GZipStream to gzip string. Can someone tell me if it is possible
I'm compressing a string using PHP's gzcompress() function: https://www.php.net/manual/en/function.gzcompress.php I'd like to take the
I am compressing the array with gzcompress(json_encode($arr),9). So I am converting array into string
I'm compressing some textures using ETC1 when my application starts. I also have a
I am compressing html files with gzip. The browser (FF 3.0.10) does not decompress
I have an application where I am taking a bitmap and compressing it using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.