jdk/src/share/classes/com/sun/java/util/jar/pack/PackerImpl.java
author ksrini
Tue, 16 Oct 2012 12:38:29 -0700
changeset 16076 d7183f4305e5
parent 12857 0a5f341c2a28
child 16107 110e24f9ad05
permissions -rw-r--r--
7186946: Refine unpacker resource usage Reviewed-by: jrose, jjh, mschoene
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
12857
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
     2
 * Copyright (c) 2003, 2012, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.util.jar.pack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    28
import com.sun.java.util.jar.pack.Attribute.Layout;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.PropertyChangeListener;
7192
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    30
import java.io.BufferedInputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    31
import java.io.ByteArrayInputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    32
import java.io.ByteArrayOutputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    33
import java.io.File;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    34
import java.io.FileInputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    35
import java.io.IOException;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    36
import java.io.InputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    37
import java.io.OutputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    38
import java.util.ArrayList;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    39
import java.util.Collections;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    40
import java.util.HashMap;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    41
import java.util.List;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    42
import java.util.ListIterator;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    43
import java.util.Map;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    44
import java.util.SortedMap;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    45
import java.util.TimeZone;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    46
import java.util.jar.JarEntry;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    47
import java.util.jar.JarFile;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    48
import java.util.jar.JarInputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 7171
diff changeset
    49
import java.util.jar.Pack200;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Implementation of the Pack provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author John Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author Kumar Srinivasan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    60
public class PackerImpl  extends TLGlobals implements Pack200.Packer {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Constructs a Packer object and sets the initial state of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * the packer engines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    66
    public PackerImpl() {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Get the set of options for the pack and unpack engines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @return A sorted association of option key strings to option values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
    72
    public SortedMap<String, String> properties() {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    73
        return props;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    //Driver routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Takes a JarFile and converts into a pack-stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Closes its input but not its output.  (Pack200 archives are appendable.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param in a JarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param out an OutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @exception IOException if an error is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 12857
diff changeset
    86
    public synchronized void pack(JarFile in, OutputStream out) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        assert(Utils.currentInstance.get() == null);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    88
        TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    89
                      ? null
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    90
                      : TimeZone.getDefault();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            Utils.currentInstance.set(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    95
            if ("0".equals(props.getProperty(Pack200.Packer.EFFORT))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                Utils.copyJarFile(in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                (new DoPack()).run(in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            Utils.currentInstance.set(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (tz != null) TimeZone.setDefault(tz);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   103
            in.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Takes a JarInputStream and converts into a pack-stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Closes its input but not its output.  (Pack200 archives are appendable.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * The modification time and deflation hint attributes are not available,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * for the jar-manifest file and the directory containing the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @see #MODIFICATION_TIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see #DEFLATION_HINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param in a JarInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param out an OutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @exception IOException if an error is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 12857
diff changeset
   121
    public synchronized void pack(JarInputStream in, OutputStream out) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        assert(Utils.currentInstance.get() == null);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   123
        TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE)) ? null :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            TimeZone.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            Utils.currentInstance.set(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   128
            if ("0".equals(props.getProperty(Pack200.Packer.EFFORT))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                Utils.copyJarFile(in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                (new DoPack()).run(in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            Utils.currentInstance.set(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            if (tz != null) TimeZone.setDefault(tz);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   136
            in.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Register a listener for changes to options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param listener  An object to be invoked when a property is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void addPropertyChangeListener(PropertyChangeListener listener) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   144
        props.addListener(listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Remove a listener for the PropertyChange event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param listener  The PropertyChange listener to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public void removePropertyChangeListener(PropertyChangeListener listener) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   152
        props.removeListener(listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    // All the worker bees.....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    // The packer worker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private class DoPack {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   160
        final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   163
            props.setInteger(Pack200.Packer.PROGRESS, 0);
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   164
            if (verbose > 0) Utils.log.info(props.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
12857
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   167
        // Here's where the bits are collected before getting packed, we also
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   168
        // initialize the version numbers now.
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   169
        final Package pkg = new Package(Package.Version.makeVersion(props, "min.class"),
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   170
                                        Package.Version.makeVersion(props, "max.class"),
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 10115
diff changeset
   171
                                        Package.Version.makeVersion(props, "package"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        final String unknownAttrCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   175
            String uaMode = props.getProperty(Pack200.Packer.UNKNOWN_ATTRIBUTE, Pack200.Packer.PASS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (!(Pack200.Packer.STRIP.equals(uaMode) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                  Pack200.Packer.PASS.equals(uaMode) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                  Pack200.Packer.ERROR.equals(uaMode))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                throw new RuntimeException("Bad option: " + Pack200.Packer.UNKNOWN_ATTRIBUTE + " = " + uaMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            unknownAttrCommand = uaMode.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   184
        final Map<Attribute.Layout, Attribute> attrDefs;
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   185
        final Map<Attribute.Layout, String> attrCommands;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   187
            Map<Attribute.Layout, Attribute> lattrDefs   = new HashMap<>();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   188
            Map<Attribute.Layout, String>  lattrCommands = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            String[] keys = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                Pack200.Packer.CLASS_ATTRIBUTE_PFX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                Pack200.Packer.FIELD_ATTRIBUTE_PFX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                Pack200.Packer.METHOD_ATTRIBUTE_PFX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                Pack200.Packer.CODE_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            int[] ctypes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                Constants.ATTR_CONTEXT_CLASS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                Constants.ATTR_CONTEXT_FIELD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                Constants.ATTR_CONTEXT_METHOD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                Constants.ATTR_CONTEXT_CODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            for (int i = 0; i < ctypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                String pfx = keys[i];
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
   203
                Map<String, String> map = props.prefixMap(pfx);
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
   204
                for (String key : map.keySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    assert(key.startsWith(pfx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    String name = key.substring(pfx.length());
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   207
                    String layout = props.getProperty(key);
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   208
                    Layout lkey = Attribute.keyForLookup(ctypes[i], name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    if (Pack200.Packer.STRIP.equals(layout) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                        Pack200.Packer.PASS.equals(layout) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        Pack200.Packer.ERROR.equals(layout)) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   212
                        lattrCommands.put(lkey, layout.intern());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    } else {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   214
                        Attribute.define(lattrDefs, ctypes[i], name, layout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        if (verbose > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                            Utils.log.fine("Added layout for "+Constants.ATTR_CONTEXT_NAME[i]+" attribute "+name+" = "+layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        }
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   218
                        assert(lattrDefs.containsKey(lkey));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   222
            this.attrDefs = (lattrDefs.isEmpty()) ? null : lattrDefs;
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   223
            this.attrCommands = (lattrCommands.isEmpty()) ? null : lattrCommands;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        final boolean keepFileOrder
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   227
            = props.getBoolean(Pack200.Packer.KEEP_FILE_ORDER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        final boolean keepClassOrder
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   229
            = props.getBoolean(Utils.PACK_KEEP_CLASS_ORDER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        final boolean keepModtime
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   232
            = Pack200.Packer.KEEP.equals(props.getProperty(Pack200.Packer.MODIFICATION_TIME));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        final boolean latestModtime
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   234
            = Pack200.Packer.LATEST.equals(props.getProperty(Pack200.Packer.MODIFICATION_TIME));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        final boolean keepDeflateHint
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   236
            = Pack200.Packer.KEEP.equals(props.getProperty(Pack200.Packer.DEFLATE_HINT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            if (!keepModtime && !latestModtime) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   239
                int modtime = props.getTime(Pack200.Packer.MODIFICATION_TIME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                if (modtime != Constants.NO_MODTIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    pkg.default_modtime = modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (!keepDeflateHint) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   245
                boolean deflate_hint = props.getBoolean(Pack200.Packer.DEFLATE_HINT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                if (deflate_hint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    pkg.default_options |= Constants.AO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        long totalOutputSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        int  segmentCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        long segmentTotalSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        long segmentSize = 0;  // running counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        final long segmentLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            long limit;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   259
            if (props.getProperty(Pack200.Packer.SEGMENT_LIMIT, "").equals(""))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                limit = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            else
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   262
                limit = props.getLong(Pack200.Packer.SEGMENT_LIMIT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            limit = Math.min(Integer.MAX_VALUE, limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            limit = Math.max(-1, limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            if (limit == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                limit = Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            segmentLimit = limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   270
        final List<String> passFiles;  // parsed pack.pass.file options
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            // Which class files will be passed through?
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   273
            passFiles = props.getProperties(Pack200.Packer.PASS_FILE_PFX);
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   274
            for (ListIterator<String> i = passFiles.listIterator(); i.hasNext(); ) {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   275
                String file = i.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                if (file == null) { i.remove(); continue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                file = Utils.getJarEntryName(file);  // normalize '\\' to '/'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                if (file.endsWith("/"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    file = file.substring(0, file.length()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                i.set(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (verbose > 0) Utils.log.info("passFiles = " + passFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            // Hook for testing:  Forces use of special archive modes.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   287
            int opt = props.getInteger(Utils.COM_PREFIX+"archive.options");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (opt != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                pkg.default_options |= opt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   292
        // (Done collecting options from props.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        boolean isClassFile(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (!name.endsWith(".class"))  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            for (String prefix = name; ; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                if (passFiles.contains(prefix))  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                int chop = prefix.lastIndexOf('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                if (chop < 0)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                prefix = prefix.substring(0, chop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        boolean isMetaInfFile(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            return name.startsWith("/" + Utils.METAINF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        name.startsWith(Utils.METAINF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        // Get a new package, based on the old one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        private void makeNextPackage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            pkg.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   315
        final class InFile {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            final JarFile jf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            final JarEntry je;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            final File f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            int modtime = Constants.NO_MODTIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            int options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            InFile(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                this.name = Utils.getJarEntryName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                this.f = new File(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                this.jf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                this.je = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                int timeSecs = getModtime(f.lastModified());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                if (keepModtime && timeSecs != Constants.NO_MODTIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    this.modtime = timeSecs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                } else if (latestModtime && timeSecs > pkg.default_modtime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    pkg.default_modtime = timeSecs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            InFile(JarFile jf, JarEntry je) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                this.name = Utils.getJarEntryName(je.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                this.f = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                this.jf = jf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                this.je = je;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                int timeSecs = getModtime(je.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                if (keepModtime && timeSecs != Constants.NO_MODTIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                     this.modtime = timeSecs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                } else if (latestModtime && timeSecs > pkg.default_modtime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    pkg.default_modtime = timeSecs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                if (keepDeflateHint && je.getMethod() == JarEntry.DEFLATED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    options |= Constants.FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            InFile(JarEntry je) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                this(null, je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            long getInputLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                long len = (je != null)? je.getSize(): f.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                assert(len >= 0) : this+".len="+len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                // Bump size by pathname length and modtime/def-hint bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                return Math.max(0, len) + name.length() + 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            int getModtime(long timeMillis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                // Convert milliseconds to seconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                long seconds = (timeMillis+500) / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                if ((int)seconds == seconds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    return (int)seconds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    Utils.log.warning("overflow in modtime for "+f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    return Constants.NO_MODTIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            void copyTo(Package.File file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                if (modtime != Constants.NO_MODTIME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    file.modtime = modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                file.options |= options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            InputStream getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                if (jf != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    return jf.getInputStream(je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    return new FileInputStream(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        private int nread = 0;  // used only if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        private void noteRead(InFile f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            nread++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (verbose > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                Utils.log.fine("...read "+f.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            if (verbose > 0 && (nread % 1000) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                Utils.log.info("Have read "+nread+" files...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        void run(JarInputStream in, OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            // First thing we do is get the manifest, as JIS does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            // not provide the Manifest as an entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            if (in.getManifest() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                ByteArrayOutputStream tmp = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                in.getManifest().write(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                InFile inFile = new InFile(je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                String name = inFile.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                Package.File bits = readFile(name, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                Package.File file = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                // (5078608) : discount the resource files in META-INF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                // from segment computation.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   411
                long inflen = (isMetaInfFile(name))
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   412
                              ? 0L
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   413
                              : inFile.getInputLength();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                if ((segmentSize += inflen) > segmentLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    segmentSize -= inflen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    int nextCount = -1;  // don't know; it's a stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    flushPartial(out, nextCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                }
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   420
                if (verbose > 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    Utils.log.fine("Reading " + name);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   422
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                assert(je.isDirectory() == name.endsWith("/"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                if (isClassFile(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    file = readClass(name, bits.getInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    file = bits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    pkg.addFile(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                inFile.copyTo(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                noteRead(inFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            flushAll(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        void run(JarFile in, OutputStream out) throws IOException {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   440
            List<InFile> inFiles = scanJar(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                Utils.log.info("Reading " + inFiles.size() + " files...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            int numDone = 0;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   446
            for (InFile inFile : inFiles) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                String name      = inFile.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                // (5078608) : discount the resource files completely from segmenting
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   449
                long inflen = (isMetaInfFile(name))
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   450
                               ? 0L
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   451
                               : inFile.getInputLength() ;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                if ((segmentSize += inflen) > segmentLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    segmentSize -= inflen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    // Estimate number of remaining segments:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    float filesDone = numDone+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    float segsDone  = segmentCount+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    float filesToDo = inFiles.size() - filesDone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    float segsToDo  = filesToDo * (segsDone/filesDone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    if (verbose > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        Utils.log.fine("Estimated segments to do: "+segsToDo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    flushPartial(out, (int) Math.ceil(segsToDo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                InputStream strm = inFile.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                if (verbose > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    Utils.log.fine("Reading " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                Package.File file = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                if (isClassFile(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    file = readClass(name, strm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        strm.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        strm = inFile.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    file = readFile(name, strm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    pkg.addFile(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                inFile.copyTo(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                strm.close();  // tidy up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                noteRead(inFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                numDone += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            flushAll(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        Package.File readClass(String fname, InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            Package.Class cls = pkg.new Class(fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            in = new BufferedInputStream(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            ClassReader reader = new ClassReader(cls, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            reader.setAttrDefs(attrDefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            reader.setAttrCommands(attrCommands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            reader.unknownAttrCommand = unknownAttrCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                reader.read();
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   495
            } catch (IOException ioe) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   496
                String message = "Passing class file uncompressed due to";
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   497
                if (ioe instanceof Attribute.FormatException) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   498
                    Attribute.FormatException ee = (Attribute.FormatException) ioe;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   499
                    // He passed up the category to us in layout.
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   500
                    if (ee.layout.equals(Pack200.Packer.PASS)) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   501
                        Utils.log.info(ee.toString());
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   502
                        Utils.log.warning(message + " unrecognized attribute: " +
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   503
                                fname);
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   504
                        return null;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   505
                    }
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   506
                } else if (ioe instanceof ClassReader.ClassFormatException) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   507
                    ClassReader.ClassFormatException ce = (ClassReader.ClassFormatException) ioe;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   508
                    // %% TODO: Do we invent a new property for this or reuse %%
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   509
                    if (unknownAttrCommand.equals(Pack200.Packer.PASS)) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   510
                        Utils.log.info(ce.toString());
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   511
                        Utils.log.warning(message + " unknown class format: " +
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   512
                                fname);
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   513
                        return null;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   514
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                // Otherwise, it must be an error.
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   517
                throw ioe;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            pkg.addClass(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            return cls.file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        // Read raw data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        Package.File readFile(String fname, InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            Package.File file = pkg.new File(fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            file.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            if (file.isDirectory() && file.getFileLength() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                throw new IllegalArgumentException("Non-empty directory: "+file.getFileName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            return file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        void flushPartial(OutputStream out, int nextCount) throws IOException {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   534
            if (pkg.files.isEmpty() && pkg.classes.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                return;  // do not flush an empty segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            flushPackage(out, Math.max(1, nextCount));
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   538
            props.setInteger(Pack200.Packer.PROGRESS, 25);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            // In case there will be another segment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            makeNextPackage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            segmentCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            segmentTotalSize += segmentSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            segmentSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        void flushAll(OutputStream out) throws IOException {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   547
            props.setInteger(Pack200.Packer.PROGRESS, 50);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            flushPackage(out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            out.flush();
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   550
            props.setInteger(Pack200.Packer.PROGRESS, 100);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            segmentCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            segmentTotalSize += segmentSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            segmentSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            if (verbose > 0 && segmentCount > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                Utils.log.info("Transmitted "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                 +segmentTotalSize+" input bytes in "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                 +segmentCount+" segments totaling "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                                 +totalOutputSize+" bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        /** Write all information in the current package segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
         *  to the output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        void flushPackage(OutputStream out, int nextCount) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            int nfiles = pkg.files.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            if (!keepFileOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                // Keeping the order of classes costs about 1%
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                // Keeping the order of all files costs something more.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                if (verbose > 1)  Utils.log.fine("Reordering files.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                boolean stripDirectories = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                pkg.reorderFiles(keepClassOrder, stripDirectories);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                // Package builder must have created a stub for each class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                assert(pkg.files.containsAll(pkg.getClassStubs()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                // Order of stubs in file list must agree with classes.
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   578
                List<Package.File> res = pkg.files;
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   579
                assert((res = new ArrayList<>(pkg.files))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                       .retainAll(pkg.getClassStubs()) || true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                assert(res.equals(pkg.getClassStubs()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            pkg.trimStubs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            // Do some stripping, maybe.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   586
            if (props.getBoolean(Utils.COM_PREFIX+"strip.debug"))        pkg.stripAttributeKind("Debug");
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   587
            if (props.getBoolean(Utils.COM_PREFIX+"strip.compile"))      pkg.stripAttributeKind("Compile");
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   588
            if (props.getBoolean(Utils.COM_PREFIX+"strip.constants"))    pkg.stripAttributeKind("Constant");
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   589
            if (props.getBoolean(Utils.COM_PREFIX+"strip.exceptions"))   pkg.stripAttributeKind("Exceptions");
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   590
            if (props.getBoolean(Utils.COM_PREFIX+"strip.innerclasses")) pkg.stripAttributeKind("InnerClasses");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            PackageWriter pw = new PackageWriter(pkg, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            pw.archiveNextCount = nextCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            pw.write();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            if (verbose > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                long outSize = pw.archiveSize0+pw.archiveSize1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                totalOutputSize += outSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                long inSize = segmentSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                Utils.log.info("Transmitted "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                                 +nfiles+" files of "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                                 +inSize+" input bytes in a segment of "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                                 +outSize+" bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   607
        List<InFile> scanJar(JarFile jf) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            // Collect jar entries, preserving order.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   609
            List<InFile> inFiles = new ArrayList<>();
7171
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   610
            try {
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   611
                for (JarEntry je : Collections.list(jf.entries())) {
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   612
                    InFile inFile = new InFile(jf, je);
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   613
                    assert(je.isDirectory() == inFile.name.endsWith("/"));
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   614
                    inFiles.add(inFile);
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   615
                }
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   616
            } catch (IllegalStateException ise) {
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   617
                throw new IOException(ise.getLocalizedMessage(), ise);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            return inFiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
}