Search in sources :

Example 1 with ZipOutputStream

use of org.apache.tools.zip.ZipOutputStream in project hive by apache.

the class CompressionUtils method zip.

public static void zip(String parentDir, String[] inputFiles, String outputFile) throws IOException {
    ZipOutputStream output = null;
    try {
        output = new ZipOutputStream(new FileOutputStream(new File(parentDir, outputFile)));
        for (int i = 0; i < inputFiles.length; i++) {
            File f = new File(parentDir, inputFiles[i]);
            FileInputStream input = new FileInputStream(f);
            output.putNextEntry(new ZipEntry(inputFiles[i]));
            try {
                IOUtils.copy(input, output);
            } finally {
                input.close();
            }
        }
    } finally {
        org.apache.hadoop.io.IOUtils.closeStream(output);
    }
}
Also used : ZipOutputStream(org.apache.tools.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(org.apache.tools.zip.ZipEntry) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with ZipOutputStream

use of org.apache.tools.zip.ZipOutputStream in project gradle by gradle.

the class DefaultZipCompressor method createArchiveOutputStream.

public ZipOutputStream createArchiveOutputStream(File destination) throws IOException {
    ZipOutputStream outStream = new ZipOutputStream(destination);
    try {
        outStream.setUseZip64(zip64Mode);
        outStream.setMethod(entryCompressionMethod);
        return outStream;
    } catch (Exception e) {
        IOUtils.closeQuietly(outStream);
        String message = String.format("Unable to create ZIP output stream for file %s.", destination);
        throw new UncheckedIOException(message, e);
    }
}
Also used : ZipOutputStream(org.apache.tools.zip.ZipOutputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Aggregations

ZipOutputStream (org.apache.tools.zip.ZipOutputStream)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ZipEntry (org.apache.tools.zip.ZipEntry)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1