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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:56:45+00:00 2026-05-22T11:56:45+00:00

Can anyone recommend whether I should do something like: os = new GzipOutputStream(new BufferedOutputStream(…));

  • 0

Can anyone recommend whether I should do something like:

os = new GzipOutputStream(new BufferedOutputStream(...));

or

os = new BufferedOutputStream(new GzipOutputStream(...));

Which is more efficient? Should I use BufferedOutputStream at all?

  • 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-22T11:56:46+00:00Added an answer on May 22, 2026 at 11:56 am

    What order should I use GzipOutputStream and BufferedOutputStream

    For object streams, I found that wrapping the buffered stream around the gzip stream for both input and output was almost always significantly faster. The smaller the objects, the better this did. Better or the same in all cases then no buffered stream.

    ois = new ObjectInputStream(new BufferedInputStream(new GZIPInputStream(fis)));
    oos = new ObjectOutputStream(new BufferedOutputStream(new GZIPOutputStream(fos)));
    

    However, for text and straight byte streams, I found that it was a toss up — with the gzip stream around the buffered stream being only slightly better. But better in all cases then no buffered stream.

    reader = new InputStreamReader(new GZIPInputStream(new BufferedInputStream(fis)));
    writer = new OutputStreamWriter(new GZIPOutputStream(new BufferedOutputStream(fos)));
    

    I ran each version 20 times and cut off the first run and averaged the rest. I also tried buffered-gzip-buffered which was slightly better for objects and worse for text. I did not play with buffer sizes at all.


    For the object streams, I tested 2 serialized object files in the 10s of megabytes. For the larger file (38mb), it was 85% faster on reading (0.7 versus 5.6 seconds) but actually slightly slower for writing (5.9 versus 5.7 seconds). These objects had some large arrays in them which may have meant larger writes.

    method       crc     date  time    compressed    uncompressed  ratio
    defla   eb338650   May 19 16:59      14027543        38366001  63.4%
    

    For the smaller file (18mb), it was 75% faster for reading (1.6 versus 6.1 seconds) and 40% faster for writing (2.8 versus 4.7 seconds). It contained a large number of small objects.

    method       crc     date  time    compressed    uncompressed  ratio
    defla   92c9d529   May 19 16:56       6676006        17890857  62.7%
    

    For the text reader/writer I used a 64mb csv text file. The gzip stream around the buffered stream was 11% faster for reading (950 versus 1070 milliseconds) and slightly faster when writing (7.9 versus 8.1 seconds).

    method       crc     date  time    compressed    uncompressed  ratio
    defla   c6b72e34   May 20 09:16      22560860        63465800  64.5%
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application in which users interact with each-other. I want to visualize
I am trying to use Python to read in an XML file containing some
We have a number of embedded systems requiring r/w access to the filesystem which
My query look like this at the moment: $result = mysql_query(SELECT * FROM promo
What list of verbs are you using for method names? What's your personal or
I have recently implemented an Action that toggles the enabled status of a business
Disclaimer: I have no Twitter API experience nor have I used Twitter until today
I work for a medical lab company. They need to be able to search
I recently came across this in some code - basically someone trying to create
Consider the following code (C# 4.0): public class Foo : LambdaExpression { } This

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.