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