當前位置: 首頁>>代碼示例>>Java>>正文


Java LZMACompressorInputStream類代碼示例

本文整理匯總了Java中org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream的典型用法代碼示例。如果您正苦於以下問題:Java LZMACompressorInputStream類的具體用法?Java LZMACompressorInputStream怎麽用?Java LZMACompressorInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LZMACompressorInputStream類屬於org.apache.commons.compress.compressors.lzma包,在下文中一共展示了LZMACompressorInputStream類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: read

import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream; //導入依賴的package包/類
/**
 * Read from compressed file
 * 
 * @param srcPath
 *            path of compressed file
 * @param fileCompressor
 *            FileCompressor object
 * @throws Exception
 */
@Override
public void read(String srcPath, FileCompressor fileCompressor)
        throws Exception {
    long t1 = System.currentTimeMillis();
    byte[] data = FileUtil.convertFileToByte(srcPath);
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    LZMACompressorInputStream cis = new LZMACompressorInputStream(bais);
    ZipInputStream zis = new ZipInputStream(cis);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        byte[] buffer = new byte[1024];
        int readByte;
        ZipEntry entry = zis.getNextEntry();
        while (entry != null) {
            long t2 = System.currentTimeMillis();
            baos = new ByteArrayOutputStream();
            readByte = zis.read(buffer);
            while (readByte != -1) {
                baos.write(buffer, 0, readByte);
                readByte = zis.read(buffer);
            }
            zis.closeEntry();
            BinaryFile binaryFile = new BinaryFile(entry.getName(),
                    baos.toByteArray());
            fileCompressor.addBinaryFile(binaryFile);
            LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
                    System.currentTimeMillis());
            entry = zis.getNextEntry();
        }
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on get compressor file", e);
    } finally {
        baos.close();
        zis.close();
        cis.close();
        bais.close();
    }
    LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
            System.currentTimeMillis());
}
 
開發者ID:espringtran,項目名稱:compressor4j,代碼行數:50,代碼來源:LzmaProcessor.java


注:本文中的org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。