本文整理汇总了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());
}