Example usage for org.apache.commons.compress.archivers.sevenz SevenZOutputFile write

List of usage examples for org.apache.commons.compress.archivers.sevenz SevenZOutputFile write

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.sevenz SevenZOutputFile write.

Prototype

public void write(final byte[] b) throws IOException 

Source Link

Document

Writes a byte array to the current archive entry.

Usage

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

/**
 * Compress data//from w w w  .  j av a 2 s .c  o  m
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SevenZOutputFile sevenZOutput = new SevenZOutputFile(new File(fileCompressor.getCompressedPath()));
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) {
            SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(new File(binaryFile.getSrcPath()),
                    binaryFile.getDesPath());
            entry.setSize(binaryFile.getActualSize());
            sevenZOutput.putArchiveEntry(entry);
            sevenZOutput.write(binaryFile.getData());
            sevenZOutput.closeArchiveEntry();
        }
        sevenZOutput.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        sevenZOutput.close();
        baos.close();
    }
    return baos.toByteArray();
}