jdk/src/share/classes/com/sun/java/util/jar/pack/PackerImpl.java
author ksrini
Fri, 08 Jul 2011 10:25:57 -0700
changeset 10115 eb08d08c7ef7
parent 7795 98021fc612af
child 12857 0a5f341c2a28
permissions -rw-r--r--
7060849: Eliminate pack200 build warnings Reviewed-by: ksrini, jjg Contributed-by: alexandre.boulgakov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
     2
 * Copyright (c) 2003, 2011, 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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public void pack(JarFile in, OutputStream out) throws IOException {
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public void pack(JarInputStream in, OutputStream out) throws IOException {
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        // Here's where the bits are collected before getting packed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        final Package pkg = new Package();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        final String unknownAttrCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   172
            String uaMode = props.getProperty(Pack200.Packer.UNKNOWN_ATTRIBUTE, Pack200.Packer.PASS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (!(Pack200.Packer.STRIP.equals(uaMode) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                  Pack200.Packer.PASS.equals(uaMode) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                  Pack200.Packer.ERROR.equals(uaMode))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                throw new RuntimeException("Bad option: " + Pack200.Packer.UNKNOWN_ATTRIBUTE + " = " + uaMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            unknownAttrCommand = uaMode.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   181
        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
   182
        final Map<Attribute.Layout, String> attrCommands;
2
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
            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
   185
            Map<Attribute.Layout, String>  lattrCommands = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            String[] keys = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                Pack200.Packer.CLASS_ATTRIBUTE_PFX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                Pack200.Packer.FIELD_ATTRIBUTE_PFX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                Pack200.Packer.METHOD_ATTRIBUTE_PFX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                Pack200.Packer.CODE_ATTRIBUTE_PFX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            int[] ctypes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                Constants.ATTR_CONTEXT_CLASS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                Constants.ATTR_CONTEXT_FIELD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                Constants.ATTR_CONTEXT_METHOD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                Constants.ATTR_CONTEXT_CODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            for (int i = 0; i < ctypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                String pfx = keys[i];
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
   200
                Map<String, String> map = props.prefixMap(pfx);
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
   201
                for (String key : map.keySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    assert(key.startsWith(pfx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    String name = key.substring(pfx.length());
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   204
                    String layout = props.getProperty(key);
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   205
                    Layout lkey = Attribute.keyForLookup(ctypes[i], name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    if (Pack200.Packer.STRIP.equals(layout) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        Pack200.Packer.PASS.equals(layout) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        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
   209
                        lattrCommands.put(lkey, layout.intern());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    } else {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   211
                        Attribute.define(lattrDefs, ctypes[i], name, layout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        if (verbose > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                            Utils.log.fine("Added layout for "+Constants.ATTR_CONTEXT_NAME[i]+" attribute "+name+" = "+layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        }
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   215
                        assert(lattrDefs.containsKey(lkey));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   219
            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
   220
            this.attrCommands = (lattrCommands.isEmpty()) ? null : lattrCommands;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        final boolean keepFileOrder
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   224
            = props.getBoolean(Pack200.Packer.KEEP_FILE_ORDER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        final boolean keepClassOrder
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   226
            = props.getBoolean(Utils.PACK_KEEP_CLASS_ORDER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        final boolean keepModtime
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   229
            = Pack200.Packer.KEEP.equals(props.getProperty(Pack200.Packer.MODIFICATION_TIME));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        final boolean latestModtime
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   231
            = Pack200.Packer.LATEST.equals(props.getProperty(Pack200.Packer.MODIFICATION_TIME));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        final boolean keepDeflateHint
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   233
            = Pack200.Packer.KEEP.equals(props.getProperty(Pack200.Packer.DEFLATE_HINT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (!keepModtime && !latestModtime) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   236
                int modtime = props.getTime(Pack200.Packer.MODIFICATION_TIME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                if (modtime != Constants.NO_MODTIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    pkg.default_modtime = modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (!keepDeflateHint) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   242
                boolean deflate_hint = props.getBoolean(Pack200.Packer.DEFLATE_HINT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                if (deflate_hint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    pkg.default_options |= Constants.AO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        long totalOutputSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        int  segmentCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        long segmentTotalSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        long segmentSize = 0;  // running counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        final long segmentLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            long limit;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   256
            if (props.getProperty(Pack200.Packer.SEGMENT_LIMIT, "").equals(""))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                limit = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            else
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   259
                limit = props.getLong(Pack200.Packer.SEGMENT_LIMIT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            limit = Math.min(Integer.MAX_VALUE, limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            limit = Math.max(-1, limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if (limit == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                limit = Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            segmentLimit = limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   267
        final List<String> passFiles;  // parsed pack.pass.file options
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            // Which class files will be passed through?
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   270
            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
   271
            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
   272
                String file = i.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                if (file == null) { i.remove(); continue; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                file = Utils.getJarEntryName(file);  // normalize '\\' to '/'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                if (file.endsWith("/"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    file = file.substring(0, file.length()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                i.set(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (verbose > 0) Utils.log.info("passFiles = " + passFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            // Fill in permitted range of major/minor version numbers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            int ver;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   285
            if ((ver = props.getInteger(Utils.COM_PREFIX+"min.class.majver")) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                pkg.min_class_majver = (short) ver;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   287
            if ((ver = props.getInteger(Utils.COM_PREFIX+"min.class.minver")) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                pkg.min_class_minver = (short) ver;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   289
            if ((ver = props.getInteger(Utils.COM_PREFIX+"max.class.majver")) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                pkg.max_class_majver = (short) ver;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   291
            if ((ver = props.getInteger(Utils.COM_PREFIX+"max.class.minver")) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                pkg.max_class_minver = (short) ver;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   293
            if ((ver = props.getInteger(Utils.COM_PREFIX+"package.minver")) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                pkg.package_minver = (short) ver;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   295
            if ((ver = props.getInteger(Utils.COM_PREFIX+"package.majver")) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                pkg.package_majver = (short) ver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            // Hook for testing:  Forces use of special archive modes.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   301
            int opt = props.getInteger(Utils.COM_PREFIX+"archive.options");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (opt != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                pkg.default_options |= opt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   306
        // (Done collecting options from props.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        boolean isClassFile(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            if (!name.endsWith(".class"))  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            for (String prefix = name; ; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                if (passFiles.contains(prefix))  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                int chop = prefix.lastIndexOf('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                if (chop < 0)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                prefix = prefix.substring(0, chop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        boolean isMetaInfFile(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            return name.startsWith("/" + Utils.METAINF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        name.startsWith(Utils.METAINF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // Get a new package, based on the old one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        private void makeNextPackage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            pkg.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   329
        final class InFile {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            final JarFile jf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            final JarEntry je;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            final File f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            int modtime = Constants.NO_MODTIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            int options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            InFile(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                this.name = Utils.getJarEntryName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                this.f = new File(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                this.jf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                this.je = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                int timeSecs = getModtime(f.lastModified());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                if (keepModtime && timeSecs != Constants.NO_MODTIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    this.modtime = timeSecs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                } else if (latestModtime && timeSecs > pkg.default_modtime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    pkg.default_modtime = timeSecs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            InFile(JarFile jf, JarEntry je) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                this.name = Utils.getJarEntryName(je.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                this.f = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                this.jf = jf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                this.je = je;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                int timeSecs = getModtime(je.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                if (keepModtime && timeSecs != Constants.NO_MODTIME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                     this.modtime = timeSecs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                } else if (latestModtime && timeSecs > pkg.default_modtime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    pkg.default_modtime = timeSecs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                if (keepDeflateHint && je.getMethod() == JarEntry.DEFLATED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    options |= Constants.FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            InFile(JarEntry je) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                this(null, je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            long getInputLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                long len = (je != null)? je.getSize(): f.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                assert(len >= 0) : this+".len="+len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                // Bump size by pathname length and modtime/def-hint bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                return Math.max(0, len) + name.length() + 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            int getModtime(long timeMillis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                // Convert milliseconds to seconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                long seconds = (timeMillis+500) / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                if ((int)seconds == seconds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    return (int)seconds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    Utils.log.warning("overflow in modtime for "+f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    return Constants.NO_MODTIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            void copyTo(Package.File file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                if (modtime != Constants.NO_MODTIME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    file.modtime = modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                file.options |= options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            InputStream getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                if (jf != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    return jf.getInputStream(je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    return new FileInputStream(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        private int nread = 0;  // used only if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        private void noteRead(InFile f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            nread++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            if (verbose > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                Utils.log.fine("...read "+f.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            if (verbose > 0 && (nread % 1000) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                Utils.log.info("Have read "+nread+" files...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        void run(JarInputStream in, OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            // First thing we do is get the manifest, as JIS does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            // not provide the Manifest as an entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (in.getManifest() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                ByteArrayOutputStream tmp = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                in.getManifest().write(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                InFile inFile = new InFile(je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                String name = inFile.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                Package.File bits = readFile(name, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                Package.File file = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                // (5078608) : discount the resource files in META-INF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                // from segment computation.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   425
                long inflen = (isMetaInfFile(name))
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   426
                              ? 0L
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   427
                              : inFile.getInputLength();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                if ((segmentSize += inflen) > segmentLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    segmentSize -= inflen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    int nextCount = -1;  // don't know; it's a stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    flushPartial(out, nextCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                }
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   434
                if (verbose > 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    Utils.log.fine("Reading " + name);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   436
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                assert(je.isDirectory() == name.endsWith("/"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                if (isClassFile(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    file = readClass(name, bits.getInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    file = bits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    pkg.addFile(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                inFile.copyTo(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                noteRead(inFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            flushAll(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        void run(JarFile in, OutputStream out) throws IOException {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   454
            List<InFile> inFiles = scanJar(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                Utils.log.info("Reading " + inFiles.size() + " files...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            int numDone = 0;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   460
            for (InFile inFile : inFiles) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                String name      = inFile.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                // (5078608) : discount the resource files completely from segmenting
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   463
                long inflen = (isMetaInfFile(name))
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   464
                               ? 0L
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   465
                               : inFile.getInputLength() ;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                if ((segmentSize += inflen) > segmentLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    segmentSize -= inflen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    // Estimate number of remaining segments:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    float filesDone = numDone+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    float segsDone  = segmentCount+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    float filesToDo = inFiles.size() - filesDone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    float segsToDo  = filesToDo * (segsDone/filesDone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    if (verbose > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        Utils.log.fine("Estimated segments to do: "+segsToDo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    flushPartial(out, (int) Math.ceil(segsToDo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                InputStream strm = inFile.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                if (verbose > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    Utils.log.fine("Reading " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                Package.File file = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                if (isClassFile(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    file = readClass(name, strm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                        strm.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        strm = inFile.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    file = readFile(name, strm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    pkg.addFile(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                inFile.copyTo(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                strm.close();  // tidy up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                noteRead(inFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                numDone += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            flushAll(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        Package.File readClass(String fname, InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            Package.Class cls = pkg.new Class(fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            in = new BufferedInputStream(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            ClassReader reader = new ClassReader(cls, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            reader.setAttrDefs(attrDefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            reader.setAttrCommands(attrCommands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            reader.unknownAttrCommand = unknownAttrCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                reader.read();
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   509
            } catch (IOException ioe) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   510
                String message = "Passing class file uncompressed due to";
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   511
                if (ioe instanceof Attribute.FormatException) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   512
                    Attribute.FormatException ee = (Attribute.FormatException) ioe;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   513
                    // He passed up the category to us in layout.
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   514
                    if (ee.layout.equals(Pack200.Packer.PASS)) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   515
                        Utils.log.info(ee.toString());
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   516
                        Utils.log.warning(message + " unrecognized attribute: " +
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   517
                                fname);
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   518
                        return null;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   519
                    }
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   520
                } else if (ioe instanceof ClassReader.ClassFormatException) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   521
                    ClassReader.ClassFormatException ce = (ClassReader.ClassFormatException) ioe;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   522
                    // %% 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
   523
                    if (unknownAttrCommand.equals(Pack200.Packer.PASS)) {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   524
                        Utils.log.info(ce.toString());
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   525
                        Utils.log.warning(message + " unknown class format: " +
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   526
                                fname);
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   527
                        return null;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   528
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                // Otherwise, it must be an error.
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents: 6313
diff changeset
   531
                throw ioe;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            pkg.addClass(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            return cls.file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        // Read raw data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        Package.File readFile(String fname, InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            Package.File file = pkg.new File(fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            file.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            if (file.isDirectory() && file.getFileLength() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                throw new IllegalArgumentException("Non-empty directory: "+file.getFileName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        void flushPartial(OutputStream out, int nextCount) throws IOException {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   548
            if (pkg.files.isEmpty() && pkg.classes.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                return;  // do not flush an empty segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            flushPackage(out, Math.max(1, nextCount));
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   552
            props.setInteger(Pack200.Packer.PROGRESS, 25);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            // In case there will be another segment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            makeNextPackage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            segmentCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            segmentTotalSize += segmentSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            segmentSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        void flushAll(OutputStream out) throws IOException {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   561
            props.setInteger(Pack200.Packer.PROGRESS, 50);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            flushPackage(out, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            out.flush();
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   564
            props.setInteger(Pack200.Packer.PROGRESS, 100);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            segmentCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            segmentTotalSize += segmentSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            segmentSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            if (verbose > 0 && segmentCount > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                Utils.log.info("Transmitted "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                 +segmentTotalSize+" input bytes in "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                 +segmentCount+" segments totaling "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                 +totalOutputSize+" bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        /** Write all information in the current package segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
         *  to the output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        void flushPackage(OutputStream out, int nextCount) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            int nfiles = pkg.files.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            if (!keepFileOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                // Keeping the order of classes costs about 1%
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                // Keeping the order of all files costs something more.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                if (verbose > 1)  Utils.log.fine("Reordering files.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                boolean stripDirectories = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                pkg.reorderFiles(keepClassOrder, stripDirectories);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                // Package builder must have created a stub for each class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                assert(pkg.files.containsAll(pkg.getClassStubs()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                // 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
   592
                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
   593
                assert((res = new ArrayList<>(pkg.files))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                       .retainAll(pkg.getClassStubs()) || true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                assert(res.equals(pkg.getClassStubs()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            pkg.trimStubs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            // Do some stripping, maybe.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   600
            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
   601
            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
   602
            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
   603
            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
   604
            if (props.getBoolean(Utils.COM_PREFIX+"strip.innerclasses")) pkg.stripAttributeKind("InnerClasses");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            // Must choose an archive version; PackageWriter does not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            if (pkg.package_majver <= 0)  pkg.choosePackageVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            PackageWriter pw = new PackageWriter(pkg, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            pw.archiveNextCount = nextCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            pw.write();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            if (verbose > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                long outSize = pw.archiveSize0+pw.archiveSize1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                totalOutputSize += outSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                long inSize = segmentSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                Utils.log.info("Transmitted "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                                 +nfiles+" files of "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                                 +inSize+" input bytes in a segment of "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                                 +outSize+" bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   624
        List<InFile> scanJar(JarFile jf) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            // Collect jar entries, preserving order.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   626
            List<InFile> inFiles = new ArrayList<>();
7171
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   627
            try {
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   628
                for (JarEntry je : Collections.list(jf.entries())) {
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   629
                    InFile inFile = new InFile(jf, je);
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   630
                    assert(je.isDirectory() == inFile.name.endsWith("/"));
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   631
                    inFiles.add(inFile);
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   632
                }
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   633
            } catch (IllegalStateException ise) {
ee97f78e7482 6985763: Pack200.Packer.pack(...) and Pack200.Unpacker.unpack(...) throw unspecified exceptions
ksrini
parents: 6900
diff changeset
   634
                throw new IOException(ise.getLocalizedMessage(), ise);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            return inFiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
}