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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:49:55+00:00 2026-06-06T01:49:55+00:00

I am trying to read multiple files (can be of any format i.e. pdf,

  • 0

I am trying to read multiple files (can be of any format i.e. pdf, txt, tiff etc) from URLs and zipping them using ZipOutputStream. My code looks like this:

    // using in-memory file read
    // then zipping all these files in-memory
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);
    .....

    URL url = new URL(downloadUrl); // can be multiple URLs

    ByteArrayOutputStream bais = new ByteArrayOutputStream();
    InputStream is = url.openStream();
    byte[] byteChunk = new byte[4096];
    int n;

    while ( (n = is.read(byteChunk)) > 0 )
    {
        bais.write(byteChunk, 0, n);
    }

    byte[] fileBytes = bais.toByteArray();

    ZipEntry entry = new ZipEntry(fileName);
    entry.setSize(fileBytes.length);

    zos.putNextEntry(entry);
    zos.write(fileBytes);
    zos.closeEntry();

    // close the url input stream 
    is.close();

    // close the zip output stream
zos.close();


    // read the byte array from ByteArrayOutputStream
    byte[] zipFileBytes = baos.toByteArray();

    String fileContent = new String(zipFileBytes);

I am then passing this content “fileContent” to my perl frontend application.

And I m using perl code to download this zipped file:

WPHTTPResponse::setHeader( 'Content-disposition', 'attachment; filename="test.zip"' );
WPHTTPResponse::setHeader( 'Content-type', 'application/zip');
print $result; // string coming from java application

But the zip file it is giving is corrupted. I think something in going wrong with the data translation.

I’d appreciate any 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-06T01:49:56+00:00Added an answer on June 6, 2026 at 1:49 am

    Your problem is thinking that you can output your zip bytes into a string. This string can not be used to reproduce the zip content again. You need to either use the raw bytes or encode the bytes into something that can be represented as a string, such as base64 encoding.

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

Sidebar

Related Questions

I am trying to read multiple files in R from the working directory and
So essentially I am trying to read lines from multiple files in a directory
I am trying to find the easiest way to read from multiple (around 100)
I'm trying to read java.io.InputStream multiple times starting from the top of the stream.
Using Python (3.1 or 2.6), I'm trying to read data from binary data files
I want to read multiple RSS feeds using jQuery. I'm trying to write a
Trying to read an RSS and select information using Linq but can't seem to
Im trying to read a column of String values from my DB. Im trying
I'm new to python and am trying to read blocks of data from a
I'm trying to read data from a.csv file to ouput it on a webpage

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.