/** * Zips the contents of a given directory. The output ZIP file, by default, is created in the * given directory, and its name is the given directory name with 'zip' extension. * * @param dir2zip * The given directory to be zipped. * @return The output ZIP file. * @throws IOException * If any I/O exception occurred. */ public static File zipDirectory(File dir2zip) throws IOException { // construct zipped file path String zipFileName = dir2zip.getName() + ".zip"; File zipFile = new File(dir2zip, zipFileName); return zipDirectory(dir2zip, zipFile); }
/** * Zips the contents of a given directory to a given output ZIP file. * * @param dir2zip * The given directory to be zipped. * @param zippedFile * The given output ZIP file. * @return The output ZIP file. * @throws IOException * If any I/O exception occurred. */ public static File zipDirectory(File dir2zip, File zippedFile) throws IOException { ZipOutputStream zoStream = null; try { // open compressed output stream zoStream = new ZipOutputStream(new FileOutputStream(zippedFile)); // add output zip file to exclusions File[] excludeFiles = new File[1]; excludeFiles[0] = zippedFile; zipDirectory(dir2zip, zoStream, dir2zip, excludeFiles); } finally { if (zoStream != null) { try { zoStream.close(); } catch (Exception e) { } } } return zippedFile; }
zipDirectory(entry, zoStream, referenceDir, excludeFiles);
logInfoMessage(_outAggInstDesc.toString()); File outPearFile = FileUtil.zipDirectory(_outAggRootDir, _outAggPearFile); logInfoMessage("[" + PEAR_MERGER + "]: " + "created output aggregate PEAR file - " + outPearFile.getAbsolutePath());