jdk/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java
author ksrini
Thu, 19 Aug 2010 14:08:04 -0700
changeset 6313 470912c9e214
parent 5506 202f599c92aa
child 7171 ee97f78e7482
permissions -rw-r--r--
6888127: java.util.jar.Pack200.Packer Memory Leak Reviewed-by: jrose
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.jar.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.zip.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Implementation of the Pack provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author John Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Kumar Srinivasan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    42
public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Register a listener for changes to options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * @param listener  An object to be invoked when a property is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public void addPropertyChangeListener(PropertyChangeListener listener) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    50
        props.addListener(listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Remove a listener for the PropertyChange event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param listener  The PropertyChange listener to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public void removePropertyChangeListener(PropertyChangeListener listener) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    59
        props.removeListener(listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    62
    public UnpackerImpl() {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Get the set of options for the pack and unpack engines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @return A sorted association of option key strings to option values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    70
    public SortedMap<String, String> properties() {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    71
        return props;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // Back-pointer to NativeUnpacker, when active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    Object _nunp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return Utils.getVersionString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    //Driver routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // The unpack worker...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Takes a packed-stream InputStream, and writes to a JarOutputStream. Internally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * the entire buffer must be read, it may be more efficient to read the packed-stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * to a file and pass the File object, in the alternate method described below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Closes its input but not its output.  (The output can accumulate more elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param in an InputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param out a JarOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @exception IOException if an error is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public void unpack(InputStream in0, JarOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        assert(Utils.currentInstance.get() == null);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    97
        TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    98
                      ? null
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    99
                      : TimeZone.getDefault();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            Utils.currentInstance.set(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   104
            final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            BufferedInputStream in = new BufferedInputStream(in0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            if (Utils.isJarMagic(Utils.readMagic(in))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    Utils.log.info("Copying unpacked JAR file...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                Utils.copyJarFile(new JarInputStream(in), out);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   110
            } else if (props.getBoolean(Utils.DEBUG_DISABLE_NATIVE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                (new DoUnpack()).run(in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                Utils.markJarFile(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                (new NativeUnpack(this)).run(in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                Utils.markJarFile(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            _nunp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            Utils.currentInstance.set(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            if (tz != null) TimeZone.setDefault(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Takes an input File containing the pack file, and generates a JarOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Does not close its output.  (The output can accumulate more elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param in a File.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param out a JarOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @exception IOException if an error is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void unpack(File in, JarOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // Use the stream-based implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // %%% Reconsider if native unpacker learns to memory-map the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        FileInputStream instr = new FileInputStream(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        unpack(instr, out);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   139
        if (props.getBoolean(Utils.UNPACK_REMOVE_PACKFILE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            in.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private class DoUnpack {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   145
        final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   148
            props.setInteger(Pack200.Unpacker.PROGRESS, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // Here's where the bits are read from disk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        final Package pkg = new Package();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        final boolean keepModtime
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   155
            = Pack200.Packer.KEEP.equals(
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   156
              props.getProperty(Utils.UNPACK_MODIFICATION_TIME, Pack200.Packer.KEEP));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        final boolean keepDeflateHint
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   158
            = Pack200.Packer.KEEP.equals(
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   159
              props.getProperty(Pack200.Unpacker.DEFLATE_HINT, Pack200.Packer.KEEP));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        final int modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        final boolean deflateHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            if (!keepModtime) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   164
                modtime = props.getTime(Utils.UNPACK_MODIFICATION_TIME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                modtime = pkg.default_modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            deflateHint = (keepDeflateHint) ? false :
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   170
                props.getBoolean(java.util.jar.Pack200.Unpacker.DEFLATE_HINT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        // Checksum apparatus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        final CRC32 crc = new CRC32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        final ByteArrayOutputStream bufOut = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        final OutputStream crcOut = new CheckedOutputStream(bufOut, crc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        public void run(BufferedInputStream in, JarOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (verbose > 0) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   180
                props.list(System.out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            for (int seg = 1; ; seg++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                unpackSegment(in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                // Try to get another segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                if (!Utils.isPackMagic(Utils.readMagic(in)))  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    Utils.log.info("Finished segment #"+seg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        private void unpackSegment(InputStream in, JarOutputStream out) throws IOException {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   193
            props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"0");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            // Process the output directory or jar output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            new PackageReader(pkg, in).read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   197
            if (props.getBoolean("unpack.strip.debug"))    pkg.stripAttributeKind("Debug");
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   198
            if (props.getBoolean("unpack.strip.compile"))  pkg.stripAttributeKind("Compile");
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   199
            props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"50");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            pkg.ensureAllClassFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            // Now write out the files.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   202
            HashSet<Package.Class> classesToWrite = new HashSet<>(pkg.getClasses());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            for (Iterator i = pkg.getFiles().iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                Package.File file = (Package.File) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                String name = file.nameString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                JarEntry je = new JarEntry(Utils.getJarEntryName(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                boolean deflate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   209
                deflate = (keepDeflateHint)
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   210
                          ? (((file.options & Constants.FO_DEFLATE_HINT) != 0) ||
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   211
                            ((pkg.default_options & Constants.AO_DEFLATE_HINT) != 0))
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   212
                          : deflateHint;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                boolean needCRC = !deflate;  // STORE mode requires CRC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                if (needCRC)  crc.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                bufOut.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                if (file.isClassStub()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    Package.Class cls = file.getStubClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    assert(cls != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    new ClassWriter(cls, needCRC ? crcOut : bufOut).write();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    classesToWrite.remove(cls);  // for an error check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    // collect data & maybe CRC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    file.writeTo(needCRC ? crcOut : bufOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                je.setMethod(deflate ? JarEntry.DEFLATED : JarEntry.STORED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                if (needCRC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        Utils.log.info("stored size="+bufOut.size()+" and crc="+crc.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    je.setMethod(JarEntry.STORED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    je.setSize(bufOut.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    je.setCrc(crc.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if (keepModtime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    je.setTime(file.modtime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    // Convert back to milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    je.setTime((long)file.modtime * 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    je.setTime((long)modtime * 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                out.putNextEntry(je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                bufOut.writeTo(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                out.closeEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    Utils.log.info("Writing "+Utils.zeString((ZipEntry)je));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            assert(classesToWrite.isEmpty());
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   250
            props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"100");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            pkg.reset();  // reset for the next segment, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}