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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:22:01+00:00 2026-05-11T16:22:01+00:00

Love this website! My issue is as follows: I’m reading a zip file that’s

  • 0

Love this website! My issue is as follows:

I’m reading a zip file that’s coming over a network from an HTTP “PUT” request. The request header tells me that the Content-Length is (say) 1Mb. The following code creates the ZipInputStream, and saves the zip contents to files in the current directory:

ZipInputStream zis = new ZipInputStream(inputStream);
ZipEntry ze;
long totalBytesRead = 0;
while ((ze = zis.getNextEntry()) != null) {
    BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(ze.getName()));
    byte[] buffer = new byte[4096];
    int i;
    while ((i = zis.read(buffer)) != -1) {
        totalBytesRead+=i;
        outStream.write(buffer,0,i);
    } 
    outStream.close();
}
inputStream.close();

When all is said and done, totalBytesRead is equal to about 1.5Mb (depending on compression of the files, could be anything though!). What I’d like to know is if there is a way to find out how many actual bytes have been read from the original inputStream? Both ze.getSize() and ze.getCompressedSize() return -1 for every zipped entry (i.e. it doesn’t know). I need this info for a progress bar to show how many bytes of the transmitted zip file have been read off the network.

Suggestions? Should I perhaps subclass ZipInputStream and try to find out how many bytes it’s reading from it’s wrapped InputStream?

Thanks in advance!

  • 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-11T16:22:01+00:00Added an answer on May 11, 2026 at 4:22 pm

    Sure, that seems reasonable.

    There are basically two options: read all the bytes, store them (in memory or a file), count them, then decompress them; or count them as they come in. The former seems inefficient, and the latter will require a subclass of InputStream which has the ability to count the bytes it reads. I can’t think of one in the standard library, but implementations probably exist out there – then again it’d be pretty easy to write your own.

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

Sidebar

Related Questions

I'd love to understand how and where this website gets it's data from: http://elophant.com/developers/docs
I would love to get some tips from other people that have had this
I recently came across this website: http://www.mccormackmorrison.com/ I love the navigation method (vertical /
I've got a string like this: I love @kevinrose 's new website <a href=http://kevinrose.com>Link</a>
On this test page: http:// www.onebagoneearth.com/ Products-test , where it says oboe love series,
http://www.indofolio.com/ , I'm trying to create a website with similar function to this one,
I have partially developed a property website that fetch properties data from a RETS
My main website references this php file at the beginning of the document like
I love this shortcut in borne shell, and want to find out if it
I love this widget in google closure, Zippy and I need an equevalent in

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.