use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method readEmptyArchiveFromStreamWithoutMarkSupport.
@Test
public void readEmptyArchiveFromStreamWithoutMarkSupport() throws IOException {
byte[] emptyTar;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(baos)) {
tarOutput.finish();
emptyTar = baos.toByteArray();
}
ImageArchiveManifest manifest = ImageArchiveUtil.readManifest(new ByteArrayInputStream(emptyTar) {
public boolean markSupported() {
return false;
}
});
Assert.assertNull(manifest);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method readInvalidJsonInArchive.
@Test
public void readInvalidJsonInArchive() throws IOException {
byte[] archiveBytes;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(baos)) {
final byte[] entryData = ("}" + UUID.randomUUID().toString() + "{").getBytes();
TarArchiveEntry tarEntry = new TarArchiveEntry("not-the-" + ImageArchiveUtil.MANIFEST_JSON);
tarEntry.setSize(entryData.length);
tarOutput.putArchiveEntry(tarEntry);
tarOutput.write(entryData);
tarOutput.closeArchiveEntry();
tarOutput.finish();
archiveBytes = baos.toByteArray();
}
ImageArchiveManifest manifest = ImageArchiveUtil.readManifest(new ByteArrayInputStream(archiveBytes));
Assert.assertNull(manifest);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project coprhd-controller by CoprHD.
the class WorkflowHelper method makeArchive.
/**
* @param out
* @param workflowPackage
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
private static void makeArchive(final ByteArrayOutputStream out, final CustomServicesWorkflowPackage workflowPackage) throws IOException {
try (final TarArchiveOutputStream tarOut = new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream(out)))) {
tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (final Entry<URI, CustomServicesWorkflowRestRep> workflow : workflowPackage.workflows().entrySet()) {
final String name = WORKFLOWS_FOLDER + "/" + workflow.getKey().toString();
final byte[] content = MAPPER.writeValueAsBytes(workflow.getValue());
final Date modTime = workflow.getValue().getCreationTime().getTime();
addArchiveEntry(tarOut, name, modTime, content);
}
for (final Entry<URI, CustomServicesPrimitiveRestRep> operation : workflowPackage.operations().entrySet()) {
final String name = OPERATIONS_FOLDER + "/" + operation.getKey().toString();
final byte[] content = MAPPER.writeValueAsBytes(operation.getValue());
final Date modTime = operation.getValue().getCreationTime().getTime();
addArchiveEntry(tarOut, name, modTime, content);
}
for (final Entry<URI, ResourcePackage> resource : workflowPackage.resources().entrySet()) {
final String name = RESOURCES_FOLDER + "/" + resource.getKey().toString() + ".md";
final String resourceFile = RESOURCES_FOLDER + "/" + resource.getKey().toString();
final byte[] metadata = MAPPER.writeValueAsBytes(resource.getValue().metadata());
final Date modTime = resource.getValue().metadata().getCreationTime().getTime();
addArchiveEntry(tarOut, name, modTime, metadata);
addArchiveEntry(tarOut, resourceFile, modTime, resource.getValue().bytes());
}
tarOut.finish();
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project gradle by gradle.
the class TarBuildCacheEntryPacker method pack.
@Override
public PackResult pack(CacheableEntity entity, Map<String, ? extends FileSystemSnapshot> snapshots, OutputStream output, OriginWriter writeOrigin) throws IOException {
BufferedOutputStream bufferedOutput;
if (output instanceof BufferedOutputStream) {
bufferedOutput = (BufferedOutputStream) output;
} else {
bufferedOutput = new BufferedOutputStream(output);
}
try (TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(bufferedOutput, ENCODING.name())) {
tarOutput.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
tarOutput.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
tarOutput.setAddPaxHeadersForNonAsciiNames(true);
packMetadata(writeOrigin, tarOutput);
long entryCount = pack(entity, snapshots, tarOutput);
return new PackResult(entryCount + 1);
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project gradle by gradle.
the class CommonsTarPacker method pack.
@Override
public void pack(List<DataSource> inputs, DataTarget output) throws IOException {
TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(output.openOutput());
for (DataSource input : inputs) {
TarArchiveEntry entry = new TarArchiveEntry(input.getName());
entry.setSize(input.getLength());
tarOutput.putArchiveEntry(entry);
PackerUtils.packEntry(input, tarOutput, buffer);
tarOutput.closeArchiveEntry();
}
tarOutput.close();
}
Aggregations