Here you can find the source of zipInternal(String path, File file, ZipOutputStream os, boolean justFolders, boolean skipManifest)
private static void zipInternal(String path, File file, ZipOutputStream os, boolean justFolders, boolean skipManifest) throws IOException
//package com.java2s; /******************************************************************************** * Copyright (c) 2011-2017 Red Hat Inc. and/or its affiliates and others * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at * http://www.apache.org/licenses/LICENSE-2.0 * * SPDX-License-Identifier: Apache-2.0 // ww w .ja va2s . co m ********************************************************************************/ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static void zipInternal(String path, File file, ZipOutputStream os, boolean justFolders, boolean skipManifest) throws IOException { String filePath; if (path.isEmpty()) filePath = file.getName(); else filePath = path + "/" + file.getName(); if (file.isDirectory()) { if (justFolders) { if (!filePath.equalsIgnoreCase("META-INF") || !skipManifest) { ZipEntry entry = new ZipEntry(filePath + "/"); os.putNextEntry(entry); os.closeEntry(); } } for (File f : file.listFiles()) zipInternal(filePath, f, os, justFolders, skipManifest); } else if (!justFolders) { if (!filePath.equalsIgnoreCase("META-INF/MANIFEST.MF") || !skipManifest) { ZipEntry entry = new ZipEntry(filePath); os.putNextEntry(entry); try (FileInputStream in = new FileInputStream(file)) { copyStreamNoClose(in, os); } os.closeEntry(); } } } private static void copyStreamNoClose(InputStream in, OutputStream out) throws IOException { final byte[] bytes = new byte[8192]; int cnt; while ((cnt = in.read(bytes)) != -1) { out.write(bytes, 0, cnt); } out.flush(); } }