Example usage for org.apache.commons.compress.archivers ArchiveOutputStream getBytesWritten

List of usage examples for org.apache.commons.compress.archivers ArchiveOutputStream getBytesWritten

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers ArchiveOutputStream getBytesWritten.

Prototype

public long getBytesWritten() 

Source Link

Document

Returns the current number of bytes written to this stream.

Usage

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

/**
 * Lower level pack operation/* w  ww .j ava 2s  .c  o m*/
 * 
 * @param source
 *            source file
 * @param destination
 *            destination file
 * @return the number of bytes processed
 * @throws ArchiveException
 * @throws IOException
 */
public static long pack(String source, File destination) throws ArchiveException, IOException {

    ArchiveStreamFactory factory = new ArchiveStreamFactory();

    OutputStream outStream = new FileOutputStream(destination);

    ArchiveOutputStream outputStream;
    try {
        outputStream = factory.createArchiveOutputStream(ArchiveStreamFactory.TAR, outStream);
    } catch (ArchiveException e) {
        IOUtils.closeQuietly(outStream);

        throw e;
    }

    File startDirectory = new File(source);

    RecursiveArchiver archiver = new RecursiveArchiver(outputStream);

    try {
        archiver.archive(startDirectory);
        outputStream.flush();
        outputStream.close();

        outStream.flush();
        outStream.close();

    } catch (IOException e) {
        IOUtils.closeQuietly(outStream);
        IOUtils.closeQuietly(outputStream);

        throw e;
    }

    long ret = outputStream.getBytesWritten();

    if (logger.isDebugEnabled()) {
        logger.debug("Packed " + ret + " bytes");
    }

    return ret;
}