本文整理汇总了Java中org.apache.commons.compress.archivers.sevenz.SevenZFile类的典型用法代码示例。如果您正苦于以下问题:Java SevenZFile类的具体用法?Java SevenZFile怎么用?Java SevenZFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SevenZFile类属于org.apache.commons.compress.archivers.sevenz包,在下文中一共展示了SevenZFile类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decompress
import org.apache.commons.compress.archivers.sevenz.SevenZFile; //导入依赖的package包/类
public static void decompress(File outputDirectory, File file, boolean outerworld, String type) {
try {
SevenZFile archive = new SevenZFile(file);
SevenZArchiveEntry entry;
while ((entry = archive.getNextEntry()) != null) {
String filename = Paths.get(entry.getName()).getFileName().toString();
if (tablesNeeded(outerworld, type).stream().anyMatch(filename::contains)) {
log.info("Extracting {}", filename);
byte[] content = new byte[(int) entry.getSize()];
archive.read(content, 0, content.length);
File outputFile = new File(outputDirectory, filename.replace(".gz", ""));
try (GZIPInputStream input = new GZIPInputStream(new ByteArrayInputStream(content)); FileOutputStream output = new FileOutputStream(outputFile)) {
IOUtils.copy(input, output);
}
}
}
archive.close();
}
catch (IOException e) {
throw propagate(e);
}
}
示例2: parse
import org.apache.commons.compress.archivers.sevenz.SevenZFile; //导入依赖的package包/类
@Override
public void parse(File file) throws IOException {
mEntries = new ArrayList<>();
SevenZFile sevenZFile = new SevenZFile(file);
SevenZArchiveEntry entry = sevenZFile.getNextEntry();
while (entry != null) {
if (entry.isDirectory()) {
continue;
}
if (Utils.isImage(entry.getName())) {
byte[] content = new byte[(int)entry.getSize()];
sevenZFile.read(content);
mEntries.add(new SevenZEntry(entry, content));
}
entry = sevenZFile.getNextEntry();
}
Collections.sort(mEntries, new NaturalOrderComparator() {
@Override
public String stringValue(Object o) {
return ((SevenZEntry) o).entry.getName();
}
});
}
示例3: read
import org.apache.commons.compress.archivers.sevenz.SevenZFile; //导入依赖的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);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SevenZFile sevenZFile = new SevenZFile(new File(srcPath));
try {
byte[] buffer = new byte[1024];
int readByte;
SevenZArchiveEntry entry = sevenZFile.getNextEntry();
while (entry != null && entry.getSize() > 0) {
long t2 = System.currentTimeMillis();
baos = new ByteArrayOutputStream();
readByte = sevenZFile.read(buffer);
while (readByte != -1) {
baos.write(buffer, 0, readByte);
readByte = sevenZFile.read(buffer);
}
BinaryFile binaryFile = new BinaryFile(entry.getName(),
baos.toByteArray());
fileCompressor.addBinaryFile(binaryFile);
LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
System.currentTimeMillis());
entry = sevenZFile.getNextEntry();
}
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on get compressor file", e);
} finally {
sevenZFile.close();
baos.close();
}
LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
System.currentTimeMillis());
}
示例4: createArchiveInputStream
import org.apache.commons.compress.archivers.sevenz.SevenZFile; //导入依赖的package包/类
@Override
protected ArchiveInputStream createArchiveInputStream(File archive) throws IOException {
return new SevenZInputStream(new SevenZFile(archive));
}
示例5: SevenZInputStream
import org.apache.commons.compress.archivers.sevenz.SevenZFile; //导入依赖的package包/类
public SevenZInputStream(SevenZFile file) {
this.file = file;
}