001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package demo;
022
023import java.io.FileInputStream;
024import java.io.InputStream;
025
026import org.biojava.nbio.core.util.UncompressInputStream;
027import org.slf4j.Logger;
028import org.slf4j.LoggerFactory;
029
030/**
031 * Uncompresses a single tarred or zipped file, writing output to stdandard out
032 */
033public class UncompressFile {
034    private final static Logger logger
035                = LoggerFactory.getLogger(UncompressFile.class);
036
037    /**
038         * Reads a file, uncompresses it, and sends the result to stdout.
039         * Also writes trivial statistics to stderr.
040         * @param args An array with one String element, the name of the file to read.
041         * @throws IOException for any failure
042         */
043        public static void main(String[] args) throws Exception {
044
045                if (args.length != 1) {
046                        logger.info("Usage: UncompressInputStream <file>");
047                        System.exit(1);
048                }
049                long beg = System.currentTimeMillis();
050
051                long tot;
052                try (InputStream in = new FileInputStream(args[0]); 
053         ) {
054                        tot = UncompressInputStream.uncompress(in, System.out);
055                }
056
057                long end = System.currentTimeMillis();
058                logger.info("Decompressed {} bytes", tot);
059                logger.info("Time: {} seconds", (end - beg) / 1000);
060        }
061    
062}