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 6181377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:00:40+00:00 2026-05-24T01:00:40+00:00

So as the title suggests, I’m trying to get and gunzip a string from

  • 0

So as the title suggests, I’m trying to get and gunzip a string from an HTTP request.

urlConn = url.openConnection();
int len = CONTENT_LENGTH
byte[] gbytes = new byte[len];
gbuffer = new GZIPInputStream(urlConn.getInputStream(), len);
System.out.println(gbuffer.read(gbytes)+"/"+len);
System.out.println(gbytes);
result = new String(gbytes, "UTF-8");
gbuffer.close();
System.out.println(result);

With some URLs, it works fine. I get output like this:

42/42
[B@96e8209
The entire 42 bytes of my data. Abcdefghij.

With others, it gives me something like the following output:

22/77
[B@1d94882
The entire 77 bytes of

As you can see, the first some-odd bytes of data are very similar if not the same, so they shouldn’t be causing these issues. I really can’t seem to pin it down. Increasing CONTENT_LENGTH doesn’t help, and data streams of sizes both larger and smaller than the ones giving me issues work fine.

EDIT: The issue also does not lie within the raw gzipped data, as Cocoa and Python both gunzip it without issue.

EDIT: Solved. Including final code:

urlConn = url.openConnection();
int offset = 0, len = CONTENT_LENGTH
byte[] gbytes = new byte[len];
gbuffer = new GZIPInputStream(urlConn.getInputStream(), len);
while(offset < len)
{
    offset += gbuffer.read(gbytes, offset, offset-len);
}
result = new String(gbytes, "UTF-8");
gbuffer.close();
  • 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-24T01:00:41+00:00Added an answer on May 24, 2026 at 1:00 am

    It’s possible that the data isn’t available in the stream. The first println() you have says you’ve only read 22 bytes, so only 22 bytes were available when you called read(). You can try looping until you’ve read CONTENT_LENGTH worth of bytes. Maybe something like:

    int index = 0;
    int bytesRead = gbuffer.read(gbytes);
    while(bytesRead>0 && index<len) {
        index += bytesRead;
        bytesRead = gbuffer.read(gbytes,index,len-index);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

as title suggests. id string is passed to view as ViewData variable.
As the title suggests, is it correct or valid to import/export static data from
As title suggests, I had problems with a program of mine where I used
As the title suggests, I am having trouble maintaining my code on postback. I
As the title suggests. I want to be able to change the label of
As the title suggests, I'm using Google App Engine and Django. I have quite
As the title suggests, I would like to see if this is something people
As the title suggests, what's the difference between a Component (New –> MXML Component)
So as the title suggests I wish to create a new dom element (the
As the title suggests, I am curious as to the suggested file/directory permissions for

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.