Java Pack200库输出与命令行工具输出不同

时间:2017-01-19 05:05:19

标签: java jar compression

我正在处理一些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文件。
  • 库生成的文件使用较新版本的.zip格式(0x14 vs 0x0A)。
  • unpack200.exe版本1.30,07 / 05/05
  • jdk version 1.7.0_21

重申一下,命令行工具生成的jar文件功能正常,而库生成的jar文件则没有。

我非常感谢任何帮助或指导。

1 个答案:

答案 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();,小孩。

相关问题