2017-01-19 67 views
0

我正在处理一些gzipped pack200文件,并且使用命令行工具解压它们没有问题。当我试图用pack200库解压文件时,我只遇到问题。Java 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版,05年7月5日
  • JDK版本1.7.0_21

所以要重申的是,通过在命令行工具功能生成jar文件正确,而库生成的那些做不。

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

+0

您没有关闭输出。 Javadoc中'Pack200'特别提到了这一点,在任何情况下都应该关闭'OutputStreams'和'Writers'。 – EJP

+0

@EJP是的,我确定了。我的一个相当愚蠢的错误。 – Aierou

回答

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();,孩子们。