use of org.codehaus.plexus.archiver.zip.ZipOutputStream in project jib by google.
the class MavenProjectPropertiesTest method zipUpDirectory.
private static Path zipUpDirectory(Path sourceRoot, Path targetZip) throws IOException {
try (ZipOutputStream zipOut = new ZipOutputStream(Files.newOutputStream(targetZip))) {
for (Path source : new DirectoryWalker(sourceRoot).filterRoot().walk()) {
StringJoiner pathJoiner = new StringJoiner("/", "", "");
sourceRoot.relativize(source).forEach(element -> pathJoiner.add(element.toString()));
String zipEntryPath = Files.isDirectory(source) ? pathJoiner.toString() + '/' : pathJoiner.toString();
ZipEntry entry = new ZipEntry(zipEntryPath);
zipOut.putNextEntry(entry);
if (!Files.isDirectory(source)) {
try (InputStream in = Files.newInputStream(source)) {
ByteStreams.copy(in, zipOut);
}
}
zipOut.closeEntry();
}
}
return targetZip;
}
use of org.codehaus.plexus.archiver.zip.ZipOutputStream in project jib by GoogleContainerTools.
the class MavenProjectPropertiesTest method zipUpDirectory.
private static Path zipUpDirectory(Path sourceRoot, Path targetZip) throws IOException {
try (ZipOutputStream zipOut = new ZipOutputStream(Files.newOutputStream(targetZip))) {
for (Path source : new DirectoryWalker(sourceRoot).filterRoot().walk()) {
StringJoiner pathJoiner = new StringJoiner("/", "", "");
sourceRoot.relativize(source).forEach(element -> pathJoiner.add(element.toString()));
String zipEntryPath = Files.isDirectory(source) ? pathJoiner.toString() + '/' : pathJoiner.toString();
ZipEntry entry = new ZipEntry(zipEntryPath);
zipOut.putNextEntry(entry);
if (!Files.isDirectory(source)) {
try (InputStream in = Files.newInputStream(source)) {
ByteStreams.copy(in, zipOut);
}
}
zipOut.closeEntry();
}
}
return targetZip;
}
Aggregations