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

  • Home
  • SEARCH
  • 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 8624445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:31:51+00:00 2026-06-12T07:31:51+00:00

Hi I am using GZIP for compression and decompression of strings. Getting Some Exceptions

  • 0

Hi I am using GZIP for compression and decompression of strings.

Getting Some Exceptions ! Please Help me out !

protected byte[] CompressInputString(String input_string2)
        throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream(
            input_string2.length());
    System.out.println("Byte Array OS : " + os);
    GZIPOutputStream gos = new GZIPOutputStream(os);
    System.out.println("GZIPOutputStream : " + gos);
    gos.write(input_string2.getBytes());
    System.out.println("GZIPOutputStream get bytes: "
            + input_string2.getBytes());
    gos.close();
    byte[] compressed = os.toByteArray();
    os.close();
    System.out.println("Compressed : " + compressed);
    return compressed;

}

protected String DecompressInputString(byte[] input_to_decode_from_function)
        throws IOException {
    final int BUFFER_SIZE = 32;
    ByteArrayInputStream is = new ByteArrayInputStream(input_to_decode_from_function);
    GZIPInputStream gis = new GZIPInputStream(is, BUFFER_SIZE);
    StringBuilder string = new StringBuilder();
    byte[] data = new byte[BUFFER_SIZE];
    int bytesRead;
    while ((bytesRead = gis.read(data)) != -1) {
        string.append(new String(data, 0, bytesRead));
    }
    gis.close();
    is.close();
    return string.toString();
}

My input is : abcdefghijklmnop

The output is

GZIPOutputStream : java.util.zip.GZIPOutputStream@f38798
GZIPOutputStream get bytes: [B@4b222f
Compressed : [B@b169f8
Compressed File : [B@b169f8

To uncompress, what input do I give?

If I put [B@b169f8 as string input and convert it to byte array using input.getBytes() and pass it to my decompress function, an exception is raised

NOT IN GZIP FORMAL EXCEPTION LOG

  • 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-06-12T07:31:52+00:00Added an answer on June 12, 2026 at 7:31 am

    IF I PUT [B@b169f8 as string input and convert it to byte array using INPUT.getBytes() and pass it to my decompress function … A EXCEPTION IS RAISED

    Well yes – because “[B@b169f8” isn’t actually the content of the byte array. It’s just the result of calling toString() on it; it’s basically indicating the type of the object and its hash.

    If you want to convert a byte array into a string in a lossless way, you need to use something like base64. There are lots of libraries which perform base64 encoding, including this public domain one.

    Additionally, I would strongly advise against using either String.getBytes() or the String(byte[], int, int) constructors. You should always specify an encoding. The simplest way of reading the data would be to create an InputStreamReader wrapping the GZIPInputStream, and read text data directly from that. I’d suggest using UTF-8 as an encoding for the initial text-to-binary conversion (and on the decompression side too, of course).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a REST api with Gzip compression enabled, it's developed using the ASP.net
When using on_start() does it make any difference to do, // ENABLE GZIP COMPRESSION
I'm compressing a string with Gzip using this code: public static String Compress(String decompressed)
I've enabled gzip compression in IIS using the config settings specified in this answer
Wondering if anyone has set up GZIP compression for Spring HttpInvoker requests using Tomcat,
I have implemented GZIP compression on a few of my ASP.NET pages, using a
i´m using GZipStream to gzip string. Can someone tell me if it is possible
I am creating GZip compression using .htaccess. I am using following code to gzip
You might know that HTML related file formats are compressed using GZip compression, server
I'm using zlib to perform gzip compression. zlib writes the data directly to an

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.