Search in sources :

Example 31 with GzipCompressorOutputStream

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

the class GzipCompressor method compressData.

/**
 * This method takes the Byte Array data and Compresses in gzip format
 *
 * @param data Data Byte Array passed for compression
 * @return Compressed Byte Array
 */
private byte[] compressData(byte[] data, int offset, int length) {
    int initialSize = (length / 2) == 0 ? length : length / 2;
    ByteArrayOutputStream output = new ByteArrayOutputStream(initialSize);
    try (GzipCompressorOutputStream stream = new GzipCompressorOutputStream(output)) {
        /*
       * Below api will write bytes from specified byte array to the gzipCompressorOutputStream
       * The output stream will compress the given byte array.
       */
        stream.write(data, offset, length);
    } catch (IOException e) {
        throw new RuntimeException("Error during Compression writing step ", e);
    }
    return output.toByteArray();
}
Also used : GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 32 with GzipCompressorOutputStream

use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project nodejs-plugin by jenkinsci.

the class NodeJSInstaller method buildCache.

private void buildCache(FilePath expected, File cache) throws IOException, InterruptedException {
    // update the local cache on master
    // download to a temporary file and rename it in to handle concurrency and failure correctly,
    Path tmp = new File(cache.getPath() + ".tmp").toPath();
    try {
        Path tmpParent = tmp.getParent();
        if (tmpParent != null) {
            Files.createDirectories(tmpParent);
        }
        try (OutputStream out = new GzipCompressorOutputStream(Files.newOutputStream(tmp))) {
            // workaround to not store current folder as root folder in the archive
            // this prevent issue when tool name is renamed
            expected.tar(out, "**");
        }
        Files.move(tmp, cache.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } finally {
        Files.deleteIfExists(tmp);
    }
}
Also used : Path(java.nio.file.Path) FilePath(hudson.FilePath) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) OutputStream(java.io.OutputStream) File(java.io.File)

Example 33 with GzipCompressorOutputStream

use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project nodejs-plugin by jenkinsci.

the class NodeJSInstallerTest method fillArchive.

private void fillArchive(File file, String fileEntry, byte[] content) throws IOException {
    try (TarArchiveOutputStream zf = new TarArchiveOutputStream(new GzipCompressorOutputStream(new FileOutputStream(file)))) {
        TarArchiveEntry ze = new TarArchiveEntry(fileEntry);
        ze.setSize(content.length);
        zf.putArchiveEntry(ze);
        IOUtils.write(content, zf);
        zf.closeArchiveEntry();
    }
}
Also used : GzipCompressorOutputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream) FileOutputStream(java.io.FileOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

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