Search in sources :

Example 51 with TarArchiveOutputStream

use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project Manga by herrlock.

the class ViewArchive method writeCBT.

private void writeCBT() throws IOException {
    logger.traceEntry();
    Path folderPath = this.folder.toPath();
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(folderPath, new ViewPageConstants.PathIsDirectoryFilter())) {
        for (Path path : directoryStream) {
            logger.debug("Archiving {}", path);
            String chapterName = decimalTransform(String.valueOf(path.getFileName()), 4);
            Path tarArchive = this.targetFolder.resolve(mangaName() + '-' + chapterName + ".cbt");
            logger.debug("Write to: {}", tarArchive);
            try (TarArchiveOutputStream archiveZip = new TarArchiveOutputStream(Files.newOutputStream(tarArchive))) {
                writeTarEntry(archiveZip, path);
            }
            if (this.clean) {
                logger.debug("Cleaning {}", path);
                Files.walkFileTree(path, DELETE_VISITOR);
            }
        }
    }
    if (this.clean) {
        logger.debug("Cleaning {}", folderPath);
        Files.walkFileTree(folderPath, DELETE_VISITOR);
    }
}
Also used : Path(java.nio.file.Path) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)

Example 52 with TarArchiveOutputStream

use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project teku by ConsenSys.

the class ValidatorKeystores method copyDirectoryToTarFile.

private static void copyDirectoryToTarFile(Path inputDirectoryPath, Path outputPath) throws IOException {
    File outputFile = outputPath.toFile();
    try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
        TarArchiveOutputStream tarArchiveOutputStream = new TarArchiveOutputStream(bufferedOutputStream)) {
        tarArchiveOutputStream.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
        tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        List<File> files = new ArrayList<>(FileUtils.listFiles(inputDirectoryPath.toFile(), new String[] { "json", "txt" }, true));
        for (File currentFile : files) {
            String relativeFilePath = new File(inputDirectoryPath.toUri()).toURI().relativize(new File(currentFile.getAbsolutePath()).toURI()).getPath();
            TarArchiveEntry tarEntry = new TarArchiveEntry(currentFile, relativeFilePath);
            tarEntry.setSize(currentFile.length());
            tarArchiveOutputStream.putArchiveEntry(tarEntry);
            tarArchiveOutputStream.write(Files.readAllBytes(currentFile.toPath()));
            tarArchiveOutputStream.closeArchiveEntry();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 53 with TarArchiveOutputStream

use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project flink-mirror by flink-ci.

the class YarnTestArchiveJob method archiveFilesInDirectory.

private static void archiveFilesInDirectory(File directory, String target) throws IOException {
    for (Map.Entry<String, String> entry : srcFiles.entrySet()) {
        Files.write(Paths.get(directory.getAbsolutePath() + File.separator + entry.getKey()), entry.getValue().getBytes());
    }
    try (FileOutputStream fos = new FileOutputStream(target);
        GzipCompressorOutputStream gos = new GzipCompressorOutputStream(new BufferedOutputStream(fos));
        TarArchiveOutputStream taros = new TarArchiveOutputStream(gos)) {
        taros.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        for (File f : directory.listFiles()) {
            taros.putArchiveEntry(new TarArchiveEntry(f, directory.getName() + File.separator + f.getName()));
            try (FileInputStream fis = new FileInputStream(f);
                BufferedInputStream bis = new BufferedInputStream(fis)) {
                IOUtils.copy(bis, taros);
                taros.closeArchiveEntry();
            }
        }
    }
    for (Map.Entry<String, String> entry : srcFiles.entrySet()) {
        Files.delete(Paths.get(directory.getAbsolutePath() + File.separator + entry.getKey()));
    }
}
Also used : GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) FileInputStream(java.io.FileInputStream)

Example 54 with TarArchiveOutputStream

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

the class TarUtils method tar.

public static Path tar(Path srcPath, Path dstPath) throws IOException {
    try (OutputStream output = new FileOutputStream(dstPath.toFile())) {
        try (TarArchiveOutputStream taos = new TarArchiveOutputStream(output)) {
            for (File file : srcPath.toFile().listFiles()) {
                ArchiveEntry entry = taos.createArchiveEntry(file, file.getName());
                taos.putArchiveEntry(entry);
                StreamUtils.copyBytes(file.toURI().toURL(), taos);
                taos.closeArchiveEntry();
            }
        }
    }
    return dstPath;
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) File(java.io.File)

Example 55 with TarArchiveOutputStream

use of org.apache.commons.compress.archivers.tar.TarArchiveOutputStream in project devops-service by open-hand.

the class FileUtil method archive.

/**
 * 归档
 *
 * @param entry
 * @return
 * @throws IOException
 */
public static String archive(String entry, String outputFilePath) throws IOException {
    File file = new File(entry);
    TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(outputFilePath + ".tar"));
    String base = file.getName();
    if (file.isDirectory()) {
        archiveDir(file, tos, base);
    } else {
        archiveHandle(tos, file, base);
    }
    tos.close();
    return outputFilePath + ".tar";
}
Also used : TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ZipFile(java.util.zip.ZipFile) MultipartFile(org.springframework.web.multipart.MultipartFile)

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