Search in sources :

Example 81 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project bazel by bazelbuild.

the class SplitZipFiltersTest method createZip.

private File createZip(String... entries) throws FileNotFoundException, IOException {
    File zip = tmp.newFile();
    int count = 0;
    try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zip))) {
        for (String entry : entries) {
            zout.putNextEntry(new ZipEntry(entry));
            // unique content
            zout.write(("contents" + count++).getBytes(UTF_8));
            zout.closeEntry();
        }
    }
    return zip;
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File)

Example 82 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project platform_frameworks_base by android.

the class PackageHelper method extractPublicFiles.

/**
     * Extract public files for the single given APK.
     */
public static long extractPublicFiles(File apkFile, File publicZipFile) throws IOException {
    final FileOutputStream fstr;
    final ZipOutputStream publicZipOutStream;
    if (publicZipFile == null) {
        fstr = null;
        publicZipOutStream = null;
    } else {
        fstr = new FileOutputStream(publicZipFile);
        publicZipOutStream = new ZipOutputStream(fstr);
        Log.d(TAG, "Extracting " + apkFile + " to " + publicZipFile);
    }
    long size = 0L;
    try {
        final ZipFile privateZip = new ZipFile(apkFile.getAbsolutePath());
        try {
            // Copy manifest, resources.arsc and res directory to public zip
            for (final ZipEntry zipEntry : Collections.list(privateZip.entries())) {
                final String zipEntryName = zipEntry.getName();
                if ("AndroidManifest.xml".equals(zipEntryName) || "resources.arsc".equals(zipEntryName) || zipEntryName.startsWith("res/")) {
                    size += zipEntry.getSize();
                    if (publicZipFile != null) {
                        copyZipEntry(zipEntry, privateZip, publicZipOutStream);
                    }
                }
            }
        } finally {
            try {
                privateZip.close();
            } catch (IOException e) {
            }
        }
        if (publicZipFile != null) {
            publicZipOutStream.finish();
            publicZipOutStream.flush();
            FileUtils.sync(fstr);
            publicZipOutStream.close();
            FileUtils.setPermissions(publicZipFile.getAbsolutePath(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1);
        }
    } finally {
        IoUtils.closeQuietly(publicZipOutStream);
    }
    return size;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Example 83 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project gradle by gradle.

the class RuntimeShadedJarCreator method openJarOutputStream.

private ZipOutputStream openJarOutputStream(File outputJar) {
    try {
        ZipOutputStream outputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputJar), BUFFER_SIZE));
        outputStream.setLevel(0);
        return outputStream;
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 84 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project gradle by gradle.

the class RuntimeShadedJarCreator method createFatJar.

private void createFatJar(final File outputJar, final Iterable<? extends File> files, final ProgressLogger progressLogger) {
    final File tmpFile = tempFileFor(outputJar);
    IoActions.withResource(openJarOutputStream(tmpFile), new ErroringAction<ZipOutputStream>() {

        @Override
        protected void doExecute(ZipOutputStream jarOutputStream) throws Exception {
            processFiles(jarOutputStream, files, new byte[BUFFER_SIZE], new HashSet<String>(), new LinkedHashMap<String, List<String>>(), progressLogger);
            jarOutputStream.finish();
        }
    });
    GFileUtils.moveFile(tmpFile, outputJar);
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) File(java.io.File) UncheckedException(org.gradle.internal.UncheckedException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap)

Example 85 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project j2objc by google.

the class ZipEntryTest method testMaxLengthExtra_zip64.

public void testMaxLengthExtra_zip64() throws Exception {
    // Not quite the max length (65535), but large enough that there's no space
    // for the zip64 extended info header.
    byte[] maxLengthExtra = new byte[65530];
    File f = createTemporaryZipFile();
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f)), true);
    ZipEntry ze = new ZipEntry("x");
    ze.setExtra(maxLengthExtra);
    try {
        out.putNextEntry(ze);
        fail();
    } catch (ZipException expected) {
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) ZipFile(java.util.zip.ZipFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

ZipOutputStream (java.util.zip.ZipOutputStream)1168 ZipEntry (java.util.zip.ZipEntry)745 FileOutputStream (java.io.FileOutputStream)561 File (java.io.File)486 IOException (java.io.IOException)393 FileInputStream (java.io.FileInputStream)193 ByteArrayOutputStream (java.io.ByteArrayOutputStream)186 BufferedOutputStream (java.io.BufferedOutputStream)177 ZipFile (java.util.zip.ZipFile)163 InputStream (java.io.InputStream)144 Test (org.junit.Test)128 OutputStream (java.io.OutputStream)109 ByteArrayInputStream (java.io.ByteArrayInputStream)94 ZipInputStream (java.util.zip.ZipInputStream)88 Path (java.nio.file.Path)82 BufferedInputStream (java.io.BufferedInputStream)61 ArrayList (java.util.ArrayList)55 FileNotFoundException (java.io.FileNotFoundException)51 Date (java.util.Date)44 HashMap (java.util.HashMap)44