jdk/src/share/classes/java/util/zip/ZipOutputStream.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 9676 5663e62f8d7e
child 16713 7824dded9821
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 9676
diff changeset
     2
 * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2704
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: 2704
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: 2704
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2704
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2704
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 java.util.zip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    30
import java.nio.charset.Charset;
9676
5663e62f8d7e 7041612: Rename StandardCharset to StandardCharsets
mduigou
parents: 9526
diff changeset
    31
import java.nio.charset.StandardCharsets;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.HashSet;
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
    34
import static java.util.zip.ZipConstants64.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This class implements an output stream filter for writing files in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * ZIP file format. Includes support for both compressed and uncompressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author      David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static class XEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        public final ZipEntry entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        public final long offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        public XEntry(ZipEntry entry, long offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            this.entry = entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            this.offset = offset;
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
    private XEntry current;
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 5506
diff changeset
    56
    private Vector<XEntry> xentries = new Vector<>();
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 5506
diff changeset
    57
    private HashSet<String> names = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private CRC32 crc = new CRC32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private long written = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private long locoff = 0;
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    61
    private byte[] comment;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private int method = DEFLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private boolean finished;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private boolean closed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    67
    private final ZipCoder zc;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    68
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static int version(ZipEntry e) throws ZipException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        switch (e.method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        case DEFLATED: return 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        case STORED:   return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        default: throw new ZipException("unsupported compression method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Checks to make sure that this stream has not been closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private void ensureOpen() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throw new IOException("Stream closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Compression method for uncompressed (STORED) entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static final int STORED = ZipEntry.STORED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Compression method for compressed (DEFLATED) entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static final int DEFLATED = ZipEntry.DEFLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Creates a new ZIP output stream.
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    97
     *
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    98
     * <p>The UTF-8 {@link java.nio.charset.Charset charset} is used
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    99
     * to encode the entry names and comments.
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   100
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param out the actual output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public ZipOutputStream(OutputStream out) {
9676
5663e62f8d7e 7041612: Rename StandardCharset to StandardCharsets
mduigou
parents: 9526
diff changeset
   104
        this(out, StandardCharsets.UTF_8);
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   105
    }
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   106
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   107
    /**
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   108
     * Creates a new ZIP output stream.
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   109
     *
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   110
     * @param out the actual output stream
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   111
     *
2704
a92617170304 6836489: Incorrect @link usage in java.util.zip API doc
sherman
parents: 2592
diff changeset
   112
     * @param charset the {@linkplain java.nio.charset.Charset charset}
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   113
     *                to be used to encode the entry names and comments
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   114
     *
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   115
     * @since 1.7
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   116
     */
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   117
    public ZipOutputStream(OutputStream out, Charset charset) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   119
        if (charset == null)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   120
            throw new NullPointerException("charset is null");
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   121
        this.zc = ZipCoder.get(charset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        usesDefaultDeflater = true;
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
     * Sets the ZIP file comment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param comment the comment string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @exception IllegalArgumentException if the length of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *            ZIP file comment is greater than 0xFFFF bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void setComment(String comment) {
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   132
        if (comment != null) {
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   133
            this.comment = zc.getBytes(comment);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   134
            if (this.comment.length > 0xffff)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   135
                throw new IllegalArgumentException("ZIP file comment too long.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
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
     * Sets the default compression method for subsequent entries. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * default will be used whenever the compression method is not specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * for an individual ZIP file entry, and is initially set to DEFLATED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param method the default compression method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @exception IllegalArgumentException if the specified compression method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *            is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public void setMethod(int method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (method != DEFLATED && method != STORED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            throw new IllegalArgumentException("invalid compression method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.method = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Sets the compression level for subsequent entries which are DEFLATED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * The default setting is DEFAULT_COMPRESSION.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param level the compression level (0-9)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @exception IllegalArgumentException if the compression level is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public void setLevel(int level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        def.setLevel(level);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Begins writing a new ZIP file entry and positions the stream to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * start of the entry data. Closes the current entry if still active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * The default compression method will be used if no compression method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * was specified for the entry, and the current time will be used if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * the entry has no set modification time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param e the ZIP entry to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @exception ZipException if a ZIP format error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @exception IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public void putNextEntry(ZipEntry e) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (current != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            closeEntry();       // close previous entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (e.time == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            e.setTime(System.currentTimeMillis());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (e.method == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            e.method = method;  // use default method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   185
        // store size, compressed size, and crc-32 in LOC header
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   186
        e.flag = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        switch (e.method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        case DEFLATED:
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   189
            // store size, compressed size, and crc-32 in data descriptor
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   190
            // immediately following the compressed entry data
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   191
            if (e.size  == -1 || e.csize == -1 || e.crc   == -1)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   192
                e.flag = 8;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   193
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        case STORED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            // compressed size, uncompressed size, and crc-32 must all be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // set for entries using STORED compression method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (e.size == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                e.size = e.csize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            } else if (e.csize == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                e.csize = e.size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            } else if (e.size != e.csize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    "STORED entry where compressed != uncompressed size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if (e.size == -1 || e.crc == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    "STORED entry missing size, compressed size, or crc-32");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            throw new ZipException("unsupported compression method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (! names.add(e.name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new ZipException("duplicate entry: " + e.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   217
        if (zc.isUTF8())
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   218
            e.flag |= EFS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        current = new XEntry(e, written);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        xentries.add(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        writeLOC(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Closes the current ZIP entry and positions the stream for writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * the next entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @exception ZipException if a ZIP format error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @exception IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public void closeEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (current != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            ZipEntry e = current.entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            switch (e.method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            case DEFLATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                def.finish();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                while (!def.finished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    deflate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   240
                if ((e.flag & 8) == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    // verify size, compressed size, and crc-32 settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    if (e.size != def.getBytesRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                            "invalid entry size (expected " + e.size +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            " but got " + def.getBytesRead() + " bytes)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    if (e.csize != def.getBytesWritten()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                            "invalid entry compressed size (expected " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                            e.csize + " but got " + def.getBytesWritten() + " bytes)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    if (e.crc != crc.getValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                        throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                            "invalid entry CRC-32 (expected 0x" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                            Long.toHexString(e.crc) + " but got 0x" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                            Long.toHexString(crc.getValue()) + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    e.size  = def.getBytesRead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    e.csize = def.getBytesWritten();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    e.crc = crc.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    writeEXT(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                def.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                written += e.csize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            case STORED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                // we already know that both e.size and e.csize are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                if (e.size != written - locoff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                        "invalid entry size (expected " + e.size +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                        " but got " + (written - locoff) + " bytes)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                if (e.crc != crc.getValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                         "invalid entry crc-32 (expected 0x" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                         Long.toHexString(e.crc) + " but got 0x" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                         Long.toHexString(crc.getValue()) + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                throw new ZipException("invalid compression method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            crc.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            current = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
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
     * Writes an array of bytes to the current ZIP entry data. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * will block until all the bytes are written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param b the data to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @param off the start offset in the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param len the number of bytes that are written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @exception ZipException if a ZIP file error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @exception IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public synchronized void write(byte[] b, int off, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (off < 0 || len < 0 || off > b.length - len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        } else if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (current == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            throw new ZipException("no current ZIP entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        ZipEntry entry = current.entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        switch (entry.method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        case DEFLATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            super.write(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        case STORED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            written += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            if (written - locoff > entry.size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                throw new ZipException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    "attempt to write past end of STORED entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            out.write(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            throw new ZipException("invalid compression method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        crc.update(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Finishes writing the contents of the ZIP output stream without closing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * the underlying stream. Use this method when applying multiple filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * in succession to the same output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @exception ZipException if a ZIP file error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @exception IOException if an I/O exception has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public void finish() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (finished) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (current != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            closeEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // write central directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        long off = written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        for (XEntry xentry : xentries)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            writeCEN(xentry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        writeEND(off, written - off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        finished = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Closes the ZIP output stream as well as the stream being filtered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @exception ZipException if a ZIP file error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @exception IOException if an I/O error has occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (!closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            closed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Writes local file (LOC) header for specified entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    private void writeLOC(XEntry xentry) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        ZipEntry e = xentry.entry;
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   370
        int flag = e.flag;
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   371
        int elen = (e.extra != null) ? e.extra.length : 0;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   372
        boolean hasZip64 = false;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   373
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   374
        writeInt(LOCSIG);               // LOC header signature
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   375
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if ((flag & 8) == 8) {
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   377
            writeShort(version(e));     // version needed to extract
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   378
            writeShort(flag);           // general purpose bit flag
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   379
            writeShort(e.method);       // compression method
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   380
            writeInt(e.time);           // last modification time
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   381
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            // store size, uncompressed size, and crc-32 in data descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            // immediately following compressed entry data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            writeInt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            writeInt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            writeInt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        } else {
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   388
            if (e.csize >= ZIP64_MAGICVAL || e.size >= ZIP64_MAGICVAL) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   389
                hasZip64 = true;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   390
                writeShort(45);         // ver 4.5 for zip64
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   391
            } else {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   392
                writeShort(version(e)); // version needed to extract
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   393
            }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   394
            writeShort(flag);           // general purpose bit flag
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   395
            writeShort(e.method);       // compression method
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   396
            writeInt(e.time);           // last modification time
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   397
            writeInt(e.crc);            // crc-32
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   398
            if (hasZip64) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   399
                writeInt(ZIP64_MAGICVAL);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   400
                writeInt(ZIP64_MAGICVAL);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   401
                elen += 20;        //headid(2) + size(2) + size(8) + csize(8)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   402
            } else {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   403
                writeInt(e.csize);  // compressed size
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   404
                writeInt(e.size);   // uncompressed size
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   405
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   407
        byte[] nameBytes = zc.getBytes(e.name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        writeShort(nameBytes.length);
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   409
        writeShort(elen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        writeBytes(nameBytes, 0, nameBytes.length);
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   411
        if (hasZip64) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   412
            writeShort(ZIP64_EXTID);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   413
            writeShort(16);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   414
            writeLong(e.size);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   415
            writeLong(e.csize);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   416
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (e.extra != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            writeBytes(e.extra, 0, e.extra.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        locoff = written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Writes extra data descriptor (EXT) for specified entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    private void writeEXT(ZipEntry e) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        writeInt(EXTSIG);           // EXT header signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        writeInt(e.crc);            // crc-32
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   429
        if (e.csize >= ZIP64_MAGICVAL || e.size >= ZIP64_MAGICVAL) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   430
            writeLong(e.csize);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   431
            writeLong(e.size);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   432
        } else {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   433
            writeInt(e.csize);          // compressed size
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   434
            writeInt(e.size);           // uncompressed size
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   435
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Write central directory (CEN) header for specified entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * REMIND: add support for file attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    private void writeCEN(XEntry xentry) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        ZipEntry e  = xentry.entry;
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   444
        int flag = e.flag;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        int version = version(e);
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   446
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   447
        long csize = e.csize;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   448
        long size = e.size;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   449
        long offset = xentry.offset;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   450
        int e64len = 0;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   451
        boolean hasZip64 = false;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   452
        if (e.csize >= ZIP64_MAGICVAL) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   453
            csize = ZIP64_MAGICVAL;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   454
            e64len += 8;              // csize(8)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   455
            hasZip64 = true;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   456
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   457
        if (e.size >= ZIP64_MAGICVAL) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   458
            size = ZIP64_MAGICVAL;    // size(8)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   459
            e64len += 8;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   460
            hasZip64 = true;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   461
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   462
        if (xentry.offset >= ZIP64_MAGICVAL) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   463
            offset = ZIP64_MAGICVAL;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   464
            e64len += 8;              // offset(8)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   465
            hasZip64 = true;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   466
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        writeInt(CENSIG);           // CEN header signature
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   468
        if (hasZip64) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   469
            writeShort(45);         // ver 4.5 for zip64
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   470
            writeShort(45);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   471
        } else {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   472
            writeShort(version);    // version made by
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   473
            writeShort(version);    // version needed to extract
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   474
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        writeShort(flag);           // general purpose bit flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        writeShort(e.method);       // compression method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        writeInt(e.time);           // last modification time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        writeInt(e.crc);            // crc-32
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   479
        writeInt(csize);            // compressed size
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   480
        writeInt(size);             // uncompressed size
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   481
        byte[] nameBytes = zc.getBytes(e.name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        writeShort(nameBytes.length);
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   483
        if (hasZip64) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   484
            // + headid(2) + datasize(2)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   485
            writeShort(e64len + 4 + (e.extra != null ? e.extra.length : 0));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   486
        } else {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   487
            writeShort(e.extra != null ? e.extra.length : 0);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   488
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        byte[] commentBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (e.comment != null) {
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   491
            commentBytes = zc.getBytes(e.comment);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   492
            writeShort(Math.min(commentBytes.length, 0xffff));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            commentBytes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            writeShort(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        writeShort(0);              // starting disk number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        writeShort(0);              // internal file attributes (unused)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        writeInt(0);                // external file attributes (unused)
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   500
        writeInt(offset);           // relative offset of local header
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        writeBytes(nameBytes, 0, nameBytes.length);
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   502
        if (hasZip64) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   503
            writeShort(ZIP64_EXTID);// Zip64 extra
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   504
            writeShort(e64len);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   505
            if (size == ZIP64_MAGICVAL)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   506
                writeLong(e.size);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   507
            if (csize == ZIP64_MAGICVAL)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   508
                writeLong(e.csize);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   509
            if (offset == ZIP64_MAGICVAL)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   510
                writeLong(xentry.offset);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   511
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        if (e.extra != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            writeBytes(e.extra, 0, e.extra.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (commentBytes != null) {
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   516
            writeBytes(commentBytes, 0, Math.min(commentBytes.length, 0xffff));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * Writes end of central directory (END) header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    private void writeEND(long off, long len) throws IOException {
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   524
        boolean hasZip64 = false;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   525
        long xlen = len;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   526
        long xoff = off;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   527
        if (xlen >= ZIP64_MAGICVAL) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   528
            xlen = ZIP64_MAGICVAL;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   529
            hasZip64 = true;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   530
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   531
        if (xoff >= ZIP64_MAGICVAL) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   532
            xoff = ZIP64_MAGICVAL;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   533
            hasZip64 = true;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   534
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        int count = xentries.size();
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   536
        if (count >= ZIP64_MAGICCOUNT) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   537
            count = ZIP64_MAGICCOUNT;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   538
            hasZip64 = true;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   539
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   540
        if (hasZip64) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   541
            long off64 = written;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   542
            //zip64 end of central directory record
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   543
            writeInt(ZIP64_ENDSIG);        // zip64 END record signature
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   544
            writeLong(ZIP64_ENDHDR - 12);  // size of zip64 end
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   545
            writeShort(45);                // version made by
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   546
            writeShort(45);                // version needed to extract
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   547
            writeInt(0);                   // number of this disk
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   548
            writeInt(0);                   // central directory start disk
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   549
            writeLong(xentries.size());    // number of directory entires on disk
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   550
            writeLong(xentries.size());    // number of directory entires
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   551
            writeLong(len);                // length of central directory
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   552
            writeLong(off);                // offset of central directory
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   553
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   554
            //zip64 end of central directory locator
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   555
            writeInt(ZIP64_LOCSIG);        // zip64 END locator signature
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   556
            writeInt(0);                   // zip64 END start disk
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   557
            writeLong(off64);              // offset of zip64 END
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   558
            writeInt(1);                   // total number of disks (?)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   559
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   560
        writeInt(ENDSIG);                 // END record signature
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   561
        writeShort(0);                    // number of this disk
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   562
        writeShort(0);                    // central directory start disk
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   563
        writeShort(count);                // number of directory entries on disk
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   564
        writeShort(count);                // total number of directory entries
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   565
        writeInt(xlen);                   // length of central directory
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   566
        writeInt(xoff);                   // offset of central directory
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   567
        if (comment != null) {            // zip file comment
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   568
            writeShort(comment.length);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   569
            writeBytes(comment, 0, comment.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            writeShort(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Writes a 16-bit short to the output stream in little-endian byte order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    private void writeShort(int v) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        OutputStream out = this.out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        out.write((v >>> 0) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        out.write((v >>> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        written += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * Writes a 32-bit int to the output stream in little-endian byte order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    private void writeInt(long v) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        OutputStream out = this.out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        out.write((int)((v >>>  0) & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        out.write((int)((v >>>  8) & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        out.write((int)((v >>> 16) & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        out.write((int)((v >>> 24) & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        written += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    /*
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   598
     * Writes a 64-bit int to the output stream in little-endian byte order.
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   599
     */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   600
    private void writeLong(long v) throws IOException {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   601
        OutputStream out = this.out;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   602
        out.write((int)((v >>>  0) & 0xff));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   603
        out.write((int)((v >>>  8) & 0xff));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   604
        out.write((int)((v >>> 16) & 0xff));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   605
        out.write((int)((v >>> 24) & 0xff));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   606
        out.write((int)((v >>> 32) & 0xff));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   607
        out.write((int)((v >>> 40) & 0xff));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   608
        out.write((int)((v >>> 48) & 0xff));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   609
        out.write((int)((v >>> 56) & 0xff));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   610
        written += 8;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   611
    }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   612
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 1228
diff changeset
   613
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * Writes an array of bytes to the output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    private void writeBytes(byte[] b, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        super.out.write(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        written += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
}