2

I am using the following method to filter out META-INF folder and its contents:

public static void copyWithoutMetaInf(final String originalZip, final String newZip) throws IOException
{
    final ZipInputStream zip = new ZipInputStream(new FileInputStream(originalZip));
    final ZipOutputStream zop = new ZipOutputStream(new FileOutputStream(newZip));
    ZipEntry entry;
    while((entry = zip.getNextEntry()) != null)
    {
        if(!entry.getName().contains("META-INF"))
        {
            zop.putNextEntry(entry);
        }
    }
    zip.close();
    zop.close();
}

Method found here: https://stackoverflow.com/a/22433569/3952266

The only problem is that when it creates the new file it only outputs a file a tenth of the original size.

Community
  • 1
  • 1
Hugh Macdonald
  • 143
  • 1
  • 12
  • How is reduced file size a problem (as long as all files outside of META-INF are still present)? Or are you saying that each file in the jar is truncated? – Thilo Jun 16 '15 at 05:17
  • Does this method work actually? It seems `putNextEntry` only creates the metadata, you still need to `write` the file contents. – Thilo Jun 16 '15 at 05:22
  • Maybe this helps: http://stackoverflow.com/questions/11692430/is-there-a-platform-independent-way-to-programmatically-remove-a-file-from-a-zip?rq=1 – Thilo Jun 16 '15 at 05:24
  • I'll take a look thanks. – Hugh Macdonald Jun 16 '15 at 05:26

0 Answers0