Search in sources :

Example 16 with GzipCompressorOutputStream

use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project MSEC by Tencent.

the class GzipUtil method zip.

public static void zip(String srcFile, String destFile) throws Exception {
    GzipCompressorOutputStream out = new GzipCompressorOutputStream(new FileOutputStream(destFile));
    FileInputStream in = new FileInputStream(srcFile);
    byte[] buf = new byte[10240];
    while (true) {
        int len = in.read(buf);
        if (len <= 0) {
            break;
        }
        out.write(buf, 0, len);
    }
    out.flush();
    out.close();
    in.close();
}
Also used : GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 17 with GzipCompressorOutputStream

use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project MSEC by Tencent.

the class GzipUtil method zip.

public static void zip(String srcFile, String destFile) throws Exception {
    GzipCompressorOutputStream out = new GzipCompressorOutputStream(new FileOutputStream(destFile));
    FileInputStream in = new FileInputStream(srcFile);
    byte[] buf = new byte[10240];
    while (true) {
        int len = in.read(buf);
        if (len <= 0) {
            break;
        }
        out.write(buf, 0, len);
    }
    out.flush();
    out.close();
    in.close();
}
Also used : GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 18 with GzipCompressorOutputStream

use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project neo4j by neo4j.

the class Dumper method openArchiveOut.

private static ArchiveOutputStream openArchiveOut(Path archive) throws IOException {
    // StandardOpenOption.CREATE_NEW is important here because it atomically asserts that the file doesn't
    // exist as it is opened, avoiding a TOCTOU race condition which results in a security vulnerability. I
    // can't see a way to write a test to verify that we are using this option rather than just implementing
    // the check ourselves non-atomically.
    TarArchiveOutputStream tarball = new TarArchiveOutputStream(new GzipCompressorOutputStream(Files.newOutputStream(archive, StandardOpenOption.CREATE_NEW)));
    tarball.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    tarball.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
    return tarball;
}
Also used : GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)

Example 19 with GzipCompressorOutputStream

use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project docker-client by spotify.

the class CompressedDirectory method create.

/**
 * This method creates a gzip tarball of the specified directory. File permissions will be
 * retained. The file will be created in a temporary directory using the {@link
 * Files#createTempFile(String, String, java.nio.file.attribute.FileAttribute[])} method. The
 * returned object is auto-closeable, and upon closing it, the archive file will be deleted.
 *
 * @param directory the directory to compress
 * @return a Path object representing the compressed directory
 * @throws IOException if the compressed directory could not be created.
 */
public static CompressedDirectory create(final Path directory) throws IOException {
    final Path file = Files.createTempFile("docker-client-", ".tar.gz");
    final Path dockerIgnorePath = directory.resolve(".dockerignore");
    final ImmutableList<DockerIgnorePathMatcher> ignoreMatchers = parseDockerIgnore(dockerIgnorePath);
    try (final OutputStream fileOut = Files.newOutputStream(file);
        final GzipCompressorOutputStream gzipOut = new GzipCompressorOutputStream(fileOut);
        final TarArchiveOutputStream tarOut = new TarArchiveOutputStream(gzipOut)) {
        tarOut.setLongFileMode(LONGFILE_POSIX);
        tarOut.setBigNumberMode(BIGNUMBER_POSIX);
        Files.walkFileTree(directory, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new Visitor(directory, ignoreMatchers, tarOut));
    } catch (Throwable t) {
        // If an error occurs, delete temporary file before rethrowing exclude.
        try {
            Files.delete(file);
        } catch (IOException e) {
            // So we don't lose track of the reason the file was deleted... might be important
            t.addSuppressed(e);
        }
        throw t;
    }
    return new CompressedDirectory(file);
}
Also used : Path(java.nio.file.Path) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) OutputStream(java.io.OutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) IOException(java.io.IOException)

Example 20 with GzipCompressorOutputStream

use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project RecordManager2 by moravianlibrary.

the class TarGzUtils method compress.

public static File compress(String sourcePath, String targetPath) throws IOException {
    FileOutputStream fOut = null;
    BufferedOutputStream bOut = null;
    GzipCompressorOutputStream gzOut = null;
    TarArchiveOutputStream tOut = null;
    File targetFile = new File(targetPath);
    try {
        fOut = new FileOutputStream(targetFile);
        bOut = new BufferedOutputStream(fOut);
        gzOut = new GzipCompressorOutputStream(bOut);
        tOut = new TarArchiveOutputStream(gzOut);
        tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
        addFileToTarGz(tOut, sourcePath, "");
    } finally {
        if (tOut != null) {
            tOut.finish();
            tOut.close();
        }
        if (gzOut != null)
            gzOut.close();
        if (bOut != null)
            bOut.close();
        if (fOut != null)
            fOut.close();
    }
    return targetFile;
}
Also used : GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)

Aggregations

GzipCompressorOutputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream)33 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)24 File (java.io.File)16 FileOutputStream (java.io.FileOutputStream)13 Path (java.nio.file.Path)13 BufferedOutputStream (java.io.BufferedOutputStream)8 OutputStream (java.io.OutputStream)8 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)7 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 ZipOutputStream (java.util.zip.ZipOutputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ArchiveOutputStream (org.apache.commons.compress.archivers.ArchiveOutputStream)4 ArchiveEntry (org.apache.commons.compress.archivers.ArchiveEntry)3 Test (org.junit.Test)3 ZipEntry (java.util.zip.ZipEntry)2 Test (org.junit.jupiter.api.Test)2 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)1 CloseableIterator (alluxio.resource.CloseableIterator)1 ByteString (com.google.protobuf.ByteString)1