use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project spring-boot by spring-projects.
the class LayerTests method ofCreatesLayer.
@Test
void ofCreatesLayer() throws Exception {
Layer layer = Layer.of((layout) -> {
layout.directory("/directory", Owner.ROOT);
layout.file("/directory/file", Owner.ROOT, Content.of("test"));
});
assertThat(layer.getId().toString()).isEqualTo("sha256:d03a34f73804698c875eb56ff694fc2fceccc69b645e4adceb004ed13588613b");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
layer.writeTo(outputStream);
try (TarArchiveInputStream tarStream = new TarArchiveInputStream(new ByteArrayInputStream(outputStream.toByteArray()))) {
assertThat(tarStream.getNextTarEntry().getName()).isEqualTo("/directory/");
assertThat(tarStream.getNextTarEntry().getName()).isEqualTo("/directory/file");
assertThat(tarStream.getNextTarEntry()).isNull();
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project spring-boot by spring-projects.
the class TarArchiveTests method ofWritesTarContent.
@Test
void ofWritesTarContent() throws Exception {
Owner owner = Owner.of(123, 456);
TarArchive tarArchive = TarArchive.of((content) -> {
content.directory("/workspace", owner);
content.directory("/layers", owner);
content.directory("/cnb", Owner.ROOT);
content.directory("/cnb/buildpacks", Owner.ROOT);
content.directory("/platform", Owner.ROOT);
content.directory("/platform/env", Owner.ROOT);
});
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
tarArchive.writeTo(outputStream);
try (TarArchiveInputStream tarStream = new TarArchiveInputStream(new ByteArrayInputStream(outputStream.toByteArray()))) {
List<TarArchiveEntry> entries = new ArrayList<>();
TarArchiveEntry entry = tarStream.getNextTarEntry();
while (entry != null) {
entries.add(entry);
entry = tarStream.getNextTarEntry();
}
assertThat(entries).hasSize(6);
assertThat(entries.get(0).getName()).isEqualTo("/workspace/");
assertThat(entries.get(0).getLongUserId()).isEqualTo(123);
assertThat(entries.get(0).getLongGroupId()).isEqualTo(456);
assertThat(entries.get(2).getName()).isEqualTo("/cnb/");
assertThat(entries.get(2).getLongUserId()).isEqualTo(0);
assertThat(entries.get(2).getLongGroupId()).isEqualTo(0);
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project spring-boot by spring-projects.
the class ZipFileTarArchiveTests method writeToAdaptsContent.
@Test
void writeToAdaptsContent() throws Exception {
Owner owner = Owner.of(123, 456);
File file = new File(this.tempDir, "test.zip");
writeTestZip(file);
TarArchive tarArchive = TarArchive.fromZip(file, owner);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
tarArchive.writeTo(outputStream);
try (TarArchiveInputStream tarStream = new TarArchiveInputStream(new ByteArrayInputStream(outputStream.toByteArray()))) {
TarArchiveEntry dirEntry = tarStream.getNextTarEntry();
assertThat(dirEntry.getName()).isEqualTo("spring/");
assertThat(dirEntry.getLongUserId()).isEqualTo(123);
assertThat(dirEntry.getLongGroupId()).isEqualTo(456);
TarArchiveEntry fileEntry = tarStream.getNextTarEntry();
assertThat(fileEntry.getName()).isEqualTo("spring/boot");
assertThat(fileEntry.getLongUserId()).isEqualTo(123);
assertThat(fileEntry.getLongGroupId()).isEqualTo(456);
assertThat(fileEntry.getSize()).isEqualTo(4);
assertThat(fileEntry.getMode()).isEqualTo(0755);
assertThat(tarStream).hasContent("test");
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project spring-boot by spring-projects.
the class BuildpacksTests method assertThatLayerContentIsCorrect.
private void assertThatLayerContentIsCorrect(Layer layer, String path) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
layer.writeTo(out);
try (TarArchiveInputStream tar = new TarArchiveInputStream(new ByteArrayInputStream(out.toByteArray()))) {
assertThat(tar.getNextEntry().getName()).isEqualTo("/cnb/buildpacks/" + path + "/buildpack.toml");
assertThat(tar.getNextEntry()).isNull();
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project spring-boot by spring-projects.
the class EphemeralBuilderTests method getLayer.
private TarArchiveInputStream getLayer(ImageArchive archive, int index) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
archive.writeTo(outputStream);
TarArchiveInputStream tar = new TarArchiveInputStream(new ByteArrayInputStream(outputStream.toByteArray()));
for (int i = 0; i <= index; i++) {
tar.getNextEntry();
}
return new TarArchiveInputStream(tar);
}
Aggregations