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