| 1 |
14 |
jlechner |
/* JarEntry.java - Represents an entry in a jar file
|
| 2 |
|
|
Copyright (C) 2000 Free Software Foundation, Inc.
|
| 3 |
|
|
|
| 4 |
|
|
This file is part of GNU Classpath.
|
| 5 |
|
|
|
| 6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
| 7 |
|
|
it under the terms of the GNU General Public License as published by
|
| 8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
| 9 |
|
|
any later version.
|
| 10 |
|
|
|
| 11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
| 12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
|
|
General Public License for more details.
|
| 15 |
|
|
|
| 16 |
|
|
You should have received a copy of the GNU General Public License
|
| 17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
| 18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
| 19 |
|
|
02110-1301 USA.
|
| 20 |
|
|
|
| 21 |
|
|
Linking this library statically or dynamically with other modules is
|
| 22 |
|
|
making a combined work based on this library. Thus, the terms and
|
| 23 |
|
|
conditions of the GNU General Public License cover the whole
|
| 24 |
|
|
combination.
|
| 25 |
|
|
|
| 26 |
|
|
As a special exception, the copyright holders of this library give you
|
| 27 |
|
|
permission to link this library with independent modules to produce an
|
| 28 |
|
|
executable, regardless of the license terms of these independent
|
| 29 |
|
|
modules, and to copy and distribute the resulting executable under
|
| 30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
| 31 |
|
|
independent module, the terms and conditions of the license of that
|
| 32 |
|
|
module. An independent module is a module which is not derived from
|
| 33 |
|
|
or based on this library. If you modify this library, you may extend
|
| 34 |
|
|
this exception to your version of the library, but you are not
|
| 35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
| 36 |
|
|
exception statement from your version. */
|
| 37 |
|
|
|
| 38 |
|
|
package java.util.jar;
|
| 39 |
|
|
|
| 40 |
|
|
import java.io.IOException;
|
| 41 |
|
|
import java.security.cert.Certificate;
|
| 42 |
|
|
import java.util.zip.ZipEntry;
|
| 43 |
|
|
|
| 44 |
|
|
/**
|
| 45 |
|
|
* Extension to a ZipEntry that contains manifest attributes and certificates.
|
| 46 |
|
|
* Both the Atrributes and the Certificates can be null when not set.
|
| 47 |
|
|
* Note that the <code>getCertificates()</code> method only returns a
|
| 48 |
|
|
* valid value after all of the data of the entry has been read.
|
| 49 |
|
|
* <p>
|
| 50 |
|
|
* There are no public methods to set the attributes or certificate of an
|
| 51 |
|
|
* Entru. Only JarEntries created by the classes in <code>java.util.jar</code>
|
| 52 |
|
|
* will have these properties set.
|
| 53 |
|
|
*
|
| 54 |
|
|
* @since 1.2
|
| 55 |
|
|
* @author Mark Wielaard (mark@klomp.org)
|
| 56 |
|
|
*/
|
| 57 |
|
|
|
| 58 |
|
|
public class JarEntry extends ZipEntry
|
| 59 |
|
|
{
|
| 60 |
|
|
// (Package local) fields
|
| 61 |
|
|
|
| 62 |
|
|
Attributes attr;
|
| 63 |
|
|
Certificate certs[];
|
| 64 |
|
|
|
| 65 |
|
|
// Constructors
|
| 66 |
|
|
|
| 67 |
|
|
/**
|
| 68 |
|
|
* Creates a new JarEntry with the specified name and no attributes or
|
| 69 |
|
|
* or certificates. Calls <code>super(name)</code> so all other (zip)entry
|
| 70 |
|
|
* fields are null or -1.
|
| 71 |
|
|
*
|
| 72 |
|
|
* @param name the name of the new jar entry
|
| 73 |
|
|
* @exception NullPointerException when the supplied name is null
|
| 74 |
|
|
* @exception IllegalArgumentException when the supplied name is longer
|
| 75 |
|
|
* than 65535 bytes
|
| 76 |
|
|
*/
|
| 77 |
|
|
public JarEntry(String name) throws NullPointerException,
|
| 78 |
|
|
IllegalArgumentException
|
| 79 |
|
|
{
|
| 80 |
|
|
super(name);
|
| 81 |
|
|
attr = null;
|
| 82 |
|
|
certs = null;
|
| 83 |
|
|
}
|
| 84 |
|
|
|
| 85 |
|
|
/**
|
| 86 |
|
|
* Creates a new JarEntry with the specified ZipEntry as template for
|
| 87 |
|
|
* all properties of the entry. Both attributes and certificates will be
|
| 88 |
|
|
* null.
|
| 89 |
|
|
*
|
| 90 |
|
|
* @param entry the ZipEntry whose fields should be copied
|
| 91 |
|
|
*/
|
| 92 |
|
|
public JarEntry(ZipEntry entry)
|
| 93 |
|
|
{
|
| 94 |
|
|
super(entry);
|
| 95 |
|
|
attr = null;
|
| 96 |
|
|
certs = null;
|
| 97 |
|
|
}
|
| 98 |
|
|
|
| 99 |
|
|
/**
|
| 100 |
|
|
* Creates a new JarEntry with the specified JarEntry as template for
|
| 101 |
|
|
* all properties of the entry.
|
| 102 |
|
|
*
|
| 103 |
|
|
* @param entry the jarEntry whose fields should be copied
|
| 104 |
|
|
*/
|
| 105 |
|
|
public JarEntry(JarEntry entry)
|
| 106 |
|
|
{
|
| 107 |
|
|
super(entry);
|
| 108 |
|
|
try
|
| 109 |
|
|
{
|
| 110 |
|
|
attr = entry.getAttributes();
|
| 111 |
|
|
}
|
| 112 |
|
|
catch (IOException _)
|
| 113 |
|
|
{
|
| 114 |
|
|
}
|
| 115 |
|
|
certs = entry.getCertificates();
|
| 116 |
|
|
}
|
| 117 |
|
|
|
| 118 |
|
|
// Methods
|
| 119 |
|
|
|
| 120 |
|
|
/**
|
| 121 |
|
|
* Returns a copy of the Attributes set for this entry.
|
| 122 |
|
|
* When no Attributes are set in the manifest null is returned.
|
| 123 |
|
|
*
|
| 124 |
|
|
* @return a copy of the Attributes set for this entry
|
| 125 |
|
|
* @exception IOException This will never be thrown. It is here for
|
| 126 |
|
|
* binary compatibility.
|
| 127 |
|
|
*/
|
| 128 |
|
|
public Attributes getAttributes() throws IOException
|
| 129 |
|
|
{
|
| 130 |
|
|
if (attr != null)
|
| 131 |
|
|
{
|
| 132 |
|
|
return (Attributes) attr.clone();
|
| 133 |
|
|
}
|
| 134 |
|
|
else
|
| 135 |
|
|
{
|
| 136 |
|
|
return null;
|
| 137 |
|
|
}
|
| 138 |
|
|
}
|
| 139 |
|
|
|
| 140 |
|
|
/**
|
| 141 |
|
|
* Returns a copy of the certificates set for this entry.
|
| 142 |
|
|
* When no certificates are set or when not all data of this entry has
|
| 143 |
|
|
* been read null is returned.
|
| 144 |
|
|
* <p>
|
| 145 |
|
|
* To make sure that this call returns a valid value you must read all
|
| 146 |
|
|
* data from the JarInputStream for this entry.
|
| 147 |
|
|
* When you don't need the data for an entry but want to know the
|
| 148 |
|
|
* certificates that are set for the entry then you can skip all data by
|
| 149 |
|
|
* calling <code>skip(entry.getSize())</code> on the JarInputStream for
|
| 150 |
|
|
* the entry.
|
| 151 |
|
|
*
|
| 152 |
|
|
* @return a copy of the certificates set for this entry
|
| 153 |
|
|
*/
|
| 154 |
|
|
public Certificate[] getCertificates()
|
| 155 |
|
|
{
|
| 156 |
|
|
if (certs != null)
|
| 157 |
|
|
{
|
| 158 |
|
|
return (Certificate[])certs.clone();
|
| 159 |
|
|
}
|
| 160 |
|
|
else
|
| 161 |
|
|
{
|
| 162 |
|
|
return null;
|
| 163 |
|
|
}
|
| 164 |
|
|
}
|
| 165 |
|
|
}
|