jdk/src/java.base/share/classes/java/util/jar/Pack200.java
author avstepan
Thu, 06 Aug 2015 19:07:35 +0300
changeset 32037 ab4526f4ac10
parent 26974 4bee12591374
child 32649 2ee9017c7597
permissions -rw-r--r--
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26974
4bee12591374 8059973: Broken link in Class Pack200
ksrini
parents: 25859
diff changeset
     2
 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.util.jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.SortedMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Transforms a JAR file to or from a packed stream in Pack200 format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Please refer to Network Transfer Format JSR 200 Specification at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <a href=http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html>http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Typically the packer engine is used by application developers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * to deploy or host JAR files on a website.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The unpacker  engine is used by deployment applications to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * transform the byte-stream back to JAR format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18585
diff changeset
    44
 * Here is an example using  packer and unpacker:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 15684
diff changeset
    45
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *    import java.util.jar.Pack200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *    import java.util.jar.Pack200.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *    ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *    // Create the Packer object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *    Packer packer = Pack200.newPacker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *    // Initialize the state by setting the desired properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *    Map p = packer.properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *    // take more time choosing codings for better compression
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *    p.put(Packer.EFFORT, "7");  // default is "5"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *    // use largest-possible archive segments (>10% better compression).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *    p.put(Packer.SEGMENT_LIMIT, "-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *    // reorder files for better compression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *    p.put(Packer.KEEP_FILE_ORDER, Packer.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *    // smear modification times to a single value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *    p.put(Packer.MODIFICATION_TIME, Packer.LATEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *    // ignore all JAR deflation requests,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *    // transmitting a single request to use "store" mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *    p.put(Packer.DEFLATE_HINT, Packer.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *    // discard debug attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *    p.put(Packer.CODE_ATTRIBUTE_PFX+"LineNumberTable", Packer.STRIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *    // throw an error if an attribute is unrecognized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *    p.put(Packer.UNKNOWN_ATTRIBUTE, Packer.ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *    // pass one class file uncompressed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *    p.put(Packer.PASS_FILE_PFX+0, "mutants/Rogue.class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *        JarFile jarFile = new JarFile("/tmp/testref.jar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *        FileOutputStream fos = new FileOutputStream("/tmp/test.pack");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *        // Call the packer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *        packer.pack(jarFile, fos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *        jarFile.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *        fos.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *        File f = new File("/tmp/test.pack");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *        FileOutputStream fostream = new FileOutputStream("/tmp/test.jar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *        JarOutputStream jostream = new JarOutputStream(fostream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *        Unpacker unpacker = Pack200.newUnpacker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *        // Call the unpacker
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *        unpacker.unpack(f, jostream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *        // Must explicitly close the output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *        jostream.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *    } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *        ioe.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *    }
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 15684
diff changeset
    90
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * A Pack200 file compressed with gzip can be hosted on HTTP/1.1 web servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * The deployment applications can use "Accept-Encoding=pack200-gzip". This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * indicates to the server that the client application desires a version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * the file encoded with Pack200 and further compressed with gzip. Please
26974
4bee12591374 8059973: Broken link in Class Pack200
ksrini
parents: 25859
diff changeset
    96
 * refer to the Java Deployment Guide for techniques and details.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <p>
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
    98
 * Unless otherwise noted, passing a {@code null} argument to a constructor or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * method in this class will cause a {@link NullPointerException} to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * @author John Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * @author Kumar Srinivasan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
public abstract class Pack200 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private Pack200() {} //prevent instantiation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // Static methods of the Pack200 class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Obtain new instance of a class that implements Packer.
18585
820a67f42c4c 8019467: Fix doclint issues in java.util.jar.Pack200
darcy
parents: 18156
diff changeset
   111
     * <ul>
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   112
     * <li><p>If the system property {@code java.util.jar.Pack200.Packer}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * is defined, then the value is taken to be the fully-qualified name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * of a concrete implementation class, which must implement Packer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * This class is loaded and instantiated.  If this process fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * then an unspecified error is thrown.</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <li><p>If an implementation has not been specified with the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * property, then the system-default implementation class is instantiated,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * and the result is returned.</p></li>
18585
820a67f42c4c 8019467: Fix doclint issues in java.util.jar.Pack200
darcy
parents: 18156
diff changeset
   121
     * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <p>Note:  The returned object is not guaranteed to operate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * correctly if multiple threads use it at the same time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * A multi-threaded application should either allocate multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * packer engines, or else serialize use of one engine with a lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return  A newly allocated Packer engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public synchronized static Packer newPacker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return (Packer) newInstance(PACK_PROVIDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Obtain new instance of a class that implements Unpacker.
18585
820a67f42c4c 8019467: Fix doclint issues in java.util.jar.Pack200
darcy
parents: 18156
diff changeset
   137
     * <ul>
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   138
     * <li><p>If the system property {@code java.util.jar.Pack200.Unpacker}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * is defined, then the value is taken to be the fully-qualified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * name of a concrete implementation class, which must implement Unpacker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * The class is loaded and instantiated.  If this process fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * then an unspecified error is thrown.</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <li><p>If an implementation has not been specified with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * system property, then the system-default implementation class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * is instantiated, and the result is returned.</p></li>
18585
820a67f42c4c 8019467: Fix doclint issues in java.util.jar.Pack200
darcy
parents: 18156
diff changeset
   147
     * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * <p>Note:  The returned object is not guaranteed to operate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * correctly if multiple threads use it at the same time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * A multi-threaded application should either allocate multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * unpacker engines, or else serialize use of one engine with a lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @return  A newly allocated Unpacker engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public static Unpacker newUnpacker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return (Unpacker) newInstance(UNPACK_PROVIDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    // Interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * The packer engine applies various transformations to the input JAR file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * making the pack stream highly compressible by a compressor such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * gzip or zip. An instance of the engine can be obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * using {@link #newPacker}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * The high degree of compression is achieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * by using a number of techniques described in the JSR 200 specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Some of the techniques are sorting, re-ordering and co-location of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * constant pool.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * The pack engine is initialized to an initial state as described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * by their properties below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * The initial state can be manipulated by getting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * engine properties (using {@link #properties}) and storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * the modified properties on the map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * The resource files will be passed through with no changes at all.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * The class files will not contain identical bytes, since the unpacker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * is free to change minor class file features such as constant pool order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * However, the class files will be semantically identical,
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7795
diff changeset
   182
     * as specified in
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7795
diff changeset
   183
     * <cite>The Java&trade; Virtual Machine Specification</cite>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * By default, the packer does not change the order of JAR elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Also, the modification time and deflation hint of each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * JAR element is passed unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * (Any other ZIP-archive information, such as extra attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * giving Unix file permissions, are lost.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Note that packing and unpacking a JAR will in general alter the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * bytewise contents of classfiles in the JAR.  This means that packing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * and unpacking will in general invalidate any digital signatures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * which rely on bytewise images of JAR elements.  In order both to sign
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * and to pack a JAR, you must first pack and unpack the JAR to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * "normalize" it, then compute signatures on the unpacked JAR elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * and finally repack the signed JAR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Both packing steps should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * use precisely the same options, and the segment limit may also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * need to be set to "-1", to prevent accidental variation of segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * boundaries as class file sizes change slightly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * (Here's why this works:  Any reordering the packer does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * of any classfile structures is idempotent, so the second packing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * does not change the orderings produced by the first packing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Also, the unpacker is guaranteed by the JSR 200 specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * to produce a specific bytewise image for any given transmission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * ordering of archive elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <p>
5811
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   210
     * In order to maintain backward compatibility, the pack file's version is
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   211
     * set to accommodate the class files present in the input JAR file. In
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   212
     * other words, the pack file version will be the latest, if the class files
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   213
     * are the latest and conversely the pack file version will be the oldest
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   214
     * if the class file versions are also the oldest. For intermediate class
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   215
     * file versions the corresponding pack file version will be used.
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   216
     * For example:
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   217
     *    If the input JAR-files are solely comprised of 1.5  (or  lesser)
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   218
     * class files, a 1.5 compatible pack file is  produced. This will also be
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   219
     * the case for archives that have no class files.
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   220
     *    If the input JAR-files contains a 1.6 class file, then the pack file
f4d1f45c0058 6712743: pack200: should default to 150.7 pack format for classfiles without any classes.
ksrini
parents: 5799
diff changeset
   221
     * version will be set to 1.6.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <p>
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   223
     * Note: Unless otherwise noted, passing a {@code null} argument to a
7171
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 5811
diff changeset
   224
     * constructor or method in this class will cause a {@link NullPointerException}
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 5811
diff changeset
   225
     * to be thrown.
24196
61c9885d76e2 8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents: 22046
diff changeset
   226
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public interface Packer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         * This property is a numeral giving the estimated target size N
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * (in bytes) of each archive segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         * If a single input file requires more than N bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         * it will be given its own archive segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         * As a special case, a value of -1 will produce a single large
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         * segment with all input files, while a value of 0 will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         * produce one segment for each class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         * Larger archive segments result in less fragmentation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
         * better compression, but processing them requires more memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         * The size of each segment is estimated by counting the size of each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
         * input file to be transmitted in the segment, along with the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
         * of its name and other transmitted properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         * <p>
5799
e0089b2436a4 6575373: Error verifying signatures of pack200 files in some cases
ksrini
parents: 5506
diff changeset
   246
         * The default is -1, which means the packer will always create a single
e0089b2436a4 6575373: Error verifying signatures of pack200 files in some cases
ksrini
parents: 5506
diff changeset
   247
         * segment output file. In cases where extremely large output files are
e0089b2436a4 6575373: Error verifying signatures of pack200 files in some cases
ksrini
parents: 5506
diff changeset
   248
         * generated, users are strongly encouraged to use segmenting or break
e0089b2436a4 6575373: Error verifying signatures of pack200 files in some cases
ksrini
parents: 5506
diff changeset
   249
         * up the input file into smaller JARs.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         * A 10Mb JAR packed without this limit will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         * typically pack about 10% smaller, but the packer may require
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         * a larger Java heap (about ten times the segment limit).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        String SEGMENT_LIMIT    = "pack.segment.limit";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * If this property is set to {@link #TRUE}, the packer will transmit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * all elements in their original order within the source archive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         * If it is set to {@link #FALSE}, the packer may reorder elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
         * and also remove JAR directory entries, which carry no useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         * information for Java applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         * (Typically this enables better compression.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         * The default is {@link #TRUE}, which preserves the input information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
         * but may cause the transmitted archive to be larger than necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        String KEEP_FILE_ORDER = "pack.keep.file.order";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         * If this property is set to a single decimal digit, the packer will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         * use the indicated amount of effort in compressing the archive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
         * Level 1 may produce somewhat larger size and faster compression speed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
         * while level 9 will take much longer but may produce better compression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
         * The special value 0 instructs the packer to copy through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
         * original JAR file directly, with no compression.  The JSR 200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
         * standard requires any unpacker to understand this special case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
         * as a pass-through of the entire archive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
         * The default is 5, investing a modest amount of time to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
         * produce reasonable compression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        String EFFORT           = "pack.effort";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         * If this property is set to {@link #TRUE} or {@link #FALSE}, the packer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         * will set the deflation hint accordingly in the output archive, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         * will not transmit the individual deflation hints of archive elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         * If this property is set to the special string {@link #KEEP}, the packer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         * will attempt to determine an independent deflation hint for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         * available element of the input archive, and transmit this hint separately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         * The default is {@link #KEEP}, which preserves the input information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * but may cause the transmitted archive to be larger than necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         * It is up to the unpacker implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
         * to take action upon the hint to suitably compress the elements of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
         * the resulting unpacked jar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
         * The deflation hint of a ZIP or JAR element indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
         * whether the element was deflated or stored directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        String DEFLATE_HINT     = "pack.deflate.hint";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         * If this property is set to the special string {@link #LATEST},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
         * the packer will attempt to determine the latest modification time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         * among all the available entries in the original archive or the latest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
         * modification time of all the available entries in each segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         * This single value will be transmitted as part of the segment and applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
         * to all the entries in each segment, {@link #SEGMENT_LIMIT}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
         * This can marginally decrease the transmitted size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
         * archive, at the expense of setting all installed files to a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
         * date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
         * If this property is set to the special string {@link #KEEP},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
         * the packer transmits a separate modification time for each input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
         * element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
         * The default is {@link #KEEP}, which preserves the input information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         * but may cause the transmitted archive to be larger than necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         * It is up to the unpacker implementation to take action to suitably
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         * set the modification time of each element of its output file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         * @see #SEGMENT_LIMIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        String MODIFICATION_TIME        = "pack.modification.time";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
         * Indicates that a file should be passed through bytewise, with no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
         * compression.  Multiple files may be specified by specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         * additional properties with distinct strings appended, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         * make a family of properties with the common prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * There is no pathname transformation, except
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * that the system file separator is replaced by the JAR file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * separator '/'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         * The resulting file names must match exactly as strings with their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         * occurrences in the JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * If a property value is a directory name, all files under that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * directory will be passed also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         * Examples:
18585
820a67f42c4c 8019467: Fix doclint issues in java.util.jar.Pack200
darcy
parents: 18156
diff changeset
   351
         * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         *     Map p = packer.properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         *     p.put(PASS_FILE_PFX+0, "mutants/Rogue.class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
         *     p.put(PASS_FILE_PFX+1, "mutants/Wolverine.class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
         *     p.put(PASS_FILE_PFX+2, "mutants/Storm.class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         *     # Pass all files in an entire directory hierarchy:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         *     p.put(PASS_FILE_PFX+3, "police/");
18585
820a67f42c4c 8019467: Fix doclint issues in java.util.jar.Pack200
darcy
parents: 18156
diff changeset
   358
         * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        String PASS_FILE_PFX            = "pack.pass.file.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        /// Attribute control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * Indicates the action to take when a class-file containing an unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * attribute is encountered.  Possible values are the strings {@link #ERROR},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * {@link #STRIP}, and {@link #PASS}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * The string {@link #ERROR} means that the pack operation
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   370
         * as a whole will fail, with an exception of type {@code IOException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         * The string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         * {@link #STRIP} means that the attribute will be dropped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         * The string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         * {@link #PASS} means that the whole class-file will be passed through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         * (as if it were a resource file) without compression, with  a suitable warning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         * This is the default value for this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         * Examples:
18585
820a67f42c4c 8019467: Fix doclint issues in java.util.jar.Pack200
darcy
parents: 18156
diff changeset
   379
         * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         *     Map p = pack200.getProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         *     p.put(UNKNOWN_ATTRIBUTE, ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         *     p.put(UNKNOWN_ATTRIBUTE, STRIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
         *     p.put(UNKNOWN_ATTRIBUTE, PASS);
18585
820a67f42c4c 8019467: Fix doclint issues in java.util.jar.Pack200
darcy
parents: 18156
diff changeset
   384
         * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        String UNKNOWN_ATTRIBUTE        = "pack.unknown.attribute";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
         * When concatenated with a class attribute name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         * indicates the format of that attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         * using the layout language specified in the JSR 200 specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
         * For example, the effect of this option is built in:
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   394
         * {@code pack.class.attribute.SourceFile=RUH}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         * The special strings {@link #ERROR}, {@link #STRIP}, and {@link #PASS} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
         * also allowed, with the same meaning as {@link #UNKNOWN_ATTRIBUTE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         * This provides a way for users to request that specific attributes be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         * refused, stripped, or passed bitwise (with no class compression).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         * Code like this might be used to support attributes for JCOV:
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   402
         * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
         *     Map p = packer.properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         *     p.put(CODE_ATTRIBUTE_PFX+"CoverageTable",       "NH[PHHII]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         *     p.put(CODE_ATTRIBUTE_PFX+"CharacterRangeTable", "NH[PHPOHIIH]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         *     p.put(CLASS_ATTRIBUTE_PFX+"SourceID",           "RUH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         *     p.put(CLASS_ATTRIBUTE_PFX+"CompilationID",      "RUH");
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   408
         * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         * Code like this might be used to strip debugging attributes:
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   411
         * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
         *     Map p = packer.properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
         *     p.put(CODE_ATTRIBUTE_PFX+"LineNumberTable",    STRIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         *     p.put(CODE_ATTRIBUTE_PFX+"LocalVariableTable", STRIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
         *     p.put(CLASS_ATTRIBUTE_PFX+"SourceFile",        STRIP);
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   416
         * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        String CLASS_ATTRIBUTE_PFX      = "pack.class.attribute.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         * When concatenated with a field attribute name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
         * indicates the format of that attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         * For example, the effect of this option is built in:
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   424
         * {@code pack.field.attribute.Deprecated=}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
         * The special strings {@link #ERROR}, {@link #STRIP}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
         * {@link #PASS} are also allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
         * @see #CLASS_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        String FIELD_ATTRIBUTE_PFX      = "pack.field.attribute.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
         * When concatenated with a method attribute name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
         * indicates the format of that attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
         * For example, the effect of this option is built in:
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   435
         * {@code pack.method.attribute.Exceptions=NH[RCH]}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
         * The special strings {@link #ERROR}, {@link #STRIP}, and {@link #PASS}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         * are also allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
         * @see #CLASS_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        String METHOD_ATTRIBUTE_PFX     = "pack.method.attribute.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
         * When concatenated with a code attribute name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
         * indicates the format of that attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
         * For example, the effect of this option is built in:
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   446
         * {@code pack.code.attribute.LocalVariableTable=NH[PHOHRUHRSHH]}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
         * The special strings {@link #ERROR}, {@link #STRIP}, and {@link #PASS}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
         * are also allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
         * @see #CLASS_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        String CODE_ATTRIBUTE_PFX       = "pack.code.attribute.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         * The unpacker's progress as a percentage, as periodically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
         * updated by the unpacker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
         * Values of 0 - 100 are normal, and -1 indicates a stall.
14192
e218f76e78db 8000362: (pack200) Deprecate Packer/Unpacker addPropertyChangeLister and removePropertyChangeListener methods
alanb
parents: 13795
diff changeset
   457
         * Progress can be monitored by polling the value of this
e218f76e78db 8000362: (pack200) Deprecate Packer/Unpacker addPropertyChangeLister and removePropertyChangeListener methods
alanb
parents: 13795
diff changeset
   458
         * property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         * At a minimum, the unpacker must set progress to 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         * at the beginning of a packing operation, and to 100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
         * at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        String PROGRESS                 = "pack.progress";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        /** The string "keep", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
         * @see #DEFLATE_HINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
         * @see #MODIFICATION_TIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        String KEEP  = "keep";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        /** The string "pass", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
         * @see #UNKNOWN_ATTRIBUTE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
         * @see #CLASS_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
         * @see #FIELD_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
         * @see #METHOD_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
         * @see #CODE_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        String PASS  = "pass";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        /** The string "strip", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
         * @see #UNKNOWN_ATTRIBUTE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
         * @see #CLASS_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
         * @see #FIELD_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
         * @see #METHOD_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
         * @see #CODE_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        String STRIP = "strip";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        /** The string "error", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
         * @see #UNKNOWN_ATTRIBUTE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
         * @see #CLASS_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
         * @see #FIELD_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
         * @see #METHOD_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
         * @see #CODE_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        String ERROR = "error";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        /** The string "true", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
         * @see #KEEP_FILE_ORDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
         * @see #DEFLATE_HINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        String TRUE = "true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        /** The string "false", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         * @see #KEEP_FILE_ORDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         * @see #DEFLATE_HINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        String FALSE = "false";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        /** The string "latest", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         * @see #MODIFICATION_TIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        String LATEST = "latest";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         * Get the set of this engine's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         * This set is a "live view", so that changing its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
         * contents immediately affects the Packer engine, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         * changes from the engine (such as progress indications)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         * are immediately visible in the map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         * <p>The property map may contain pre-defined implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         * specific and default properties.  Users are encouraged to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         * read the information and fully understand the implications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         * before modifying pre-existing properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         * Implementation specific properties are prefixed with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
         * package name associated with the implementor, beginning
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   530
         * with {@code com.} or a similar prefix.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   531
         * All property names beginning with {@code pack.} and
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   532
         * {@code unpack.} are reserved for use by this API.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
         * Unknown properties may be ignored or rejected with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
         * unspecified error, and invalid entries may cause an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
         * unspecified error to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
         * The returned map implements all optional {@link SortedMap} operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * @return A sorted association of property key strings to property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         * values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        SortedMap<String,String> properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         * Takes a JarFile and converts it into a Pack200 archive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
         * Closes its input but not its output.  (Pack200 archives are appendable.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
         * @param in a JarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
         * @param out an OutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
         * @exception IOException if an error is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        void pack(JarFile in, OutputStream out) throws IOException ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
         * Takes a JarInputStream and converts it into a Pack200 archive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
         * Closes its input but not its output.  (Pack200 archives are appendable.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
         * The modification time and deflation hint attributes are not available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
         * for the JAR manifest file and its containing directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
         * @see #MODIFICATION_TIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
         * @see #DEFLATE_HINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
         * @param in a JarInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
         * @param out an OutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         * @exception IOException if an error is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        void pack(JarInputStream in, OutputStream out) throws IOException ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * The unpacker engine converts the packed stream to a JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * An instance of the engine can be obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * using {@link #newUnpacker}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * Every JAR file produced by this engine will include the string
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   578
     * "{@code PACK200}" as a zip file comment.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * This allows a deployer to detect if a JAR archive was packed and unpacked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * <p>
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   581
     * Note: Unless otherwise noted, passing a {@code null} argument to a
7171
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 5811
diff changeset
   582
     * constructor or method in this class will cause a {@link NullPointerException}
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 5811
diff changeset
   583
     * to be thrown.
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 5811
diff changeset
   584
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * This version of the unpacker is compatible with all previous versions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public interface Unpacker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        /** The string "keep", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         * @see #DEFLATE_HINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        String KEEP  = "keep";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        /** The string "true", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
         * @see #DEFLATE_HINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        String TRUE = "true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        /** The string "false", a possible value for certain properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
         * @see #DEFLATE_HINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        String FALSE = "false";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
         * Property indicating that the unpacker should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
         * ignore all transmitted values for DEFLATE_HINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
         * replacing them by the given value, {@link #TRUE} or {@link #FALSE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
         * The default value is the special string {@link #KEEP},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         * which asks the unpacker to preserve all transmitted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
         * deflation hints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        String DEFLATE_HINT      = "unpack.deflate.hint";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
         * The unpacker's progress as a percentage, as periodically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
         * updated by the unpacker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
         * Values of 0 - 100 are normal, and -1 indicates a stall.
14192
e218f76e78db 8000362: (pack200) Deprecate Packer/Unpacker addPropertyChangeLister and removePropertyChangeListener methods
alanb
parents: 13795
diff changeset
   621
         * Progress can be monitored by polling the value of this
e218f76e78db 8000362: (pack200) Deprecate Packer/Unpacker addPropertyChangeLister and removePropertyChangeListener methods
alanb
parents: 13795
diff changeset
   622
         * property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
         * At a minimum, the unpacker must set progress to 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         * at the beginning of a packing operation, and to 100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
         * at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        String PROGRESS         = "unpack.progress";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         * Get the set of this engine's properties. This set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         * a "live view", so that changing its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
         * contents immediately affects the Packer engine, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         * changes from the engine (such as progress indications)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
         * are immediately visible in the map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
         * <p>The property map may contain pre-defined implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
         * specific and default properties.  Users are encouraged to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         * read the information and fully understand the implications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
         * before modifying pre-existing properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
         * Implementation specific properties are prefixed with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
         * package name associated with the implementor, beginning
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   644
         * with {@code com.} or a similar prefix.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   645
         * All property names beginning with {@code pack.} and
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 26974
diff changeset
   646
         * {@code unpack.} are reserved for use by this API.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         * Unknown properties may be ignored or rejected with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         * unspecified error, and invalid entries may cause an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
         * unspecified error to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         * @return A sorted association of option key strings to option values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        SortedMap<String,String> properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         * Read a Pack200 archive, and write the encoded JAR to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
         * a JarOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
         * The entire contents of the input stream will be read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
         * It may be more efficient to read the Pack200 archive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
         * to a file and pass the File object, using the alternate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
         * method described below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
         * Closes its input but not its output.  (The output can accumulate more elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
         * @param in an InputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
         * @param out a JarOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
         * @exception IOException if an error is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        void unpack(InputStream in, JarOutputStream out) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
         * Read a Pack200 archive, and write the encoded JAR to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
         * a JarOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
         * Does not close its output.  (The output can accumulate more elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
         * @param in a File.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
         * @param out a JarOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
         * @exception IOException if an error is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        void unpack(File in, JarOutputStream out) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    // Private stuff....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
13795
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 9266
diff changeset
   688
    private static Class<?> packerImpl;
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 9266
diff changeset
   689
    private static Class<?> unpackerImpl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    private synchronized static Object newInstance(String prop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        String implName = "(unknown)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        try {
13795
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 9266
diff changeset
   694
            Class<?> impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            if (impl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                // The first time, we must decide which class to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                implName = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    new sun.security.action.GetPropertyAction(prop,""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                if (implName != null && !implName.equals(""))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    impl = Class.forName(implName);
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7171
diff changeset
   701
                else if (PACK_PROVIDER.equals(prop))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    impl = com.sun.java.util.jar.pack.PackerImpl.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                    impl = com.sun.java.util.jar.pack.UnpackerImpl.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            // We have a class.  Now instantiate it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            return impl.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            throw new Error("Class not found: " + implName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                                ":\ncheck property " + prop +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                                " in your properties file.", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            throw new Error("Could not instantiate: " + implName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                                ":\ncheck property " + prop +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                                " in your properties file.", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            throw new Error("Cannot access class: " + implName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                                ":\ncheck property " + prop +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                                " in your properties file.", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
}