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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:58:29+00:00 2026-05-18T04:58:29+00:00

I need to zip data that is coming from one stream and put zipped

  • 0

I need to zip data that is coming from one stream and put zipped data to another. Here is the code that operates with files (MyOutputStream is a simple FileOutputStream wrapper used for debug purposes). This code works fine.

        ZipOutputStream jos = new ZipOutputStream( new MyOutputStream(new FileOutputStream(zipFileName)));
        jos.setLevel(Deflater.DEFAULT_COMPRESSION);
        jos.putNextEntry(new ZipEntry("test.txt"));
        FileInputStream in = new FileInputStream("test.txt");

        int len;
        while ((len = in.read(buffer)) > 0){
             jos.write(buffer, 0, len);
        }
        jos.closeEntry();
        jos.close();

In my real application I have to deal with more complex streams. In fact, streams are used for CORBA interop. However, data is successfully read. But when I try to do jos.write(buffer, 0, len); no data is written to the output stream that is underlying ZipOutputStream. However, zip file headers, entries comments and central directory are written successfully so I get absolutely valid zip with only one exception that files are empty.

Maybe anyone had seen this behavior before? Any help is appreciated.

EDIT
Here is my real code as it may be useful:

String fileName = fullSourcePath.substring(fullSourcePath.lastIndexOf('\\') + 1, fullSourcePath.length());
WrapperOutputStream out = new WrapperOutputStream(newexchangeStream64);
ZipOutputStream jos = new ZipOutputStream(out);
jos.setLevel(Deflater.NO_COMPRESSION);

jos.putNextEntry(new ZipEntry(fileName));
jos.setComment("Comment");
IDLDataHolder data = new IDLDataHolder();
LongHolder dataAmount = new LongHolder();
LongHolder written = new LongHolder();

while (true) {
    exchangeStream64.Read(data, READ_AMOUNT, dataAmount);
    if (0 == dataAmount.value) {
        break;
    }

    jos.write(data.value, (int)dataAmount.value, (int)written.value);
}
jos.closeEntry();
jos.close();
  • 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-18T04:58:30+00:00Added an answer on May 18, 2026 at 4:58 am
    LongHolder written = new LongHolder();
    
    while (true) {
        exchangeStream64.Read(data, READ_AMOUNT, dataAmount);
        if (0 == dataAmount.value) {
            break;
        }
    
        jos.write(data.value, (int)dataAmount.value, (int)written.value);
    }
    

    It may be just a copy&paste mistake here, but the last parameter of jos.write is always 0. That is the amount of bytes to write from the array.

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

Sidebar

Related Questions

I need a solution that allows me to create compressed data files (gzip, zip.
I need to delete files of a certain type (.zip files, say) from a
I've written some Python code that fetches a zip file from the web and
I have a data set that is generated by a Zip Code range search:
I need to serve some data from my database in a zip file, streaming
I need to compress files in [*.zip] format in .NET 1.1. I don't want
How can I create 7-Zip archives from my C# console application? I need to
I have two strings that I need to pull data out of but can't
I am using the SWFUpload from http://www.anedix.com/data/file/news/realname/swfupload-php-example-v1_4.zip and want to integrate this into my
I'm reading binary data from a file, specifically from a zip file. (To know

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.