Inserting already deflated files in a zip file


I have been searching for this issue but I cannot find any response that I can use.

Is it possible (using java) to include new files that are already deflated in a zip file in a way that, after, when I decompress the zip file, those deflated files are inflated in the same way as if they were passed “inflated” to the zip tool and incorporated to the zip as to be compressed (“DEFLETED” in the ZipEntry according to In that case, how?

Most of the information about compression with java for zip files I get from google and others searchers can be resumed in:

I deflect the files using JZlib (but you can do with whatever any other library. An example,

As you can expect about what I said, when I try to insert the already deflated files, they are deflated again (using the DEFLETED method in the ZipEntry, that is the default) and when the zip file is unzipped, the files are deflated to the their former already deflated state.

Looking to the source of from oracle, you can see that there are two methods for adding entries to the zip:

    DEFLATED (an integer set to 20)
    STORED   (an integer set to 10)

What I want is to add the deflated entries as STORED in the zip, but once they are added, to change the info in the own zip as if they were processed DEFLATED. Do you know any library or any alternative to do it easily? I was thinking in making my own ZipOutputStream inheriting from the jdk ZipOutputStream and overriding the methods to make the trick, but a “fast copy-paste and modification” of the methods according to this idea -just to have a “it could work” feeling- did not work according to my hopes either.

The reason why I would like to have this option is to compress huge amount of files in a zip file on demand dynamically. I am not sure if this could save time and cpu having the deflated files saved in the database and selecting in each moment those files that are requested to make the zips.

Thanks a lot,


Need Help? Chat with us