Example usage for org.apache.commons.compress.archivers.ar ArArchiveOutputStream flush

List of usage examples for org.apache.commons.compress.archivers.ar ArArchiveOutputStream flush

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.ar ArArchiveOutputStream flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output bytes to be written out.

Usage

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

/**
 * Compress data//ww w  . ja v a2s. co m
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ArArchiveOutputStream aos = new ArArchiveOutputStream(baos);
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) {
            ArArchiveEntry entry = new ArArchiveEntry(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();
}