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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:13:24+00:00 2026-06-13T11:13:24+00:00

This honestly should not be having so many issues, but I must be missing

  • 0

This honestly should not be having so many issues, but I must be missing something obvious.

I can compress a file just fine using GZIPOutputStream but when I try to get the input directly (not from a file, but from a pipe or something), when I go to call gunzip -d on my file to see if it decompresses correctly, it tells me that it runs into an end of file immediately. Basically, I want these to work

echo foo | java Jgzip >foo.gz

or

java Jzip <test.txt >test.gz

And there’s no guarantee these are strings, so we’re reading byte by byte. I thought I could just use System.in and System.out, but that doesn’t seem to working.

public static void main (String[] args) {
    try{
        BufferedInputStream bf = new BufferedInputStream(System.in);
        byte[] buff = new byte[1024];
        int bytesRead = 0;

        GZIPOutputStream gout = new GZIPOutputStream (System.out);

        while ((bytesRead = bf.read(buff)) != -1) {
            gout.write(buff,0,bytesRead);
        }
    }
    catch (IOException ioe) {
        System.out.println("IO error.");
        System.exit(-1);    
    }
    catch (Throwable e) {
        System.out.println("Unexpected exception or error.");
        System.exit(-1);
    }
}
  • 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-13T11:13:25+00:00Added an answer on June 13, 2026 at 11:13 am

    I suggest:

    OutputStream gout= new GZIPOutputStream( System.out );
    System.setOut( new PrintStream( gout ));              //<<<<< EDIT here
    while(( bytesRead = bf.read( buff )) != -1 ) {
       gout.write(buff,0,bytesRead);
    }
    gout.close(); // close flush the last remaining bytes in the buffer stream
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Preface : I'm honestly not sure if this should be on StackOverflow, SuperUser or
Somewhere some guy said (I honestly do not know where I got this from),
Crappy title, yes. But I honestly have no idea what this particular line of
there are many ActiveRecord versioning gems available to Rails but most if not all
Im not sure how else I should approach it, but if I was to
Sorry for the length of this, but more info is usually better than not
I'm honestly not sure if the title fits the question completely, but here it
I have this Objective-C code that I found somewhere. Honestly, I don't understand a
This should be a simple one: I have an observableArray object called To in
Hope the title is not that confusing - honestly said I had no idea

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.