Search in sources :

Example 31 with TarArchiveOutputStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Example 32 with TarArchiveOutputStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Example 33 with TarArchiveOutputStream

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();
    }
}
Also used : CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) ResourcePackage(com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Date(java.util.Date) GZIPOutputStream(java.util.zip.GZIPOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep) BufferedOutputStream(java.io.BufferedOutputStream)

Example 34 with TarArchiveOutputStream

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);
    }
}
Also used : TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 35 with TarArchiveOutputStream

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();
}
Also used : TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Aggregations

TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)101 File (java.io.File)42 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)42 FileOutputStream (java.io.FileOutputStream)37 GzipCompressorOutputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream)30 BufferedOutputStream (java.io.BufferedOutputStream)22 IOException (java.io.IOException)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 FileInputStream (java.io.FileInputStream)19 Path (java.nio.file.Path)17 GZIPOutputStream (java.util.zip.GZIPOutputStream)17 ByteArrayInputStream (java.io.ByteArrayInputStream)15 OutputStream (java.io.OutputStream)13 Test (org.junit.Test)12 ArchiveEntry (org.apache.commons.compress.archivers.ArchiveEntry)11 ArchiveOutputStream (org.apache.commons.compress.archivers.ArchiveOutputStream)11 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)9 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)9 ImageArchiveManifest (io.fabric8.maven.docker.model.ImageArchiveManifest)8 InputStream (java.io.InputStream)7