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