Example usage for org.apache.commons.compress.archivers.cpio CpioArchiveOutputStream finish

List of usage examples for org.apache.commons.compress.archivers.cpio CpioArchiveOutputStream finish

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.cpio CpioArchiveOutputStream finish.

Prototype

public void finish() throws IOException 

Source Link

Document

Finishes writing the contents of the CPIO output stream without closing the underlying stream.

Usage

From source file:com.espringtran.compressor4j.processor.CpioProcessor.java

/**
 * Compress data/*from   w ww.  j a va 2  s . com*/
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CpioArchiveOutputStream aos = new CpioArchiveOutputStream(baos);
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) {
            CpioArchiveEntry entry = new CpioArchiveEntry(binaryFile.getDesPath(), binaryFile.getActualSize());
            aos.putArchiveEntry(entry);
            aos.write(binaryFile.getData());
            aos.closeArchiveEntry();
        }
        aos.flush();
        aos.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        aos.close();
        baos.close();
    }
    return baos.toByteArray();
}