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