我正在处理一些gzip压缩包文件,并且使用命令行工具解压缩它们没有问题。当我尝试使用pack200库解压缩文件时,我只会遇到问题。
作为参考,这是我用来解压缩文件的方法:
//Output from this can be properly unpacked with command line tool
InputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
//This is where things go awry
Pack200.Unpacker unpacker = Pack200.newUnpacker();
JarOutputStream out = new JarOutputStream(new FileOutputStream("file.jar"));
unpacker.unpack(in, out);
这是unpacker.properties()的输出:
com.sun.java.util.jar.pack.default.timezone: false
com.sun.java.util.jar.pack.disable.native: false
com.sun.java.util.jar.pack.verbose: 0
pack.class.attribute.CompilationID: RUH
pack.class.attribute.SourceID: RUH
pack.code.attribute.CharacterRangeTable: NH[PHPOHIIH]
pack.code.attribute.CoverageTable: NH[PHHII]
pack.deflate.hint: keep
pack.effort: 5
pack.keep.file.order: true
pack.modification.time: keep
pack.segment.limit: -1
pack.unknown.attribute: pass
其他一些相关信息:
重申一下,命令行工具生成的jar文件功能正常,而库生成的jar文件则没有。
我非常感谢任何帮助或指导。
答案 0 :(得分:0)
这很简单,但我很高兴找到了问题。这是我能够使用的解决方案:
//Output from this can be properly unpacked with command line tool
InputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
//This is where things go awry
Pack200.Unpacker unpacker = Pack200.newUnpacker();
JarOutputStream out = new JarOutputStream(new FileOutputStream("file.jar"));
unpacker.unpack(in, out);
out.close();
不要忘记你的JarOutPutStream.close();
,小孩。