jdk/src/share/classes/java/util/zip/ZipEntry.java
author herrick
Wed, 09 Feb 2011 09:19:33 -0500
changeset 8197 e45f21c2a40b
parent 5506 202f599c92aa
child 8552 f36470084574
permissions -rw-r--r--
7016724: Remove sun.jkernel.* classes in JDK 7 Summary: Remove sun.jkernel.* classes in JDK 7 Reviewed-by: ohair, alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3958
diff changeset
     2
 * Copyright (c) 1995, 2009, 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: 3958
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: 3958
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: 3958
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3958
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3958
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.util.Date;
3958
b8acd5ee4f4f 6612680: Remove classloader dependency on jkernel
mchung
parents: 3844
diff changeset
    29
import sun.misc.BootClassLoaderHook;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This class is used to represent a ZIP file entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @author      David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
class ZipEntry implements ZipConstants, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    String name;        // entry name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    long time = -1;     // modification time (in DOS time)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    long crc = -1;      // crc-32 of entry data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    long size = -1;     // uncompressed size of entry data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    long csize = -1;    // compressed size of entry data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    int method = -1;    // compression method
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    44
    int flag = 0;       // general purpose flag
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    byte[] extra;       // optional extra field data for entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    String comment;     // optional comment string for entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Compression method for uncompressed entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final int STORED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Compression method for compressed (deflated) entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static final int DEFLATED = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Creates a new zip entry with the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param name the entry name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @exception NullPointerException if the entry name is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @exception IllegalArgumentException if the entry name is longer than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *            0xFFFF bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public ZipEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (name.length() > 0xFFFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            throw new IllegalArgumentException("entry name too long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.name = name;
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
     * Creates a new zip entry with fields taken from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * zip entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param e a zip Entry object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public ZipEntry(ZipEntry e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        name = e.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        time = e.time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        crc = e.crc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        size = e.size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        csize = e.csize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        method = e.method;
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    88
        flag = e.flag;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        extra = e.extra;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        comment = e.comment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /*
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    94
     * Creates a new un-initialized zip entry
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
    96
    ZipEntry() {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Returns the name of the entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @return the name of the entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Sets the modification time of the entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param time the entry modification time in number of milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *             since the epoch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see #getTime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public void setTime(long time) {
8197
e45f21c2a40b 7016724: Remove sun.jkernel.* classes in JDK 7
herrick
parents: 5506
diff changeset
   113
        this.time = javaToDosTime(time);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Returns the modification time of the entry, or -1 if not specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return the modification time of the entry, or -1 if not specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @see #setTime(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public long getTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return time != -1 ? dosToJavaTime(time) : -1;
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 uncompressed size of the entry data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param size the uncompressed size in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @exception IllegalArgumentException if the specified size is less
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   129
     *            than 0, is greater than 0xFFFFFFFF when
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   130
     *            <a href="package-summary.html#zip64">ZIP64 format</a> is not supported,
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   131
     *            or is less than 0 when ZIP64 is supported
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see #getSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void setSize(long size) {
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2
diff changeset
   135
        if (size < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            throw new IllegalArgumentException("invalid entry size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        this.size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Returns the uncompressed size of the entry data, or -1 if not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return the uncompressed size of the entry data, or -1 if not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @see #setSize(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public long getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Returns the size of the compressed entry data, or -1 if not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * In the case of a stored entry, the compressed size will be the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * as the uncompressed size of the entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @return the size of the compressed entry data, or -1 if not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @see #setCompressedSize(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public long getCompressedSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return csize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Sets the size of the compressed entry data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param csize the compressed size to set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see #getCompressedSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public void setCompressedSize(long csize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        this.csize = csize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Sets the CRC-32 checksum of the uncompressed entry data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param crc the CRC-32 value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @exception IllegalArgumentException if the specified CRC-32 value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *            less than 0 or greater than 0xFFFFFFFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see #getCrc()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public void setCrc(long crc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (crc < 0 || crc > 0xFFFFFFFFL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            throw new IllegalArgumentException("invalid entry crc-32");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        this.crc = crc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @return the CRC-32 checksum of the uncompressed entry data, or -1 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see #setCrc(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public long getCrc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return crc;
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
     * Sets the compression method for the entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param method the compression method, either STORED or DEFLATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @exception IllegalArgumentException if the specified compression
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *            method is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see #getMethod()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public void setMethod(int method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (method != STORED && method != DEFLATED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            throw new IllegalArgumentException("invalid compression method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        this.method = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Returns the compression method of the entry, or -1 if not specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return the compression method of the entry, or -1 if not specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see #setMethod(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public int getMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Sets the optional extra field data for the entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param extra the extra field data bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @exception IllegalArgumentException if the length of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *            extra field data is greater than 0xFFFF bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see #getExtra()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public void setExtra(byte[] extra) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (extra != null && extra.length > 0xFFFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            throw new IllegalArgumentException("invalid extra field length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        this.extra = extra;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Returns the extra field data for the entry, or null if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return the extra field data for the entry, or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @see #setExtra(byte[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public byte[] getExtra() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return extra;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Sets the optional comment string for the entry.
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   243
     *
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   244
     * <p>ZIP entry comments have maximum length of 0xffff. If the length of the
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   245
     * specified comment string is greater than 0xFFFF bytes after encoding, only
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   246
     * the first 0xFFFF bytes are output to the ZIP file entry.
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   247
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param comment the comment string
3844
74c6b6e2db6c 6881337: ZipEntry.setComment() was accidentally changed back to old spec/impl in jdk7-b64
sherman
parents: 3111
diff changeset
   249
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see #getComment()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public void setComment(String comment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        this.comment = comment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Returns the comment string for the entry, or null if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return the comment string for the entry, or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see #setComment(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public String getComment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return comment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Returns true if this is a directory entry. A directory entry is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * defined to be one whose name ends with a '/'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return true if this is a directory entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public boolean isDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return name.endsWith("/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Returns a string representation of the ZIP entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Converts DOS time to Java time (number of milliseconds since epoch).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private static long dosToJavaTime(long dtime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                          (int)(((dtime >> 21) & 0x0f) - 1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                          (int)((dtime >> 16) & 0x1f),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                          (int)((dtime >> 11) & 0x1f),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                          (int)((dtime >> 5) & 0x3f),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                          (int)((dtime << 1) & 0x3e));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return d.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Converts Java time to DOS time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    private static long javaToDosTime(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        Date d = new Date(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        int year = d.getYear() + 1900;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (year < 1980) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return (1 << 21) | (1 << 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
               d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
               d.getSeconds() >> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Returns the hash code value for this entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return name.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Returns a copy of this entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            ZipEntry e = (ZipEntry)super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            e.extra = (extra == null) ? null : extra.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            // This should never happen, since we are Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            throw new InternalError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
}