1 /* 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * 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 * @since 1.2 37 */ 38 public 39 class JarEntry extends ZipEntry { 40 Attributes attr; 41 Certificate[] certs; 42 CodeSigner[] signers; 43 44 /** 45 * Creates a new <code>JarEntry</code> for the specified JAR file 46 * entry name. 47 * 48 * @param name the JAR file entry name 49 * @exception NullPointerException if the entry name is <code>null</code> 50 * @exception IllegalArgumentException if the entry name is longer than 51 * 0xFFFF bytes. 52 */ JarEntry(String name)53 public JarEntry(String name) { 54 super(name); 55 } 56 57 /** 58 * Creates a new <code>JarEntry</code> with fields taken from the 59 * specified <code>ZipEntry</code> object. 60 * @param ze the <code>ZipEntry</code> object to create the 61 * <code>JarEntry</code> from 62 */ JarEntry(ZipEntry ze)63 public JarEntry(ZipEntry ze) { 64 super(ze); 65 } 66 67 /** 68 * Creates a new <code>JarEntry</code> with fields taken from the 69 * specified <code>JarEntry</code> object. 70 * 71 * @param je the <code>JarEntry</code> to copy 72 */ JarEntry(JarEntry je)73 public JarEntry(JarEntry je) { 74 this((ZipEntry)je); 75 this.attr = je.attr; 76 this.certs = je.certs; 77 this.signers = je.signers; 78 } 79 80 /** 81 * Returns the <code>Manifest</code> <code>Attributes</code> for this 82 * entry, or <code>null</code> if none. 83 * 84 * @return the <code>Manifest</code> <code>Attributes</code> for this 85 * entry, or <code>null</code> if none 86 * @throws IOException if an I/O error has occurred 87 */ getAttributes()88 public Attributes getAttributes() throws IOException { 89 return attr; 90 } 91 92 /** 93 * Returns the <code>Certificate</code> objects for this entry, or 94 * <code>null</code> if none. This method can only be called once 95 * the <code>JarEntry</code> has been completely verified by reading 96 * from the entry input stream until the end of the stream has been 97 * reached. Otherwise, this method will return <code>null</code>. 98 * 99 * <p>The returned certificate array comprises all the signer certificates 100 * that were used to verify this entry. Each signer certificate is 101 * followed by its supporting certificate chain (which may be empty). 102 * Each signer certificate and its supporting certificate chain are ordered 103 * bottom-to-top (i.e., with the signer certificate first and the (root) 104 * certificate authority last). 105 * 106 * @return the <code>Certificate</code> objects for this entry, or 107 * <code>null</code> if none. 108 */ getCertificates()109 public Certificate[] getCertificates() { 110 return certs == null ? null : certs.clone(); 111 } 112 113 /** 114 * Returns the <code>CodeSigner</code> objects for this entry, or 115 * <code>null</code> if none. This method can only be called once 116 * the <code>JarEntry</code> has been completely verified by reading 117 * from the entry input stream until the end of the stream has been 118 * reached. Otherwise, this method will return <code>null</code>. 119 * 120 * <p>The returned array comprises all the code signers that have signed 121 * this entry. 122 * 123 * @return the <code>CodeSigner</code> objects for this entry, or 124 * <code>null</code> if none. 125 * 126 * @since 1.5 127 */ getCodeSigners()128 public CodeSigner[] getCodeSigners() { 129 return signers == null ? null : signers.clone(); 130 } 131 132 /** 133 * This method returns the same name that {@link #getName()} returns. 134 * 135 * @return the real name of the JarEntry 136 * 137 * @since 10 138 */ getRealName()139 public String getRealName() { 140 return super.getName(); 141 } 142 } 143