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