Search in sources :

Example 91 with ZipOutputStream

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

the class AndroidResourceOutputs method createSrcJar.

/** Creates a zip archive from all found R.java files. */
public static void createSrcJar(Path generatedSourcesRoot, Path srcJar, boolean staticIds) {
    try {
        Files.createDirectories(srcJar.getParent());
        try (final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(srcJar)))) {
            SymbolFileSrcJarBuildingVisitor visitor = new SymbolFileSrcJarBuildingVisitor(zip, generatedSourcesRoot, staticIds);
            Files.walkFileTree(generatedSourcesRoot, visitor);
            visitor.writeEntries();
        }
        // Set to the epoch for caching purposes.
        Files.setLastModifiedTime(srcJar, FileTime.fromMillis(0L));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 92 with ZipOutputStream

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

the class AndroidResourceOutputs method createClassJar.

/** Creates a zip archive from all found R.class (and inner class) files. */
public static void createClassJar(Path generatedClassesRoot, Path classJar) {
    try {
        Files.createDirectories(classJar.getParent());
        try (final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(classJar)))) {
            ClassJarBuildingVisitor visitor = new ClassJarBuildingVisitor(zip, generatedClassesRoot);
            Files.walkFileTree(generatedClassesRoot, visitor);
            visitor.writeEntries();
            visitor.writeManifestContent();
        }
        // Set to the epoch for caching purposes.
        Files.setLastModifiedTime(classJar, FileTime.fromMillis(0L));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 93 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project buck by facebook.

the class CustomZipEntryTest method writeSimpleJarAndGetHash.

private HashCode writeSimpleJarAndGetHash() throws Exception {
    Path output = Files.createTempFile("example", ".jar");
    try (FileOutputStream fileOutputStream = new FileOutputStream(output.toFile());
        ZipOutputStream out = new JarOutputStream(fileOutputStream)) {
        ZipEntry entry = new CustomZipEntry("test");
        out.putNextEntry(entry);
        out.write(new byte[0]);
        entry = new ZipEntry("test1");
        entry.setTime(ZipConstants.getFakeTime());
        out.putNextEntry(entry);
        out.write(new byte[0]);
    }
    return Hashing.sha1().hashBytes(Files.readAllBytes(output));
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream)

Example 94 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project buck by facebook.

the class RepackZipEntriesStepTest method buildSampleZipFile.

@Before
public void buildSampleZipFile() throws IOException {
    parent = tmp.newFolder("foo");
    filesystem = new ProjectFilesystem(parent);
    zipFile = parent.resolve("example.zip");
    // Since we've modeled our outputstreams after the zip output stream, be compatible with that.
    try (ZipOutputStream stream = new ZipOutputStream(Files.newOutputStream(zipFile))) {
        ZipEntry entry = new ZipEntry("file");
        stream.putNextEntry(entry);
        String packageName = getClass().getPackage().getName().replace(".", "/");
        URL sample = Resources.getResource(packageName + "/sample-bytes.properties");
        stream.write(Resources.toByteArray(sample));
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) URL(java.net.URL) Before(org.junit.Before)

Example 95 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project translationstudio8 by heartsome.

the class ZipUtil method zipFolder.

/**
	 * 压缩文件夹
	 * @param zipPath
	 *            生成的zip文件路径
	 * @param filePath
	 *            需要压缩的文件夹路径
	 * @throws Exception
	 */
public static void zipFolder(String zipPath, String filePath) throws IOException {
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipPath));
    File f = new File(filePath);
    zipFiles(out, f, "");
    out.close();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

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