1   /*
2    * %W% %E%
3    *
4    * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
5    * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6    */
7   
8   package java.util.jar;
9   
10  import java.io.IOException;
11  import java.util.zip.ZipEntry;
12  import java.security.CodeSigner;
13  import java.security.cert.Certificate;
14  
15  /**
16   * This class is used to represent a JAR file entry.
17   */
18  public
19  class JarEntry extends ZipEntry {
20      Attributes attr;
21      Certificate[] certs;
22      CodeSigner[] signers;
23  
24      /**
25       * Creates a new <code>JarEntry</code> for the specified JAR file
26       * entry name.
27       *
28       * @param name the JAR file entry name
29       * @exception NullPointerException if the entry name is <code>null</code>
30       * @exception IllegalArgumentException if the entry name is longer than
31       *            0xFFFF bytes.
32       */
33      public JarEntry(String name) {
34      super(name);
35      }
36  
37      /**
38       * Creates a new <code>JarEntry</code> with fields taken from the
39       * specified <code>ZipEntry</code> object.
40       * @param ze the <code>ZipEntry</code> object to create the 
41       *           <code>JarEntry</code> from
42       */
43      public JarEntry(ZipEntry ze) {
44      super(ze);
45      }
46  
47      /**
48       * Creates a new <code>JarEntry</code> with fields taken from the
49       * specified <code>JarEntry</code> object.
50       *
51       * @param je the <code>JarEntry</code> to copy
52       */
53      public JarEntry(JarEntry je) {
54      this((ZipEntry)je);
55      this.attr = je.attr;
56      this.certs = je.certs;
57      this.signers = je.signers;
58      }
59  
60      /**
61       * Returns the <code>Manifest</code> <code>Attributes</code> for this
62       * entry, or <code>null</code> if none.
63       *
64       * @return the <code>Manifest</code> <code>Attributes</code> for this
65       * entry, or <code>null</code> if none
66       */
67      public Attributes getAttributes() throws IOException {
68      return attr;
69      }
70  
71      /**
72       * Returns the <code>Certificate</code> objects for this entry, or
73       * <code>null</code> if none. This method can only be called once
74       * the <code>JarEntry</code> has been completely verified by reading
75       * from the entry input stream until the end of the stream has been
76       * reached. Otherwise, this method will return <code>null</code>.
77       *
78       * <p>The returned certificate array comprises all the signer certificates
79       * that were used to verify this entry. Each signer certificate is
80       * followed by its supporting certificate chain (which may be empty).
81       * Each signer certificate and its supporting certificate chain are ordered
82       * bottom-to-top (i.e., with the signer certificate first and the (root)
83       * certificate authority last).
84       *
85       * @return the <code>Certificate</code> objects for this entry, or
86       * <code>null</code> if none.
87       */
88      public Certificate[] getCertificates() {
89      return certs == null ? null : (Certificate[]) certs.clone();
90      }
91  
92      /**
93       * Returns the <code>CodeSigner</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 array comprises all the code signers that have signed
100      * this entry. 
101      *
102      * @return the <code>CodeSigner</code> objects for this entry, or
103      * <code>null</code> if none.
104      *
105      * @since 1.5
106      */
107     public CodeSigner[] getCodeSigners() {
108     return signers == null ? null : (CodeSigner[]) signers.clone();
109     }
110 }
111