Example usage for org.apache.commons.compress.compressors CompressorStreamFactory GZIP

List of usage examples for org.apache.commons.compress.compressors CompressorStreamFactory GZIP

Introduction

In this page you can find the example usage for org.apache.commons.compress.compressors CompressorStreamFactory GZIP.

Prototype

String GZIP

To view the source code for org.apache.commons.compress.compressors CompressorStreamFactory GZIP.

Click Source Link

Document

Constant used to identify the GZIP compression algorithm.

Usage

From source file:com.github.wolfposd.jdpkg.deb.DpkgDeb.java

public static void main(String[] args) {

    if (args.length == 0) {
        System.out.println("jdpkg-deb: Missing parameters");
        System.out.println("jdpkg-deb: Usage: java -jar jdpkg.jar -Zgzip -b SomeFileOrFolder");
        System.exit(0);//from www. java 2s.  c  o  m
    }

    BuildFile = getBuildfile(args);
    String compressType = getCompressionType(args, "gzip");

    if (!new File(BuildFile).exists()) {
        System.out.println("jdpkg-deb: error: failed to open package info file '" + BuildFile
                + "/DEBIAN/control' for reading: No such file or directory");
        System.exit(0);
    }

    switch (compressType) {
    case "gzip":
        dpgk_deb(new File(BuildFile), ArchiveStreamFactory.TAR, CompressorStreamFactory.GZIP);
        break;
    default:
        System.out.println("Currently only supports gzip");
        break;

    }

}

From source file:darks.codec.wrap.zip.CommonsCompress.java

public CommonsCompress() {
    this.type = CompressorStreamFactory.GZIP;
}

From source file:com.facebook.buck.util.unarchive.Untar.java

public static Untar gzipUnarchiver() {
    return new Untar(Optional.of(CompressorStreamFactory.GZIP));
}

From source file:fr.gael.dhus.util.UnZip.java

public static void unCompress(String zip_file, String output_folder)
        throws IOException, CompressorException, ArchiveException {
    ArchiveInputStream ais = null;//from   ww  w .  j  av a 2 s.c  o m
    ArchiveStreamFactory asf = new ArchiveStreamFactory();

    FileInputStream fis = new FileInputStream(new File(zip_file));

    if (zip_file.toLowerCase().endsWith(".tar")) {
        ais = asf.createArchiveInputStream(ArchiveStreamFactory.TAR, fis);
    } else if (zip_file.toLowerCase().endsWith(".zip")) {
        ais = asf.createArchiveInputStream(ArchiveStreamFactory.ZIP, fis);
    } else if (zip_file.toLowerCase().endsWith(".tgz") || zip_file.toLowerCase().endsWith(".tar.gz")) {
        CompressorInputStream cis = new CompressorStreamFactory()
                .createCompressorInputStream(CompressorStreamFactory.GZIP, fis);
        ais = asf.createArchiveInputStream(new BufferedInputStream(cis));
    } else {
        try {
            fis.close();
        } catch (IOException e) {
            LOGGER.warn("Cannot close FileInputStream:", e);
        }
        throw new IllegalArgumentException("Format not supported: " + zip_file);
    }

    File output_file = new File(output_folder);
    if (!output_file.exists())
        output_file.mkdirs();

    // copy the existing entries
    ArchiveEntry nextEntry;
    while ((nextEntry = ais.getNextEntry()) != null) {
        File ftemp = new File(output_folder, nextEntry.getName());
        if (nextEntry.isDirectory()) {
            ftemp.mkdir();
        } else {
            FileOutputStream fos = FileUtils.openOutputStream(ftemp);
            IOUtils.copy(ais, fos);
            fos.close();
        }
    }
    ais.close();
    fis.close();
}

From source file:fr.gael.ccsds.sip.archive.TgzArchiveManager.java

@Override
public File copy(final File src, final File tar_file, final String dst) throws Exception {
    final ArchiveStreamFactory asf = new ArchiveStreamFactory();
    final CompressorStreamFactory csf = new CompressorStreamFactory();

    // Case of tar already exist: all the entries must be copied..
    if (tar_file.exists()) {
        final FileInputStream fis = new FileInputStream(tar_file);
        final CompressorInputStream cis = csf.createCompressorInputStream(CompressorStreamFactory.GZIP, fis);
        final ArchiveInputStream ais = asf.createArchiveInputStream(ArchiveStreamFactory.TAR, cis);

        final File tempFile = File.createTempFile("updateTar", "tar");
        final FileOutputStream fos = new FileOutputStream(tempFile);
        final CompressorOutputStream cos = csf.createCompressorOutputStream(CompressorStreamFactory.GZIP, fos);
        final ArchiveOutputStream aos = asf.createArchiveOutputStream(ArchiveStreamFactory.TAR, cos);

        // copy the existing entries
        ArchiveEntry nextEntry;//from  w w w.  j a  v  a 2  s  .  co m
        while ((nextEntry = ais.getNextEntry()) != null) {
            aos.putArchiveEntry(nextEntry);
            IOUtils.copy(ais, aos);
            aos.closeArchiveEntry();
        }

        // create the new entry
        final TarArchiveEntry entry = new TarArchiveEntry(src, dst);
        entry.setSize(src.length());
        aos.putArchiveEntry(entry);
        final FileInputStream sfis = new FileInputStream(src);
        IOUtils.copy(sfis, aos);
        sfis.close();
        aos.closeArchiveEntry();

        aos.finish();
        ais.close();
        aos.close();
        fis.close();

        // copies the new file over the old
        tar_file.delete();
        tempFile.renameTo(tar_file);
        return tar_file;
    } else {
        final FileOutputStream fos = new FileOutputStream(tar_file);
        final CompressorOutputStream cos = csf.createCompressorOutputStream(CompressorStreamFactory.GZIP, fos);
        final ArchiveOutputStream aos = asf.createArchiveOutputStream(ArchiveStreamFactory.TAR, cos);

        // create the new entry
        final TarArchiveEntry entry = new TarArchiveEntry(src, dst);
        entry.setSize(src.length());
        aos.putArchiveEntry(entry);
        final FileInputStream sfis = new FileInputStream(src);
        IOUtils.copy(sfis, aos);
        sfis.close();
        aos.closeArchiveEntry();

        aos.finish();
        aos.close();
        fos.close();
    }
    return tar_file;
}

From source file:com.quanticate.opensource.compressingcontentstore.CompressingContentStore.java

@Override
public void afterPropertiesSet() throws Exception {
    // Compression type is optional, use GZip if in doubt
    if (compressionType == null || compressionType.isEmpty()) {
        compressionType = CompressorStreamFactory.GZIP;
    }//  ww  w  .j ava2s .c om

    // Real Content Store and MimeTypes must be given
    if (compressMimeTypes == null || compressMimeTypes.isEmpty()) {
        throw new IllegalArgumentException("'compressMimeTypes' must be given");
    }
    if (realContentStore == null) {
        throw new IllegalArgumentException("'realContentStore' must be given");
    }
    if (mimetypeService == null) {
        throw new IllegalArgumentException("'mimetypeService' must be given");
    }
}

From source file:adams.core.io.GzipUtils.java

/**
 * Decompresses the specified gzip archive.
 *
 * @param archiveFile   the gzip file to decompress
 * @param buffer   the buffer size to use
 * @param outputFile   the destination file
 * @return      the error message, null if everything OK
 *//*from ww w .j a  v a  2  s .  c o  m*/
@MixedCopyright(copyright = "Apache compress commons", license = License.APACHE2, url = "http://commons.apache.org/compress/apidocs/org/apache/commons/compress/compressors/CompressorStreamFactory.html")
public static String decompress(File archiveFile, int buffer, File outputFile) {
    String result;
    OutputStream out;
    InputStream fis;
    CompressorInputStream in;
    String msg;

    in = null;
    fis = null;
    out = null;
    result = null;
    try {

        // does file already exist?
        if (outputFile.exists())
            System.err.println("WARNING: overwriting '" + outputFile + "'!");

        fis = new FileInputStream(archiveFile.getAbsolutePath());
        out = new FileOutputStream(outputFile.getAbsolutePath());
        in = new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.GZIP, fis);
        IOUtils.copy(in, out, buffer);
    } catch (Exception e) {
        msg = "Failed to decompress '" + archiveFile + "': ";
        System.err.println(msg);
        e.printStackTrace();
        result = msg + e;
    } finally {
        FileUtils.closeQuietly(in);
        FileUtils.closeQuietly(fis);
        FileUtils.closeQuietly(out);
    }

    return result;
}

From source file:com.jaeksoft.searchlib.crawler.web.sitemap.SiteMapItem.java

public Set<SiteMapUrl> load(HttpDownloader httpDownloader, Set<SiteMapUrl> siteMapUrlSet)
        throws SearchLibException {
    if (siteMapUrlSet == null)
        siteMapUrlSet = new TreeSet<SiteMapUrl>();
    InputStream inputStream = null;
    try {//from w ww. j  a  va 2  s  .  c o  m
        DownloadItem downloadItem = httpDownloader.get(uri, null);
        downloadItem.checkNoErrorList(200);
        if ("application/x-gzip".equals(downloadItem.getContentBaseType())) {
            inputStream = new CompressorStreamFactory().createCompressorInputStream(
                    CompressorStreamFactory.GZIP, downloadItem.getContentInputStream());
        } else
            inputStream = downloadItem.getContentInputStream();
        Document doc = DomUtils.readXml(new InputSource(inputStream), true);
        if (doc != null) {
            List<Node> nodes = DomUtils.getAllNodes(doc, "url");
            if (nodes != null)
                for (Node node : nodes)
                    siteMapUrlSet.add(new SiteMapUrl(node));
        }
        return siteMapUrlSet;
    } catch (ClientProtocolException e) {
        throw new SearchLibException(e);
    } catch (IllegalStateException e) {
        throw new SearchLibException(e);
    } catch (IOException e) {
        throw new SearchLibException(e);
    } catch (URISyntaxException e) {
        throw new SearchLibException(e);
    } catch (SAXException e) {
        throw new SearchLibException(e);
    } catch (ParserConfigurationException e) {
        throw new SearchLibException(e);
    } catch (CompressorException e) {
        throw new SearchLibException(e);
    } finally {
        IOUtils.close(inputStream);
    }
}

From source file:net.sf.util.zip.FileNameUtil.java

/**
 *
 * @param fileName  the file name/*from   w  w  w .  j  a v a  2s. c  om*/
 * @return   Compressed file type, as defined in CompressorStreamFactory
 */
public static String[] getCompressFileType(String fileName) {
    String s = fileName.toLowerCase();
    String[] ret = { null, null };
    if (GzipUtils.isCompressedFilename(s)) {
        ret[0] = CompressorStreamFactory.GZIP;
        ret[1] = GzipUtils.getUncompressedFilename(fileName);
    } else if (BZip2Utils.isCompressedFilename(s)) {
        ret[0] = CompressorStreamFactory.BZIP2;
        ret[1] = BZip2Utils.getUncompressedFilename(fileName);
    } else if (XZUtils.isCompressedFilename(s)) {
        ret[0] = CompressorStreamFactory.XZ;
        ret[1] = XZUtils.getUncompressedFilename(fileName);
    }

    return ret;
}

From source file:edu.utah.bmi.ibiomes.io.IBIOMESFileReader.java

/**
 * Get input stream reader//from w w w .j a v a  2  s  .  co m
 * @param hex Hexadecimal representation of first bits 
 * @return Input stream
 * @throws CompressorException
 * @throws IOException
 */
private CompressorInputStream getInputStreamForCompressedFile(String hex)
        throws CompressorException, IOException {
    if (hex.startsWith(HEX_HEADER_BZIP))
        compressionScheme = CompressorStreamFactory.BZIP2;
    else if (hex.startsWith(HEX_HEADER_GZIP))
        compressionScheme = CompressorStreamFactory.GZIP;

    if (compressionScheme != null) {
        CompressorStreamFactory factory = new CompressorStreamFactory();
        CompressorInputStream inputStream = factory.createCompressorInputStream(compressionScheme,
                new FileInputStream(file));
        return inputStream;
    } else //unsupported
    {
        throw new IOException(
                "Cannot read file " + file.getAbsolutePath() + ". Unsupported compression scheme.");
    }
}