Search in sources :

Example 91 with TarArchiveOutputStream

use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project testcontainers-java by testcontainers.

the class MountableFileTest method intoTarArchive.

private TarArchiveInputStream intoTarArchive(Consumer<TarArchiveOutputStream> consumer) throws IOException {
    @Cleanup final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    @Cleanup final TarArchiveOutputStream taos = new TarArchiveOutputStream(baos);
    consumer.accept(taos);
    taos.close();
    return new TarArchiveInputStream(new ByteArrayInputStream(baos.toByteArray()));
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) Cleanup(lombok.Cleanup)

Example 92 with TarArchiveOutputStream

use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project elastest-torm by elastest.

the class FilesService method getTarArchiveOutputStream.

private TarArchiveOutputStream getTarArchiveOutputStream(String name) throws FileNotFoundException {
    logger.info("Creating output for the tar file.");
    TarArchiveOutputStream taos = new TarArchiveOutputStream(new FileOutputStream(name));
    taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
    taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    taos.setAddPaxHeadersForNonAsciiNames(true);
    return taos;
}
Also used : FileOutputStream(java.io.FileOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)

Example 93 with TarArchiveOutputStream

use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project xp by enonic.

the class AbstractDumpWriter method openTarStream.

private void openTarStream(final PathRef metaPath) {
    try {
        this.tarOutputStream = new TarArchiveOutputStream(new GZIPOutputStream(openMetaFileStream(metaPath)));
        this.tarOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    } catch (Exception e) {
        throw new RepoDumpException("Could not open meta-file", e);
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) IOException(java.io.IOException) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException)

Example 94 with TarArchiveOutputStream

use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project byzer-notebook by byzer-org.

the class UploadFileController method download.

@SneakyThrows
@ApiOperation("download file - from mlsql")
@GetMapping("/upload_file")
public void download(HttpServletRequest request, HttpServletResponse response) {
    String username = request.getParameter("userName").toLowerCase();
    String fileName = request.getParameter("fileName");
    String filePath = System.getProperty("NOTEBOOK_HOME") + "/tmp/" + username + "/" + fileName;
    File file = new File(filePath);
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".tar\"");
    try (TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(response.getOutputStream())) {
        log.info("User: [" + username + "] Downloading File: " + fileName);
        tarOutputStream.setBigNumberMode(BIGNUMBER_POSIX);
        ArchiveEntry entry = tarOutputStream.createArchiveEntry(file, fileName);
        tarOutputStream.putArchiveEntry(entry);
        IOUtils.copyLarge(new FileInputStream((file)), tarOutputStream);
        tarOutputStream.closeArchiveEntry();
        tarOutputStream.flush();
    }
}
Also used : ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream) ApiOperation(io.swagger.annotations.ApiOperation) SneakyThrows(lombok.SneakyThrows)

Example 95 with TarArchiveOutputStream

use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project cloud-pipeline by epam.

the class ScanServiceTest method mockDockerLayer.

private void mockDockerLayer(String s, ScanRequest headTestLayer) throws IOException, URISyntaxException {
    try (ByteArrayOutputStream layer = new ByteArrayOutputStream(BUFFER_SIZE);
        TarArchiveOutputStream tar = new TarArchiveOutputStream(new GzipCompressorOutputStream(layer))) {
        Files.walk(Paths.get(classLoader.getResource(s).toURI())).filter(Files::isRegularFile).forEach(path -> {
            File file = path.toFile();
            TarArchiveEntry entry = new TarArchiveEntry(file, file.getName());
            entry.setSize(file.length());
            try {
                tar.putArchiveEntry(entry);
                tar.write(IOUtils.toByteArray(new FileInputStream(file)));
                tar.closeArchiveEntry();
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        tar.close();
        Mockito.when(registryService.getDockerLayerBlob(headTestLayer.getLayer())).thenReturn(new ByteArrayInputStream(layer.toByteArray()));
    }
}
Also used : GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) 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