org.apache.tools.zip.ZipOutputStream Java Examples

The following examples show how to use org.apache.tools.zip.ZipOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AntJarProcessor.java    From jarjar with Apache License 2.0 6 votes vote down vote up
protected void zipFile(
    InputStream is,
    ZipOutputStream zOut,
    String vPath,
    long lastModified,
    File fromArchive,
    int mode)
    throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  IoUtil.pipe(is, baos, buf);
  struct.data = baos.toByteArray();
  struct.name = vPath;
  struct.time = lastModified;
  if (proc.process(struct)) {
    if (mode == 0) {
      mode = ZipFileSet.DEFAULT_FILE_MODE;
    }
    if (!filesOnly) {
      addParentDirs(struct.name, zOut);
    }
    super.zipFile(
        new ByteArrayInputStream(struct.data), zOut, struct.name, struct.time, fromArchive, mode);
  }
}
 
Example #2
Source File: Files.java    From development with Apache License 2.0 6 votes vote down vote up
public void writeTo(OutputStream out) throws IOException {
    final Set<String> filenames = new HashSet<String>();
    final ZipOutputStream zipout = new ZipOutputStream(out);
    for (IFile f : container.getFiles()) {
        assertNoAbsolutePath(f);
        assertNoDuplicates(filenames, f);
        ZipEntry entry = new ZipEntry(f.getLocalPath());
        entry.setTime(f.getLastModified());
        if (f.getPermissions() != IFile.UNDEF_PERMISSIONS) {
            entry.setUnixMode(f.getPermissions());
        }
        zipout.putNextEntry(entry);
        f.writeTo(zipout);
        zipout.closeEntry();
    }
    zipout.finish();
}
 
Example #3
Source File: JarVersionCreator.java    From gs-xsd2bean with Apache License 2.0 6 votes vote down vote up
@Override
protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode) throws IOException
{
    if (vPath.startsWith("META-INF/"))
    {
        if (!vPath.equals("META-INF/"+applicationName+".crcver"))
        {
            super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode);
        }
    }
    else
    {
        crcInputStream.resetStream(is);
        super.zipFile(crcInputStream, zOut, vPath, lastModified, fromArchive, mode);
        fileChecksums.add(new FileChecksum(vPath, crcInputStream.getCrcValue()));
    }

}
 
Example #4
Source File: MigrateForm.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * 压缩
 * 
 * @param zos
 *            压缩输出流
 * @param relativePath
 *            相对路径
 * @param absolutPath
 *            文件或文件夹绝对路径
 * @throws IOException
 */
private static void zip(ZipOutputStream zos, String relativePath, String absolutPath) throws IOException {
	File file = new File(absolutPath);
	if (file.isDirectory()) {
		File[] files = file.listFiles();
		for (int i = 0; i < files.length; i++) {
			File tempFile = files[i];
			if (tempFile.isDirectory()) {
				String newRelativePath = relativePath + tempFile.getName() + File.separator;
				createZipNode(zos, newRelativePath);
				zip(zos, newRelativePath, tempFile.getPath());
			} else {
				zipFile(zos, tempFile, relativePath);
			}
		}
	} else {
		zipFile(zos, file, relativePath);
	}
}
 
Example #5
Source File: ExtractionToolsTest.java    From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 6 votes vote down vote up
@Test
public void canDecompressZipFile() {
    try {
        compressedFile = Files.createTempFile(ARCHIVE_PREFIX, ".zip");
        try (final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(
                    new BufferedOutputStream(new FileOutputStream(compressedFile.toFile())))) {
            // Deflated is the default compression method
            zipDirectory(testDir, outputStream, ZipOutputStream.DEFLATED);
        }

        ExtractionTools.decompressFile(
                compressedFile.toFile(),
                decompressDestination.toFile(),
                CompressionType.Zip,
                null);

        assertEquals(getFileNames(testDir), getFileNames(decompressDestination));
    } catch (final IOException e) {
        fail(e.getMessage());
    }
}
 
Example #6
Source File: ExtractionToolsTest.java    From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 6 votes vote down vote up
@Test
public void canDecompressZipFileWithStoredCompressionMethod() {
    try {
        compressedFile = Files.createTempFile(ARCHIVE_PREFIX, ".zip");
        try (final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(
                    new BufferedOutputStream(new FileOutputStream(compressedFile.toFile())))) {
            zipDirectory(testDir, outputStream, ZipOutputStream.STORED);
        }

        ExtractionTools.decompressFile(
                compressedFile.toFile(),
                decompressDestination.toFile(),
                CompressionType.Zip,
                null);

        assertEquals(getFileNames(testDir), getFileNames(decompressDestination));
    } catch (final IOException e) {
        fail(e.getMessage());
    }
}
 
Example #7
Source File: JarVersionCreator.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode) throws IOException
{
    if (vPath.startsWith("META-INF/"))
    {
        if (!vPath.equals("META-INF/"+applicationName+".crcver"))
        {
            super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode);
        }
    }
    else
    {
        crcInputStream.resetStream(is);
        super.zipFile(crcInputStream, zOut, vPath, lastModified, fromArchive, mode);
        fileChecksums.add(new FileChecksum(vPath, crcInputStream.getCrcValue()));
    }

}
 
Example #8
Source File: ZipUtils.java    From joylau-springboot-daemon-windows with MIT License 6 votes vote down vote up
/**
 * <p>
 * 压缩文件
 * </p>
 *
 * @param sourceFolder 压缩文件夹
 * @param zipFilePath 压缩文件输出路径
 */
public static void zip(String sourceFolder, String zipFilePath) throws Exception {
    OutputStream out = new FileOutputStream(zipFilePath);
    BufferedOutputStream bos = new BufferedOutputStream(out);
    ZipOutputStream zos = new ZipOutputStream(bos);
    // 解决中文文件名乱码
    zos.setEncoding(CHINESE_CHARSET);
    File file = new File(sourceFolder);
    String basePath = null;
    if (file.isDirectory()) {
        basePath = file.getPath();
    } else {
        basePath = file.getParent();
    }
    zipFile(file, basePath, zos);
    zos.closeEntry();
    zos.close();
    bos.close();
    out.close();
}
 
Example #9
Source File: CslJar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void zipFile(File file, ZipOutputStream zOut, String vPath, int mode) throws IOException {
    if (vPath.equals(layer)) {
        System.setProperty("CslJar", Boolean.TRUE.toString());
        try {
            // Create a tempfile and trick it!
            InputStream is = new FileInputStream(file);
            String modifiedLayer = getModifiedLayer(is);
            if (modifiedLayer != null) {
                File tmpFile = File.createTempFile("csl", "tmp"); // NOI18N
                BufferedWriter w = new BufferedWriter(new FileWriter(tmpFile));
                w.write(modifiedLayer);
                w.flush();
                w.close();
                // Note - we're passing the temp file instead of the "real" layer file
                super.zipFile(tmpFile, zOut, vPath, mode);
                // Remove the tmpfile
                tmpFile.delete();
                return;
            }
        } finally {
            System.setProperty("CslJar", Boolean.FALSE.toString());
        }
    }
    super.zipFile(file, zOut, vPath, mode);
}
 
Example #10
Source File: AntJarProcessor.java    From jarjar with Apache License 2.0 6 votes vote down vote up
protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath,
                                 long lastModified, File fromArchive, int mode) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IoUtil.pipe(is, baos, buf);
    struct.data = baos.toByteArray();
    struct.name = vPath;
    struct.time = lastModified;
    if (proc.process(struct)) {
        if (mode == 0)
            mode = ZipFileSet.DEFAULT_FILE_MODE;
        if (!filesOnly) {
          addParentDirs(struct.name, zOut);
        }
        super.zipFile(new ByteArrayInputStream(struct.data),
                      zOut, struct.name, struct.time, fromArchive, mode);
    }
}
 
Example #11
Source File: ZipUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public static void zip(String path, List<File> files) throws IOException {
	ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(   
			new FileOutputStream(path), 1024));   
	for(File f : files) {
		String zipName = f.getName();
		if(!f.getName().contains(".png")) { 
			zipName = f.getName() + ".xml"; 
		}
		ZipEntry ze = new ZipEntry(zipName);
		ze.setTime(f.lastModified());
	    DataInputStream dis = new DataInputStream(new BufferedInputStream(   
	                new FileInputStream(f)));   
        zos.putNextEntry(ze);   
        int c;   
        while ((c = dis.read()) != -1) {   
            zos.write(c);   
        }   
	}
	zos.setEncoding("gbk");    
       zos.closeEntry();   
       zos.close();  
}
 
Example #12
Source File: AntJarProcessor.java    From bazel with Apache License 2.0 6 votes vote down vote up
protected void zipFile(
    InputStream is,
    ZipOutputStream zOut,
    String vPath,
    long lastModified,
    File fromArchive,
    int mode)
    throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  IoUtil.pipe(is, baos, buf);
  struct.data = baos.toByteArray();
  struct.name = vPath;
  struct.time = lastModified;
  if (proc.process(struct)) {
    if (mode == 0) {
      mode = ZipFileSet.DEFAULT_FILE_MODE;
    }
    if (!filesOnly) {
      addParentDirs(struct.name, zOut);
    }
    super.zipFile(
        new ByteArrayInputStream(struct.data), zOut, struct.name, struct.time, fromArchive, mode);
  }
}
 
Example #13
Source File: MigrateForm.java    From jeecg with Apache License 2.0 6 votes vote down vote up
/**
 * 压缩
 * 
 * @param zos
 *            压缩输出流
 * @param relativePath
 *            相对路径
 * @param absolutPath
 *            文件或文件夹绝对路径
 * @throws IOException
 */
private static void zip(ZipOutputStream zos, String relativePath, String absolutPath) throws IOException {
	File file = new File(absolutPath);
	if (file.isDirectory()) {
		File[] files = file.listFiles();
		for (int i = 0; i < files.length; i++) {
			File tempFile = files[i];
			if (tempFile.isDirectory()) {
				String newRelativePath = relativePath + tempFile.getName() + File.separator;
				createZipNode(zos, newRelativePath);
				zip(zos, newRelativePath, tempFile.getPath());
			} else {
				zipFile(zos, tempFile, relativePath);
			}
		}
	} else {
		zipFile(zos, file, relativePath);
	}
}
 
Example #14
Source File: DefaultZipCompressor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ZipOutputStream createArchiveOutputStream(File destination) {
    try {
        ZipOutputStream outStream = new ZipOutputStream(destination);
        outStream.setUseZip64(zip64Mode);
        outStream.setMethod(entryCompressionMethod);
        return outStream;
    } catch (Exception e) {
        String message = String.format("Unable to create ZIP output stream for file %s.", destination);
        throw new UncheckedIOException(message, e);
    }
}
 
Example #15
Source File: Zip.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ZipCompressor getCompressor() {
    switch (entryCompression) {
        case DEFLATED:
            return new DefaultZipCompressor(allowZip64, ZipOutputStream.DEFLATED);
        case STORED:
            return new DefaultZipCompressor(allowZip64, ZipOutputStream.STORED);
        default:
            throw new IllegalArgumentException(String.format("Unknown Compression type %s", entryCompression));
    }
}
 
Example #16
Source File: FileUtils.java    From frpMgr with MIT License 5 votes vote down vote up
/**
 * 压缩文件或目录
 * @param srcDirName 压缩的根目录
 * @param fileName 根目录下的待压缩的文件名或文件夹名,其中*或""表示跟目录下的全部文件
 * @param descFileName 目标zip文件
 */
public static void zipFiles(String srcDirName, String fileName,
		String descFileName) {
	// 判断目录是否存在
	if (srcDirName == null) {
		logger.debug("文件压缩失败,目录 " + srcDirName + " 不存在!");
		return;
	}
	File fileDir = new File(srcDirName);
	if (!fileDir.exists() || !fileDir.isDirectory()) {
		logger.debug("文件压缩失败,目录 " + srcDirName + " 不存在!");
		return;
	}
	String dirPath = fileDir.getAbsolutePath();
	File descFile = new File(descFileName);
	try {
		ZipOutputStream zouts = new ZipOutputStream(new FileOutputStream(
				descFile));
		if ("*".equals(fileName) || "".equals(fileName)) {
			FileUtils.zipDirectoryToZipFile(dirPath, fileDir, zouts);
		} else {
			File file = new File(fileDir, fileName);
			if (file.isFile()) {
				FileUtils.zipFilesToZipFile(dirPath, file, zouts);
			} else {
				FileUtils
						.zipDirectoryToZipFile(dirPath, file, zouts);
			}
		}
		zouts.close();
		logger.debug(descFileName + " 文件压缩成功!");
	} catch (Exception e) {
		logger.debug("文件压缩失败:" + e.getMessage());
		e.printStackTrace();
	}

}
 
Example #17
Source File: DefaultZipCompressor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ZipOutputStream createArchiveOutputStream(File destination) {
    try {
        ZipOutputStream outStream = new ZipOutputStream(destination);
        outStream.setUseZip64(zip64Mode);
        outStream.setMethod(entryCompressionMethod);
        return outStream;
    } catch (Exception e) {
        String message = String.format("Unable to create ZIP output stream for file %s.", destination);
        throw new UncheckedIOException(message, e);
    }
}
 
Example #18
Source File: AntJarProcessor.java    From jarjar with Apache License 2.0 5 votes vote down vote up
private void addParentDirs(String file, ZipOutputStream zOut) throws IOException {
  int slash = file.lastIndexOf('/');
  if (slash >= 0) {
    String dir = file.substring(0, slash);
    if (dirs.add(dir)) {
      addParentDirs(dir, zOut);
      super.zipDir((File) null, zOut, dir + "/", ZipFileSet.DEFAULT_DIR_MODE, JAR_MARKER);
    }
  }
}
 
Example #19
Source File: Zip.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ZipCompressor getCompressor() {
    switch (entryCompression) {
        case DEFLATED:
            return new DefaultZipCompressor(allowZip64, ZipOutputStream.DEFLATED);
        case STORED:
            return new DefaultZipCompressor(allowZip64, ZipOutputStream.STORED);
        default:
            throw new IllegalArgumentException(String.format("Unknown Compression type %s", entryCompression));
    }
}
 
Example #20
Source File: ExtractionToolsTest.java    From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 5 votes vote down vote up
private static void zipDirectory(
        final Path directory,
        final ZipArchiveOutputStream out,
        final int compressionMethod) throws IOException {

    Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
            final String entryName = directory.relativize(file).toString();
            final ZipArchiveEntry archiveEntry = new ZipArchiveEntry(file.toFile(), entryName);
            final byte[] contents = Files.readAllBytes(file);

            out.setMethod(compressionMethod);
            archiveEntry.setMethod(compressionMethod);

            if (compressionMethod == ZipOutputStream.STORED) {
                archiveEntry.setSize(contents.length);

                final CRC32 crc32 = new CRC32();
                crc32.update(contents);
                archiveEntry.setCrc(crc32.getValue());
            }

            out.putArchiveEntry(archiveEntry);
            out.write(contents);
            out.closeArchiveEntry();

            return FileVisitResult.CONTINUE;
        }
    });
}
 
Example #21
Source File: AntJarProcessor.java    From bazel with Apache License 2.0 5 votes vote down vote up
private void addParentDirs(String file, ZipOutputStream zOut) throws IOException {
  int slash = file.lastIndexOf('/');
  if (slash >= 0) {
    String dir = file.substring(0, slash);
    if (dirs.add(dir)) {
      addParentDirs(dir, zOut);
      super.zipDir((File) null, zOut, dir + "/", ZipFileSet.DEFAULT_DIR_MODE, JAR_MARKER);
    }
  }
}
 
Example #22
Source File: Zipper.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 创建Zipper对象
 * 
 * @param out
 *            输出流
 * @param filter
 *            文件过滤,不过滤可以为null。
 * @param srcFilename
 *            源文件名。可以有多个源文件,如果源文件是目录,那么所有子目录都将被包含。
 */
protected Zipper(OutputStream out, List<FileEntry> fileEntrys,
		String encoding) {
	Assert.notEmpty(fileEntrys);
	long begin = System.currentTimeMillis();
	log.debug("开始制作压缩包");
	try {
		try {
			zipOut = new ZipOutputStream(out);
			if (!StringUtils.isBlank(encoding)) {
				log.debug("using encoding: {}", encoding);
				zipOut.setEncoding(encoding);
			} else {
				log.debug("using default encoding");
			}
			for (FileEntry fe : fileEntrys) {
				zip(fe.getFile(), fe.getFilter(), fe.getZipEntry(), fe
						.getPrefix());
			}
		} finally {
			zipOut.close();
		}
	} catch (IOException e) {
		throw new RuntimeException("制作压缩包时,出现IO异常!", e);
	}
	long end = System.currentTimeMillis();
	log.info("制作压缩包成功。耗时:{}ms。", end - begin);
}
 
Example #23
Source File: HttpDownHandler.java    From AndroidWebServ with Apache License 2.0 5 votes vote down vote up
/** 递归压缩文件进zip文件流 */
private void zip(ZipOutputStream zos, File file, String base) throws IOException {
    if (file.isDirectory()) { // 目录时
        File[] files = file.listFiles();
        if (null != files && files.length > 0) {
            for (File f : files) {
                zip(zos, f, base + "/" + f.getName()); // 递归
            }
        } else {
            zos.putNextEntry(new ZipEntry(base + "/")); // 加入目录条目
            zos.closeEntry();
        }
    } else {
        zos.putNextEntry(new ZipEntry(base)); // 加入文件条目
        FileInputStream fis = new FileInputStream(file); // 创建文件输入流
        try {
            int count; // 读取计数
            byte[] buffer = new byte[Config.BUFFER_LENGTH]; // 缓冲字节数组
            /* 写入zip输出流 */
            while ((count = fis.read(buffer)) != -1) {
                zos.write(buffer, 0, count);
            }
        } finally {
            zos.flush();
            zos.closeEntry();
            fis.close();
        }
    }
}
 
Example #24
Source File: MigrateForm.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 压缩
 * 
 * @param zipFileName
 *            压缩产生的zip包文件名--带路径,如果为null或空则默认按文件名生产压缩文件名
 * @param relativePath
 *            相对路径,默认为空
 * @param directory
 *            文件或目录的绝对路径
 * @throws FileNotFoundException
 * @throws IOException
 */
public static String zip(String zipFileName, String relativePath, String directory) throws FileNotFoundException, IOException {
	String fileName = zipFileName;
	if (fileName == null || fileName.trim().equals("")) {
		File temp = new File(directory);
		if (temp.isDirectory()) {
			fileName = directory + ".zip";
		} else {
			if (directory.indexOf(".") > 0) {
				fileName = directory.substring(0, directory.lastIndexOf(".")) + ".zip";
			} else {
				fileName = directory + ".zip";
			}
		}
	}
	ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(fileName));
	try {
		zip(zos, relativePath, directory);
	} catch (IOException ex) {
		throw ex;
	} finally {
		if (null != zos) {
			zos.close();
		}
	}
	return fileName;
}
 
Example #25
Source File: MigrateForm.java    From jeecg with Apache License 2.0 5 votes vote down vote up
/**
 * 压缩
 * 
 * @param zipFileName
 *            压缩产生的zip包文件名--带路径,如果为null或空则默认按文件名生产压缩文件名
 * @param relativePath
 *            相对路径,默认为空
 * @param directory
 *            文件或目录的绝对路径
 * @throws FileNotFoundException
 * @throws IOException
 */
public static String zip(String zipFileName, String relativePath, String directory) throws FileNotFoundException, IOException {
	String fileName = zipFileName;
	if (fileName == null || fileName.trim().equals("")) {
		File temp = new File(directory);
		if (temp.isDirectory()) {
			fileName = directory + ".zip";
		} else {
			if (directory.indexOf(".") > 0) {
				fileName = directory.substring(0, directory.lastIndexOf(".")) + ".zip";
			} else {
				fileName = directory + ".zip";
			}
		}
	}
	ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(fileName));
	try {
		zip(zos, relativePath, directory);
	} catch (IOException ex) {
		throw ex;
	} finally {
		if (null != zos) {
			zos.close();
		}
	}
	return fileName;
}
 
Example #26
Source File: JarVersionCreator.java    From gs-xsd2bean with Apache License 2.0 5 votes vote down vote up
private void createVersionInfo(ZipOutputStream zOut) throws IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(baos, "UTF8"));

    CRC32 fullCrc = new CRC32();
    // header
    writer.print("name: ");
    writer.println(applicationName);
    writer.print("version: ");
    writer.println(this.version);

    fullCrc.update(applicationName.getBytes("UTF8"));
    fullCrc.update(version.getBytes("UTF8"));

    writeVersionInfo(writer, fullCrc);
    writer.println();
    writer.print(":crc: ");
    writer.println(Long.toHexString(fullCrc.getValue()));
    
    if (writer.checkError())
    {
        throw new IOException("Encountered an error writing jar version information");
    }
    writer.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    super.zipFile(bais, zOut, "META-INF/"+applicationName+".crcver", System.currentTimeMillis(), null, ZipFileSet.DEFAULT_FILE_MODE);
    bais.close();
}
 
Example #27
Source File: DefaultZipCompressor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ZipOutputStream createArchiveOutputStream(File destination) {
    try {
        ZipOutputStream outStream = new ZipOutputStream(destination);
        outStream.setUseZip64(zip64Mode);
        outStream.setMethod(entryCompressionMethod);
        return outStream;
    } catch (Exception e) {
        String message = String.format("Unable to create ZIP output stream for file %s.", destination);
        throw new UncheckedIOException(message, e);
    }
}
 
Example #28
Source File: Zip.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ZipCompressor getCompressor() {
    switch (entryCompression) {
        case DEFLATED:
            return new DefaultZipCompressor(allowZip64, ZipOutputStream.DEFLATED);
        case STORED:
            return new DefaultZipCompressor(allowZip64, ZipOutputStream.STORED);
        default:
            throw new IllegalArgumentException(String.format("Unknown Compression type %s", entryCompression));
    }
}
 
Example #29
Source File: DefaultZipCompressor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ZipOutputStream createArchiveOutputStream(File destination) {
    try {
        ZipOutputStream outStream = new ZipOutputStream(destination);
        outStream.setUseZip64(zip64Mode);
        outStream.setMethod(entryCompressionMethod);
        return outStream;
    } catch (Exception e) {
        String message = String.format("Unable to create ZIP output stream for file %s.", destination);
        throw new UncheckedIOException(message, e);
    }
}
 
Example #30
Source File: AntJarProcessor.java    From jarjar with Apache License 2.0 5 votes vote down vote up
private void addParentDirs(String file, ZipOutputStream zOut) throws IOException {
  int slash = file.lastIndexOf('/');
  if (slash >= 0) {
    String dir = file.substring(0, slash);
    if (dirs.add(dir)) {
      addParentDirs(dir, zOut);
      super.zipDir((File) null, zOut, dir + "/", ZipFileSet.DEFAULT_DIR_MODE, JAR_MARKER);
    }
  }
}