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 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      */
JarEntry(String name)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      */
JarEntry(ZipEntry ze)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      */
JarEntry(JarEntry je)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      * @throws IOException  if an I/O error has occurred
85      */
getAttributes()86     public Attributes getAttributes() throws IOException {
87         return attr;
88     }
89 
90     /**
91      * Returns the <code>Certificate</code> objects for this entry, or
92      * <code>null</code> if none. This method can only be called once
93      * the <code>JarEntry</code> has been completely verified by reading
94      * from the entry input stream until the end of the stream has been
95      * reached. Otherwise, this method will return <code>null</code>.
96      *
97      * <p>The returned certificate array comprises all the signer certificates
98      * that were used to verify this entry. Each signer certificate is
99      * followed by its supporting certificate chain (which may be empty).
100      * Each signer certificate and its supporting certificate chain are ordered
101      * bottom-to-top (i.e., with the signer certificate first and the (root)
102      * certificate authority last).
103      *
104      * @return the <code>Certificate</code> objects for this entry, or
105      * <code>null</code> if none.
106      */
getCertificates()107     public Certificate[] getCertificates() {
108         return certs == null ? null : certs.clone();
109     }
110 
111     /**
112      * Returns the <code>CodeSigner</code> objects for this entry, or
113      * <code>null</code> if none. This method can only be called once
114      * the <code>JarEntry</code> has been completely verified by reading
115      * from the entry input stream until the end of the stream has been
116      * reached. Otherwise, this method will return <code>null</code>.
117      *
118      * <p>The returned array comprises all the code signers that have signed
119      * this entry.
120      *
121      * @return the <code>CodeSigner</code> objects for this entry, or
122      * <code>null</code> if none.
123      *
124      * @since 1.5
125      */
getCodeSigners()126     public CodeSigner[] getCodeSigners() {
127         return signers == null ? null : signers.clone();
128     }
129 }
130