public abstract class Pack200 extends Object
通常情况下,应用程序开发人员使用的封隔器引擎在网站上部署或主机上的文件。解包引擎被部署的应用程序用来将字节流回到jar格式。
这里是用封隔器和unpacker为例:
import java.util.jar.Pack200;
import java.util.jar.Pack200.*;
...
// Create the Packer object
Packer packer = Pack200.newPacker();
// Initialize the state by setting the desired properties
Map p = packer.properties();
// take more time choosing codings for better compression
p.put(Packer.EFFORT, "7"); // default is "5"
// use largest-possible archive segments (>10% better compression).
p.put(Packer.SEGMENT_LIMIT, "-1");
// reorder files for better compression.
p.put(Packer.KEEP_FILE_ORDER, Packer.FALSE);
// smear modification times to a single value.
p.put(Packer.MODIFICATION_TIME, Packer.LATEST);
// ignore all JAR deflation requests,
// transmitting a single request to use "store" mode.
p.put(Packer.DEFLATE_HINT, Packer.FALSE);
// discard debug attributes
p.put(Packer.CODE_ATTRIBUTE_PFX+"LineNumberTable", Packer.STRIP);
// throw an error if an attribute is unrecognized
p.put(Packer.UNKNOWN_ATTRIBUTE, Packer.ERROR);
// pass one class file uncompressed:
p.put(Packer.PASS_FILE_PFX+0, "mutants/Rogue.class");
try {
JarFile jarFile = new JarFile("/tmp/testref.jar");
FileOutputStream fos = new FileOutputStream("/tmp/test.pack");
// Call the packer
packer.pack(jarFile, fos);
jarFile.close();
fos.close();
File f = new File("/tmp/test.pack");
FileOutputStream fostream = new FileOutputStream("/tmp/test.jar");
JarOutputStream jostream = new JarOutputStream(fostream);
Unpacker unpacker = Pack200.newUnpacker();
// Call the unpacker
unpacker.unpack(f, jostream);
// Must explicitly close the output.
jostream.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
一个pack200文件用gzip压缩可以驻留在Web服务器的HTTP / 1.1。部署应用程序可以使用“接受编码= pack200压缩”。这表明在服务器,客户端应用程序需要的版本文件编码pack200进一步用gzip压缩。请参阅Java Deployment Guide更多的细节和技巧。
除非另有说明,通过null争论这类构造函数或方法会导致一个NullPointerException
被。
Modifier and Type | Class and Description |
---|---|
static interface |
Pack200.Packer
封隔器机适用于各种变换输入JAR文件,使包流是高度可压缩的压缩机如gzip或拉链。
|
static interface |
Pack200.Unpacker
解包引擎将打包到一个JAR文件流。
|
Modifier and Type | Method and Description |
---|---|
static Pack200.Packer |
newPacker()
获取一个实现封隔器的类的新实例。
|
static Pack200.Unpacker |
newUnpacker()
获得新的类的实例,实现了Unpacker。
|
public static Pack200.Packer newPacker()
如果系统性能java.util.jar.Pack200.Packer定义,那么价值是一个具体的实现类的完全限定名,必须实施封隔器。这类被加载和实例化。如果这个过程失败,则抛出一个未指定的错误。
如果一个执行尚未与系统属性中指定,则系统默认实现类被实例化,并返回结果。
注意:如果多个线程同时使用它,返回的对象不能保证正确的操作。一个多线程应用程序可以配置多个封隔器引擎,否则将使用一个引擎锁。
public static Pack200.Unpacker newUnpacker()
如果系统性能java.util.jar.Pack200.Unpacker定义,那么价值是一个具体的实现类的完全限定名,必须贯彻Unpacker。类的加载和实例化。如果这个过程失败,则抛出一个未指定的错误。
如果一个执行尚未与系统属性中指定,则系统默认实现类被实例化,并返回结果。
注意:如果多个线程同时使用它,返回的对象不能保证正确的操作。一个多线程应用程序可以配置多个新型发动机,否则将使用一个引擎锁。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.