J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package java.util.jar; |
| 27 | |
| 28 | import java.io.IOException; |
| 29 | import java.util.zip.ZipEntry; |
| 30 | import java.security.CodeSigner; |
| 31 | import java.security.cert.Certificate; |
| 32 | |
| 33 | /** |
| 34 | * This class is used to represent a JAR file entry. |
| 35 | */ |
| 36 | public |
| 37 | class JarEntry extends ZipEntry { |
| 38 | Attributes attr; |
| 39 | Certificate[] certs; |
| 40 | CodeSigner[] signers; |
| 41 | |
| 42 | /** |
| 43 | * Creates a new <code>JarEntry</code> for the specified JAR file |
| 44 | * entry name. |
| 45 | * |
| 46 | * @param name the JAR file entry name |
| 47 | * @exception NullPointerException if the entry name is <code>null</code> |
| 48 | * @exception IllegalArgumentException if the entry name is longer than |
| 49 | * 0xFFFF bytes. |
| 50 | */ |
| 51 | public JarEntry(String name) { |
| 52 | super(name); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Creates a new <code>JarEntry</code> with fields taken from the |
| 57 | * specified <code>ZipEntry</code> object. |
| 58 | * @param ze the <code>ZipEntry</code> object to create the |
| 59 | * <code>JarEntry</code> from |
| 60 | */ |
| 61 | public JarEntry(ZipEntry ze) { |
| 62 | super(ze); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Creates a new <code>JarEntry</code> with fields taken from the |
| 67 | * specified <code>JarEntry</code> object. |
| 68 | * |
| 69 | * @param je the <code>JarEntry</code> to copy |
| 70 | */ |
| 71 | public JarEntry(JarEntry je) { |
| 72 | this((ZipEntry)je); |
| 73 | this.attr = je.attr; |
| 74 | this.certs = je.certs; |
| 75 | this.signers = je.signers; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns the <code>Manifest</code> <code>Attributes</code> for this |
| 80 | * entry, or <code>null</code> if none. |
| 81 | * |
| 82 | * @return the <code>Manifest</code> <code>Attributes</code> for this |
| 83 | * entry, or <code>null</code> if none |
| 84 | */ |
| 85 | public Attributes getAttributes() throws IOException { |
| 86 | return attr; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the <code>Certificate</code> objects for this entry, or |
| 91 | * <code>null</code> if none. This method can only be called once |
| 92 | * the <code>JarEntry</code> has been completely verified by reading |
| 93 | * from the entry input stream until the end of the stream has been |
| 94 | * reached. Otherwise, this method will return <code>null</code>. |
| 95 | * |
| 96 | * <p>The returned certificate array comprises all the signer certificates |
| 97 | * that were used to verify this entry. Each signer certificate is |
| 98 | * followed by its supporting certificate chain (which may be empty). |
| 99 | * Each signer certificate and its supporting certificate chain are ordered |
| 100 | * bottom-to-top (i.e., with the signer certificate first and the (root) |
| 101 | * certificate authority last). |
| 102 | * |
| 103 | * @return the <code>Certificate</code> objects for this entry, or |
| 104 | * <code>null</code> if none. |
| 105 | */ |
| 106 | public Certificate[] getCertificates() { |
| 107 | return certs == null ? null : certs.clone(); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns the <code>CodeSigner</code> objects for this entry, or |
| 112 | * <code>null</code> if none. This method can only be called once |
| 113 | * the <code>JarEntry</code> has been completely verified by reading |
| 114 | * from the entry input stream until the end of the stream has been |
| 115 | * reached. Otherwise, this method will return <code>null</code>. |
| 116 | * |
| 117 | * <p>The returned array comprises all the code signers that have signed |
| 118 | * this entry. |
| 119 | * |
| 120 | * @return the <code>CodeSigner</code> objects for this entry, or |
| 121 | * <code>null</code> if none. |
| 122 | * |
| 123 | * @since 1.5 |
| 124 | */ |
| 125 | public CodeSigner[] getCodeSigners() { |
| 126 | return signers == null ? null : signers.clone(); |
| 127 | } |
| 128 | } |