有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我正在处理一些gzip打包的pack200文件,使用命令行工具解包它们没有问题。我只有在尝试使用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);

这是解包程序的输出。属性():

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与0x0A)
  • 拆包200。exe版本1.30,07/05/05
  • jdk版本1.7.0_21

因此,重申一下,命令行工具生成的jar文件可以正常工作,而库生成的jar文件不能正常工作

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


共 (1) 个答案

  1. # 1 楼答案

    这很简单,但我很高兴发现了问题所在。以下是我能够使用的解决方案:

    //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();