Example usage for org.apache.commons.compress.compressors.gzip GzipCompressorInputStream getBytesRead

List of usage examples for org.apache.commons.compress.compressors.gzip GzipCompressorInputStream getBytesRead

Introduction

In this page you can find the example usage for org.apache.commons.compress.compressors.gzip GzipCompressorInputStream getBytesRead.

Prototype

public long getBytesRead() 

Source Link

Document

Returns the current number of bytes read from this stream.

Usage

From source file:net.orpiske.ssps.common.archive.CompressedArchiveUtils.java

/**
 * Decompress a file//from ww  w  .j  a v  a2s. c o  m
 * @param source the source file to be uncompressed
 * @param destination the destination directory
 * @return the number of bytes read
 * @throws IOException for lower level I/O errors
 */
public static long gzDecompress(File source, File destination) throws IOException {
    FileOutputStream out;

    prepareDestination(destination);
    out = new FileOutputStream(destination);

    FileInputStream fin = null;
    BufferedInputStream bin = null;
    GzipCompressorInputStream gzIn = null;

    try {
        fin = new FileInputStream(source);
        bin = new BufferedInputStream(fin);
        gzIn = new GzipCompressorInputStream(bin);

        IOUtils.copy(gzIn, out);

        gzIn.close();

        fin.close();
        bin.close();
        out.close();
    } catch (IOException e) {
        IOUtils.closeQuietly(out);

        IOUtils.closeQuietly(fin);
        IOUtils.closeQuietly(bin);
        IOUtils.closeQuietly(gzIn);

        throw e;
    }

    return gzIn.getBytesRead();
}