use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project flink by splunk.
the class YarnTestArchiveJob method archiveFilesInDirectory.
private static void archiveFilesInDirectory(File directory, String target) throws IOException {
for (Map.Entry<String, String> entry : srcFiles.entrySet()) {
Files.write(Paths.get(directory.getAbsolutePath() + File.separator + entry.getKey()), entry.getValue().getBytes());
}
try (FileOutputStream fos = new FileOutputStream(target);
GzipCompressorOutputStream gos = new GzipCompressorOutputStream(new BufferedOutputStream(fos));
TarArchiveOutputStream taros = new TarArchiveOutputStream(gos)) {
taros.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (File f : directory.listFiles()) {
taros.putArchiveEntry(new TarArchiveEntry(f, directory.getName() + File.separator + f.getName()));
try (FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis)) {
IOUtils.copy(bis, taros);
taros.closeArchiveEntry();
}
}
}
for (Map.Entry<String, String> entry : srcFiles.entrySet()) {
Files.delete(Paths.get(directory.getAbsolutePath() + File.separator + entry.getKey()));
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project vespa by vespa-engine.
the class CompressedFileReference method compress.
public static byte[] compress(File baseDir, List<File> inputFiles) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GZIPOutputStream(out));
archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
createArchiveFile(archiveOutputStream, baseDir, inputFiles);
return out.toByteArray();
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project spring-boot by spring-projects.
the class BootBuildImageIntegrationTests method tarGzipBuildpackContent.
private void tarGzipBuildpackContent() throws IOException {
Path tarGzipPath = Paths.get(this.gradleBuild.getProjectDir().getAbsolutePath(), "hello-world.tgz");
try (TarArchiveOutputStream tar = new TarArchiveOutputStream(new GzipCompressorOutputStream(Files.newOutputStream(Files.createFile(tarGzipPath))))) {
File buildpackDir = new File(this.gradleBuild.getProjectDir(), "buildpack/hello-world");
writeDirectoryToTar(tar, buildpackDir, buildpackDir.getAbsolutePath());
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project spring-boot by spring-projects.
the class ImageBuildpackTests method withMockLayers.
private Object withMockLayers(InvocationOnMock invocation) {
try {
IOBiConsumer<String, TarArchive> consumer = invocation.getArgument(1);
TarArchive archive = (out) -> {
try (TarArchiveOutputStream tarOut = new TarArchiveOutputStream(out)) {
tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
writeTarEntry(tarOut, "/cnb/");
writeTarEntry(tarOut, "/cnb/buildpacks/");
writeTarEntry(tarOut, "/cnb/buildpacks/example_buildpack/");
writeTarEntry(tarOut, "/cnb/buildpacks/example_buildpack/0.0.1/");
writeTarEntry(tarOut, "/cnb/buildpacks/example_buildpack/0.0.1/buildpack.toml");
writeTarEntry(tarOut, "/cnb/buildpacks/example_buildpack/0.0.1/" + this.longFilePath);
tarOut.finish();
}
};
consumer.accept("test", archive);
} catch (IOException ex) {
fail("Error writing mock layers", ex);
}
return null;
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project spring-boot by spring-projects.
the class TarGzipBuildpack method copyAndRebaseEntries.
private void copyAndRebaseEntries(OutputStream outputStream) throws IOException {
String id = this.coordinates.getSanitizedId();
Path basePath = Paths.get("/cnb/buildpacks/", id, this.coordinates.getVersion());
try (TarArchiveInputStream tar = new TarArchiveInputStream(new GzipCompressorInputStream(Files.newInputStream(this.path)));
TarArchiveOutputStream output = new TarArchiveOutputStream(outputStream)) {
writeBasePathEntries(output, basePath);
TarArchiveEntry entry = tar.getNextTarEntry();
while (entry != null) {
entry.setName(basePath + "/" + entry.getName());
output.putArchiveEntry(entry);
StreamUtils.copy(tar, output);
output.closeArchiveEntry();
entry = tar.getNextTarEntry();
}
output.finish();
}
}
Aggregations