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) {
}
}
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");
}
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();
}
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();
}
}
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);
}
}
}
Aggregations