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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:02:05+00:00 2026-06-01T16:02:05+00:00

I’m trying to make a program to compress file to .tar.gz: Here is the

  • 0

I’m trying to make a program to compress file to .tar.gz:

Here is the code:

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;

public class Compress {

    public static void main(String[] args) {
        BufferedInputStream input = null;
        try {
            input = new BufferedInputStream(new FileInputStream(new File("input_filename.filetype")));
            TarArchiveOutputStream out = null;
            try {
                out = new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream("output_filename.tar.gz"))));
                out.putArchiveEntry(new TarArchiveEntry(new File("input_filename.filetype")));

                int count;
                byte data[] = new byte[input.available()];
                while ((count = input.read(data)) != -1) {
                    out.write(data, 0, count);
                }

                input.close();
            } catch (IOException ex) {
                Logger.getLogger(Compress.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                if (out != null) {
                    try {
                        out.closeArchiveEntry();
                        out.close();
                    } catch (IOException ex) {
                        Logger.getLogger(Compress.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Compress.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                input.close();
            } catch (IOException ex) {
                Logger.getLogger(Compress.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

I’m using Apache Commons Compression as the library.

I test with 2 conditions:

  1. Compress GIF File
  2. Compress PDF File

And I compare compress using PeaZip, here is the result:

  1. Compare GIF, From Left to Right -> Code Above, PeaZip, File Input
  2. Compare PDF, From Left to Right -> Code Above, PeaZip, File Input

If the input file is GIF the size of the compress file increase, same if we using PeaZip. But for the other file it works for the compression process.

Can anyone explain what happen with this? Is there are something wrong with my code?

Thank you for your help…

  • 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-01T16:02:07+00:00Added an answer on June 1, 2026 at 4:02 pm

    Depending on what compression algorithm you’re using, you’ll get different results — each type of file compresses differently. Text files, for example, compress extremely well. Also, since GIF files are already compressed using LZW compression, a second compression should have little to no effect.

    From Wikipedia, “GIF images are compressed using the Lempel-Ziv-Welch (LZW) lossless data compression technique to reduce the file size without degrading the visual quality.”

    See http://en.wikipedia.org/wiki/Graphics_Interchange_Format for more info.

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

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

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.