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

  • Home
  • SEARCH
  • 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 909203
In Process

The Archive Base Latest Questions

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

The background Currently, I try to get a zip-file through a HTTP-servlet with a

  • 0

The background
Currently, I try to get a zip-file through a HTTP-servlet with a HTTP-request. The received zip-file contains three different files. These files contain information I want to filter out and doing this from the source is not an option (that’s just how it is, though I am aware it would be much better).

Because I cant filter out some information in the file from the source, where the file is build from the beginning, my solution is to decompress the file, read these three files as strings and then filter them. In the end “rebuild” all as a “zipfile” (inputStream) and return the inputStream.

The problem
Currently, I’ve made a class to handle the decompression and filtering of the file. In the end I just want to return the new inputStream containing the zip-file and the three files inside.

I’ve come as far as get the content from the HTTP entity into a inputStream, decompress this inputStream and get the three files as three strings. To just try to see if this work, I currently don’t want to do more than just decompress them and just close the inputStream and return it.. This does however cause an exception when I return the inputStream:

 java.io.IOException: Attempted read on closed stream.

This is because the inputStream is used outside the function I present below. As I close the zipInputStream, I probably also closes the inputStream for further work.

The current code

public InputStream convertInputStream(HttpEntity entity)
{
    InputStream inputStream = null;
    try
    {
        inputStream = entity.getContent();
    }
    catch (IOException e11)
    {

    }

    ZipInputStream zipInputStream = new ZipInputStream(inputStream);
    Vector <String>entryVector = new Vector<String>();
    ZipEntry entry;
    try
    {
        String entryValue;
        while((entry = zipInputStream.getNextEntry()) != null)
        {           
            System.out.println("Unzipping file: " + entry.getName() + "...");
            byte [] buf = new byte[(int) entry.getSize()];
            zipInputStream.read(buf);
            entryValue = new String(buf);
            entryVector.add(entryValue);
            zipInputStream.closeEntry();
        }
    }
    catch(IOException e)
    {
        System.out.println("error in getting next entry.");
    }
    finally
    {
        try 
        {
            zipInputStream.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        System.out.println("Unzipping done!");
    }
    return inputStream;
}

I hope I manage to express this as clear as possible. I can still see that this is very confusing to understand when I can’t show the whole solution outside this function.

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

    Where you print “unzipping file”, you are not actually unzipping anything. If you want to do that, you need to read the content of the entry from the ZipInputStream using the read() function and write that to a file.

    EDIT:
    You can try reading the (compressed) zip file from the input stream into a byte array. Then create a ByteArrayInputStream on that array and then wrap your ZipInputStream around that. Then you can safely close the input stream without closing the underlying stream.

    Also, make sure that the file’s content as String is actually useful. new String(byte[]) creates a string using the default encoding, so this may very well be useless.

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

Sidebar

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.