Search in sources :

Example 86 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project wire by square.

the class SchemaLoaderTest method failLocateInZipFile.

@Test
public void failLocateInZipFile() throws IOException {
    Files.createDirectories(fileSystem.getPath("/source"));
    Path zip = fileSystem.getPath("/source/protos.zip");
    ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(zip));
    zipOutputStream.putNextEntry(new ZipEntry("a/b/trix.proto"));
    zipOutputStream.write("message Trix {}".getBytes(UTF_8));
    zipOutputStream.close();
    try {
        new SchemaLoader().addSource(zip).addProto("a/b/message.proto").load();
        fail();
    } catch (FileNotFoundException expected) {
    }
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 87 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project wire by square.

the class SchemaLoaderTest method locateInZipFile.

@Test
public void locateInZipFile() throws IOException {
    Files.createDirectories(fileSystem.getPath("/source"));
    Path zip = fileSystem.getPath("/source/protos.zip");
    ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(zip));
    zipOutputStream.putNextEntry(new ZipEntry("a/b/message.proto"));
    zipOutputStream.write("message Message {}".getBytes(UTF_8));
    zipOutputStream.close();
    Schema schema = new SchemaLoader().addSource(zip).addProto("a/b/message.proto").load();
    Type message = schema.getType("Message");
    assertThat(message).isNotNull();
    assertThat(message.location().base()).isEqualTo("/source/protos.zip");
    assertThat(message.location().path()).isEqualTo("a/b/message.proto");
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) Test(org.junit.Test)

Example 88 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project h2o-3 by h2oai.

the class RequestServer method zipLogs.

private static byte[] zipLogs(byte[][] results, byte[] clientResult, String topDir) throws IOException {
    int l = 0;
    assert H2O.CLOUD._memary.length == results.length : "Unexpected change in the cloud!";
    for (byte[] result : results) l += result.length;
    ByteArrayOutputStream baos = new ByteArrayOutputStream(l);
    // Add top-level directory.
    ZipOutputStream zos = new ZipOutputStream(baos);
    {
        ZipEntry zde = new ZipEntry(topDir + File.separator);
        zos.putNextEntry(zde);
    }
    try {
        // Add zip directory from each cloud member.
        for (int i = 0; i < results.length; i++) {
            String filename = topDir + File.separator + "node" + i + "_" + H2O.CLOUD._memary[i].getIpPortString().replace(':', '_').replace('/', '_') + ".zip";
            ZipEntry ze = new ZipEntry(filename);
            zos.putNextEntry(ze);
            zos.write(results[i]);
            zos.closeEntry();
        }
        // Add zip directory from the client node.  Name it 'driver' since that's what Sparking Water users see.
        if (clientResult != null) {
            String filename = topDir + File.separator + "driver.zip";
            ZipEntry ze = new ZipEntry(filename);
            zos.putNextEntry(ze);
            zos.write(clientResult);
            zos.closeEntry();
        }
        // Close the top-level directory.
        zos.closeEntry();
    } finally {
        // Close the full zip file.
        zos.close();
    }
    return baos.toByteArray();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry)

Example 89 with ZipOutputStream

use of java.util.zip.ZipOutputStream in project h2o-2 by h2oai.

the class LogCollectorTask method lcompute.

@Override
public void lcompute() {
    _result = new byte[H2O.CLOUD._memary.length][];
    int idx = H2O.SELF.index();
    baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);
    try {
        zipDir(Log.LOG_DIR, zos);
    } catch (IOException e) {
        H2O.ignore(e);
    } finally {
        try {
            zos.close();
            baos.close();
        } catch (Exception xe) {
        // do nothing
        }
        byte[] arr = baos.toByteArray();
        _result[idx] = arr;
        tryComplete();
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream)

Example 90 with ZipOutputStream

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

the class JavacTurbine method emitClassJar.

/** Write the class output from a successful compilation to the output jar. */
private static void emitClassJar(Path outputJar, ImmutableMap<String, OutputFileObject> files) throws IOException {
    try (OutputStream fos = Files.newOutputStream(outputJar);
        ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(fos, ZIPFILE_BUFFER_SIZE))) {
        for (Map.Entry<String, OutputFileObject> entry : files.entrySet()) {
            if (entry.getValue().location != StandardLocation.CLASS_OUTPUT) {
                continue;
            }
            String name = entry.getKey();
            byte[] bytes = entry.getValue().asBytes();
            if (bytes == null) {
                continue;
            }
            if (name.endsWith(".class")) {
                bytes = processBytecode(bytes);
            }
            ZipUtil.storeEntry(name, bytes, zipOut);
        }
    }
}
Also used : OutputFileObject(com.google.devtools.build.java.turbine.javac.ZipOutputFileManager.OutputFileObject) ZipOutputStream(java.util.zip.ZipOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

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