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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:03:09+00:00 2026-06-13T05:03:09+00:00

Given ZipFile zip , its ZipEntry entry and target File unzippedEntryFile , what is

  • 0

Given ZipFile zip, its ZipEntry entry and target File unzippedEntryFile, what is the most readable way to write entry to unzippedEntryFile?

I came up with following solution using Google Guava and Apache.Commons.IO:

InputSupplier<ByteArrayInputStream> entryInputSupplier = ByteStreams.newInputStreamSupplier(IOUtils.toByteArray(zip.getInputStream(entry)));
Files.copy(entryInputSupplier, unzippedEntryFile);

However, something tells me it can be made simplier.

Thanks,
Konrad

  • 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-13T05:03:09+00:00Added an answer on June 13, 2026 at 5:03 am

    I don’t know what’s not readable about your code, other than that you have a lot of nested calls. These can be broken out and assigned to local variables, which would make the code longer (but, in my opinion, a bit more readable).

    You do seem to be processing the data twice — once to read it into a byte array and again to copy it to the file. I haven’t tested this, but it should work and cut the amount of data movement in half:

    final InputStream zipStream = zip.getInputStream(entry);
    InputSupplier<InputStream> supplier = new InputSupplier<InputStream>() {
        InputStream getInput() {
            return zipStream;
        }
    };
    Files.copy(supplier, unzippedEntryFile);
    

    You could, in fact, create your own little class that implements InputSuppler<InputStream>. I’m surprised that I couldn’t find one in the Guava library. (Apparently, others have been surprised at this as well.)

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

Sidebar

Related Questions

I'm using the following method to compress a file into a zip file: import
Given URL of an archive (e.g. a zip file) Full name (including path) of
Given that I have a zip file called archive.zip that contains a file called
I have a FileUploader class that can optionally be given a zip file which
I am writing a component that, given a ZIP file, needs to: Unzip the
I've recently been given a task that involves uploading a zip file, storing it
I have a perl script URL which gives me a ZIP file, it processes
Please any one give me the suggestion for this. I'm having the Xerces-J-source.zip file
Given a zipfile with an unknown directory, how can I rename or move that
Trying to extract files to a given folder ignoring the path in the zipfile

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.