use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project spring-boot by spring-projects.
the class ImageBuildpackTests method writeTarEntry.
private void writeTarEntry(TarArchiveOutputStream tarOut, String name) throws IOException {
TarArchiveEntry entry = new TarArchiveEntry(name);
tarOut.putArchiveEntry(entry);
tarOut.closeArchiveEntry();
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project spring-boot by spring-projects.
the class ImageBuildpackTests method assertHasExpectedLayers.
private void assertHasExpectedLayers(Buildpack buildpack) throws IOException {
List<ByteArrayOutputStream> layers = new ArrayList<>();
buildpack.apply((layer) -> {
ByteArrayOutputStream out = new ByteArrayOutputStream();
layer.writeTo(out);
layers.add(out);
});
assertThat(layers).hasSize(1);
byte[] content = layers.get(0).toByteArray();
List<TarArchiveEntry> entries = new ArrayList<>();
try (TarArchiveInputStream tar = new TarArchiveInputStream(new ByteArrayInputStream(content))) {
TarArchiveEntry entry = tar.getNextTarEntry();
while (entry != null) {
entries.add(entry);
entry = tar.getNextTarEntry();
}
}
assertThat(entries).extracting("name", "mode").containsExactlyInAnyOrder(tuple("cnb/", TarArchiveEntry.DEFAULT_DIR_MODE), tuple("cnb/buildpacks/", TarArchiveEntry.DEFAULT_DIR_MODE), tuple("cnb/buildpacks/example_buildpack/", TarArchiveEntry.DEFAULT_DIR_MODE), tuple("cnb/buildpacks/example_buildpack/0.0.1/", TarArchiveEntry.DEFAULT_DIR_MODE), tuple("cnb/buildpacks/example_buildpack/0.0.1/buildpack.toml", TarArchiveEntry.DEFAULT_FILE_MODE), tuple("cnb/buildpacks/example_buildpack/0.0.1/" + this.longFilePath, TarArchiveEntry.DEFAULT_FILE_MODE));
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project spring-boot by spring-projects.
the class TestTarGzip method writeEntry.
private void writeEntry(TarArchiveOutputStream tar, String entryName, String content) throws IOException {
TarArchiveEntry entry = new TarArchiveEntry(entryName);
entry.setSize(content.length());
tar.putArchiveEntry(entry);
IOUtils.copy(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), tar);
tar.closeArchiveEntry();
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project crate by crate.
the class SymbolicLinkPreservingUntarTransform method unpack.
public void unpack(File tarFile, File targetDir) throws IOException {
Logging.getLogger(SymbolicLinkPreservingUntarTransform.class).info("Unpacking " + tarFile.getName() + " using " + SymbolicLinkPreservingUntarTransform.class.getSimpleName() + ".");
TarArchiveInputStream tar = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(tarFile)));
final Path destinationPath = targetDir.toPath();
TarArchiveEntry entry = tar.getNextTarEntry();
while (entry != null) {
final Path relativePath = UnpackTransform.trimArchiveExtractPath(entry.getName());
if (relativePath == null) {
entry = tar.getNextTarEntry();
continue;
}
final Path destination = destinationPath.resolve(relativePath);
final Path parent = destination.getParent();
if (Files.exists(parent) == false) {
Files.createDirectories(parent);
}
if (entry.isDirectory()) {
Files.createDirectory(destination);
} else if (entry.isSymbolicLink()) {
Files.createSymbolicLink(destination, Paths.get(entry.getLinkName()));
} else {
// copy the file from the archive using a small buffer to avoid heaping
Files.createFile(destination);
try (FileOutputStream fos = new FileOutputStream(destination.toFile())) {
tar.transferTo(fos);
}
}
if (entry.isSymbolicLink() == false) {
// check if the underlying file system supports POSIX permissions
final PosixFileAttributeView view = Files.getFileAttributeView(destination, PosixFileAttributeView.class);
if (view != null) {
final Set<PosixFilePermission> permissions = PosixFilePermissions.fromString(permissions((entry.getMode() >> 6) & 07) + permissions((entry.getMode() >> 3) & 07) + permissions((entry.getMode() >> 0) & 07));
Files.setPosixFilePermissions(destination, permissions);
}
}
entry = tar.getNextTarEntry();
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project zeppelin by apache.
the class HeliumBundleFactory method unTgz.
private static List<String> unTgz(File tarFile, File directory) throws IOException {
List<String> result = new ArrayList<>();
try (TarArchiveInputStream in = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(tarFile)))) {
TarArchiveEntry entry = in.getNextTarEntry();
while (entry != null) {
if (entry.isDirectory()) {
entry = in.getNextTarEntry();
continue;
}
File curfile = new File(directory, entry.getName());
File parent = curfile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
try (OutputStream out = new FileOutputStream(curfile)) {
IOUtils.copy(in, out);
}
result.add(entry.getName());
entry = in.getNextTarEntry();
}
}
return result;
}
Aggregations