所以我编写了用于解析单个文件的解析器,但是我可以读取存档中的每个文件,而无需将存档实际提取到磁盘
答案 0 :(得分:3)
按照http://commons.apache.org/proper/commons-compress/examples.html中的示例,你必须用另一个
包装一个InputStream// 1st InputStream from your compressed file
FileInputStream in = new FileInputStream(tarbz2File);
// wrap in a 2nd InputStream that deals with compression
BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);
// wrap in a 3rd InputStream that deals with tar
TarArchiveInputStream tarIn = new TarArchiveInputStream(bzIn);
ArchiveEntry entry = null;
while (null != (entry = tarIn.getNextEntry())){
if (entry.getSize() < 1){
continue;
}
// use your parser here, the tar inputStream deals with the size of the current entry
parser.parse(tarIn);
}
tarIn.close();