Commit c5f651bf by Mark Wielaard Committed by Mark Wielaard

backport: *.java: Reformat all to unofficial standard coding style.

	Merge with Classpath (changes by Bryce McKinlay)
	* java/util/jar/*.java: Reformat all to unofficial standard coding
	style. No changes of substance.

From-SVN: r37538
parent c003f378
2000-11-17 Mark Wielaar <mark@klomp.org>
Merge with Classpath (changes by Bryce McKinlay)
* java/util/jar/*.java: Reformat all to unofficial standard coding
style. No changes of substance.
2000-11-17 Mark Wielaard <mark@klomp.org> 2000-11-17 Mark Wielaard <mark@klomp.org>
* java/util/zip/*.java: Javadoc updates. * java/util/zip/*.java: Javadoc updates.
......
...@@ -54,7 +54,8 @@ import java.util.Set; ...@@ -54,7 +54,8 @@ import java.util.Set;
* @see java.util.jar.Attributes.Name * @see java.util.jar.Attributes.Name
* @author Mark Wielaard (mark@klomp.org) * @author Mark Wielaard (mark@klomp.org)
*/ */
public class Attributes implements Cloneable, Map { public class Attributes implements Cloneable, Map
{
// Fields // Fields
...@@ -88,7 +89,8 @@ public class Attributes implements Cloneable, Map { ...@@ -88,7 +89,8 @@ public class Attributes implements Cloneable, Map {
* @since 1.2 * @since 1.2
* @author Mark Wielaard (mark@klomp.org) * @author Mark Wielaard (mark@klomp.org)
*/ */
public static class Name { public static class Name
{
// Fields // Fields
...@@ -98,14 +100,12 @@ public class Attributes implements Cloneable, Map { ...@@ -98,14 +100,12 @@ public class Attributes implements Cloneable, Map {
* General main attribute - * General main attribute -
* the version of this Manifest file. * the version of this Manifest file.
*/ */
public static final Name MANIFEST_VERSION public static final Name MANIFEST_VERSION = new Name("Manifest-Version");
= new Name("Manifest-Version");
/** /**
* General main attribute - * General main attribute -
* tool and version that created this Manifest file. * tool and version that created this Manifest file.
*/ */
public static final Name CREATED_BY public static final Name CREATED_BY = new Name("Created-By");
= new Name("Created-By");
/** /**
* General main attribute - * General main attribute -
* the version of the jar file signature. * the version of the jar file signature.
...@@ -117,16 +117,14 @@ public class Attributes implements Cloneable, Map { ...@@ -117,16 +117,14 @@ public class Attributes implements Cloneable, Map {
* (relative) URLs of the libraries/classpaths that the Classes in * (relative) URLs of the libraries/classpaths that the Classes in
* this jar file depend on. * this jar file depend on.
*/ */
public static final Name CLASS_PATH public static final Name CLASS_PATH = new Name("Class-Path");
= new Name("Class-Path");
/** /**
* Stand alone application attribute - * Stand alone application attribute -
* the entry (without the .class ending) that is the main * the entry (without the .class ending) that is the main
* class of this jar file. * class of this jar file.
*/ */
public static final Name MAIN_CLASS public static final Name MAIN_CLASS = new Name("Main-Class");
= new Name("Main-Class");
/** /**
* Applet attribute - * Applet attribute -
...@@ -147,21 +145,18 @@ public class Attributes implements Cloneable, Map { ...@@ -147,21 +145,18 @@ public class Attributes implements Cloneable, Map {
* where the latest version of the extension library can be found * where the latest version of the extension library can be found
* </ul> * </ul>
*/ */
public static final Name EXTENSION_LIST public static final Name EXTENSION_LIST = new Name("Extension-List");
= new Name("Extension-List");
/** /**
* Extension identification attribute - * Extension identification attribute -
* the name if the extension library contained in the jar. * the name if the extension library contained in the jar.
*/ */
public static final Name EXTENSION_NAME public static final Name EXTENSION_NAME = new Name("Extension-Name");
= new Name("Extension-Name");
/** /**
* Extension identification attribute - * Extension identification attribute -
* synonym for <code>EXTENSTION_NAME</code>. * synonym for <code>EXTENSTION_NAME</code>.
*/ */
public static final Name EXTENSION_INSTALLATION public static final Name EXTENSION_INSTALLATION = EXTENSION_NAME;
= EXTENSION_NAME;
// Package versioning and sealing attributes // Package versioning and sealing attributes
/** /**
...@@ -218,30 +213,26 @@ public class Attributes implements Cloneable, Map { ...@@ -218,30 +213,26 @@ public class Attributes implements Cloneable, Map {
* whether (all) package(s) is(/are) sealed. Value is either "true" * whether (all) package(s) is(/are) sealed. Value is either "true"
* or "false". * or "false".
*/ */
public static final Name SEALED public static final Name SEALED = new Name("Sealed");
= new Name("Sealed");
/** /**
* File contents attribute - * File contents attribute -
* Mime type and subtype for the jar entry. * Mime type and subtype for the jar entry.
*/ */
public static final Name CONTENT_TYPE public static final Name CONTENT_TYPE = new Name("Content-Type");
= new Name("Content-Type");
/** /**
* Bean objects attribute - * Bean objects attribute -
* whether the entry is a Java Bean. Value is either "true" or "false". * whether the entry is a Java Bean. Value is either "true" or "false".
*/ */
public static final Name JAVA_BEAN public static final Name JAVA_BEAN = new Name("Java-Bean");
= new Name("Java-Bean");
/** /**
* Signing attribute - * Signing attribute -
* application specific signing attribute. Must be understood by * application specific signing attribute. Must be understood by
* the manifest parser when present to validate the jar (entry). * the manifest parser when present to validate the jar (entry).
*/ */
public static final Name MAGIC public static final Name MAGIC = new Name("Magic");
= new Name("Magic");
/** The (lowercase) String representation of this Name */ /** The (lowercase) String representation of this Name */
private final String name; private final String name;
...@@ -261,32 +252,34 @@ public class Attributes implements Cloneable, Map { ...@@ -261,32 +252,34 @@ public class Attributes implements Cloneable, Map {
* @exception NullPointerException if name is null * @exception NullPointerException if name is null
*/ */
public Name(String name) throws IllegalArgumentException, public Name(String name) throws IllegalArgumentException,
NullPointerException { NullPointerException
{
// name must not be null // name must not be null
// this will throw a NullPointerException if it is // this will throw a NullPointerException if it is
char chars[] = name.toCharArray(); char chars[] = name.toCharArray();
// there must be at least one character // there must be at least one character
if (chars.length == 0) if (chars.length == 0)
throw new IllegalArgumentException( throw new
"There must be at least one character in a name"); IllegalArgumentException
("There must be at least one character in a name");
// first character must be alphanum // first character must be alphanum
char c = chars[0]; char c = chars[0];
if (!((c >= 'a' && c <= 'z') || if (!((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')))
(c >= '0' && c <= '9'))) throw new
throw new IllegalArgumentException( IllegalArgumentException("First character must be alphanum");
"First character must be alphanum");
// all other characters must be alphanums, '-' or '_' // all other characters must be alphanums, '-' or '_'
for (int i = 1; i < chars.length; i++) { for (int i = 1; i < chars.length; i++)
{
if (!((c >= 'a' && c <= 'z') || if (!((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') || (c >= '0' && c <= '9') || (c == '-') || (c == '_')))
(c == '-') || (c == '_'))) throw new
throw new IllegalArgumentException( IllegalArgumentException
"Characters must be alphanums, '-' or '_'"); ("Characters must be alphanums, '-' or '_'");
} }
// Still here? Then convert to lower case and be done. // Still here? Then convert to lower case and be done.
...@@ -299,7 +292,8 @@ public class Attributes implements Cloneable, Map { ...@@ -299,7 +292,8 @@ public class Attributes implements Cloneable, Map {
* Returns the hash code of the (lowercase) String representation of * Returns the hash code of the (lowercase) String representation of
* this Name. * this Name.
*/ */
public int hashCode() { public int hashCode()
{
return name.hashCode(); return name.hashCode();
} }
...@@ -308,19 +302,25 @@ public class Attributes implements Cloneable, Map { ...@@ -308,19 +302,25 @@ public class Attributes implements Cloneable, Map {
* Another object is equal to this Name object if it is an instance of * Another object is equal to this Name object if it is an instance of
* Name and the (lowercase) string representation of the name is equal. * Name and the (lowercase) string representation of the name is equal.
*/ */
public boolean equals(Object o) { public boolean equals(Object o)
{
// Quick and dirty check // Quick and dirty check
if (name == o) if (name == o)
return true; return true;
try { try
{
// Note that the constructor already converts the strings to // Note that the constructor already converts the strings to
// lowercase. // lowercase.
String otherName = ((Name)o).name; String otherName = ((Name) o).name;
return name.equals(otherName); return name.equals(otherName);
} catch (ClassCastException cce) { }
catch (ClassCastException cce)
{
return false; return false;
} catch (NullPointerException npe) { }
catch (NullPointerException npe)
{
return false; return false;
} }
} }
...@@ -329,7 +329,8 @@ public class Attributes implements Cloneable, Map { ...@@ -329,7 +329,8 @@ public class Attributes implements Cloneable, Map {
* Returns the string representation of this Name as given to the * Returns the string representation of this Name as given to the
* constructor (not neccesarily the lower case representation). * constructor (not neccesarily the lower case representation).
*/ */
public String toString() { public String toString()
{
return origName; return origName;
} }
} }
...@@ -339,7 +340,8 @@ public class Attributes implements Cloneable, Map { ...@@ -339,7 +340,8 @@ public class Attributes implements Cloneable, Map {
/** /**
* Creates an empty Attributes map. * Creates an empty Attributes map.
*/ */
public Attributes() { public Attributes()
{
map = new Hashtable(); map = new Hashtable();
} }
...@@ -347,7 +349,8 @@ public class Attributes implements Cloneable, Map { ...@@ -347,7 +349,8 @@ public class Attributes implements Cloneable, Map {
* Creates an empty Attributes map with the given initial size. * Creates an empty Attributes map with the given initial size.
* @param size the initial size of the underlying map * @param size the initial size of the underlying map
*/ */
public Attributes(int size) { public Attributes(int size)
{
map = new Hashtable(size); map = new Hashtable(size);
} }
...@@ -356,7 +359,8 @@ public class Attributes implements Cloneable, Map { ...@@ -356,7 +359,8 @@ public class Attributes implements Cloneable, Map {
* Attributes map. * Attributes map.
* @param attr Attributes map to take the initial values from * @param attr Attributes map to take the initial values from
*/ */
public Attributes(Attributes attr) { public Attributes(Attributes attr)
{
map = new Hashtable(attr.map); map = new Hashtable(attr.map);
} }
...@@ -368,8 +372,9 @@ public class Attributes implements Cloneable, Map { ...@@ -368,8 +372,9 @@ public class Attributes implements Cloneable, Map {
* @param name a String describing the Name to look for * @param name a String describing the Name to look for
* @return the value gotten from the map of null when not found * @return the value gotten from the map of null when not found
*/ */
public String getValue(String name) { public String getValue(String name)
return (String)get(new Name(name)); {
return (String) get(new Name(name));
} }
/** /**
...@@ -378,8 +383,9 @@ public class Attributes implements Cloneable, Map { ...@@ -378,8 +383,9 @@ public class Attributes implements Cloneable, Map {
* @param name the Name to look for * @param name the Name to look for
* @return the value gotten from the map of null when not found * @return the value gotten from the map of null when not found
*/ */
public String getValue(Name name) { public String getValue(Name name)
return (String)get(name); {
return (String) get(name);
} }
/** /**
...@@ -415,7 +421,7 @@ public class Attributes implements Cloneable, Map { ...@@ -415,7 +421,7 @@ public class Attributes implements Cloneable, Map {
*/ */
private String putValue(Name name, String value) private String putValue(Name name, String value)
{ {
return (String)put(name, value); return (String) put(name, value);
} }
// Methods from Cloneable interface // Methods from Cloneable interface
...@@ -423,7 +429,8 @@ public class Attributes implements Cloneable, Map { ...@@ -423,7 +429,8 @@ public class Attributes implements Cloneable, Map {
/** /**
* Return a clone of this attribute map. * Return a clone of this attribute map.
*/ */
public Object clone() { public Object clone()
{
return new Attributes(this); return new Attributes(this);
} }
...@@ -432,7 +439,8 @@ public class Attributes implements Cloneable, Map { ...@@ -432,7 +439,8 @@ public class Attributes implements Cloneable, Map {
/** /**
* Removes all attributes. * Removes all attributes.
*/ */
public void clear() { public void clear()
{
map.clear(); map.clear();
} }
...@@ -444,7 +452,8 @@ public class Attributes implements Cloneable, Map { ...@@ -444,7 +452,8 @@ public class Attributes implements Cloneable, Map {
* @return true if there is an attribute with the specified name, false * @return true if there is an attribute with the specified name, false
* otherwise * otherwise
*/ */
public boolean containsKey(Object attrName) { public boolean containsKey(Object attrName)
{
return map.containsKey(attrName); return map.containsKey(attrName);
} }
...@@ -455,7 +464,8 @@ public class Attributes implements Cloneable, Map { ...@@ -455,7 +464,8 @@ public class Attributes implements Cloneable, Map {
* @return true if there is an attribute name with the specified value, * @return true if there is an attribute name with the specified value,
* false otherwise * false otherwise
*/ */
public boolean containsValue(Object attrValue) { public boolean containsValue(Object attrValue)
{
return map.containsValue(attrValue); return map.containsValue(attrValue);
} }
...@@ -466,7 +476,8 @@ public class Attributes implements Cloneable, Map { ...@@ -466,7 +476,8 @@ public class Attributes implements Cloneable, Map {
* *
* @return a set of attribute name value pairs * @return a set of attribute name value pairs
*/ */
public Set entrySet() { public Set entrySet()
{
return map.entrySet(); return map.entrySet();
} }
...@@ -479,16 +490,22 @@ public class Attributes implements Cloneable, Map { ...@@ -479,16 +490,22 @@ public class Attributes implements Cloneable, Map {
* @return true if the object is an instance of Attributes and contains the * @return true if the object is an instance of Attributes and contains the
* same name/value pairs, false otherwise * same name/value pairs, false otherwise
*/ */
public boolean equals(Object o) { public boolean equals(Object o)
{
// quick and dirty check // quick and dirty check
if (this == o) if (this == o)
return true; return true;
try { try
return map.equals(((Attributes)o).map); {
} catch (ClassCastException cce) { return map.equals(((Attributes) o).map);
}
catch (ClassCastException cce)
{
return false; return false;
} catch (NullPointerException npe) { }
catch (NullPointerException npe)
{
return false; return false;
} }
} }
...@@ -501,28 +518,32 @@ public class Attributes implements Cloneable, Map { ...@@ -501,28 +518,32 @@ public class Attributes implements Cloneable, Map {
* @return the value of the specified attribute name or null when there is * @return the value of the specified attribute name or null when there is
* no such attribute name * no such attribute name
*/ */
public Object get(Object attrName) { public Object get(Object attrName)
{
return map.get(attrName); return map.get(attrName);
} }
/** /**
* Returns the hashcode of the attribute name/value map. * Returns the hashcode of the attribute name/value map.
*/ */
public int hashCode() { public int hashCode()
{
return map.hashCode(); return map.hashCode();
} }
/** /**
* Returns true if there are no attributes set, false otherwise. * Returns true if there are no attributes set, false otherwise.
*/ */
public boolean isEmpty() { public boolean isEmpty()
{
return map.isEmpty(); return map.isEmpty();
} }
/** /**
* Gives a Set of all the values of defined attribute names. * Gives a Set of all the values of defined attribute names.
*/ */
public Set keySet() { public Set keySet()
{
return map.keySet(); return map.keySet();
} }
...@@ -536,7 +557,8 @@ public class Attributes implements Cloneable, Map { ...@@ -536,7 +557,8 @@ public class Attributes implements Cloneable, Map {
* @return the old value of the attribute or null when there was no old * @return the old value of the attribute or null when there was no old
* attribute with this name * attribute with this name
*/ */
public Object put(Object name, Object value) { public Object put(Object name, Object value)
{
return map.put(name, value); return map.put(name, value);
} }
...@@ -549,10 +571,12 @@ public class Attributes implements Cloneable, Map { ...@@ -549,10 +571,12 @@ public class Attributes implements Cloneable, Map {
* @exception ClassCastException if the supplied map is not an instance of * @exception ClassCastException if the supplied map is not an instance of
* Attributes * Attributes
*/ */
public void putAll(Map attr) { public void putAll(Map attr)
if (!(attr instanceof Attributes)) { {
throw new ClassCastException( if (!(attr instanceof Attributes))
"Supplied Map is not an instance of Attributes"); {
throw new
ClassCastException("Supplied Map is not an instance of Attributes");
} }
map.putAll(attr); map.putAll(attr);
} }
...@@ -565,14 +589,16 @@ public class Attributes implements Cloneable, Map { ...@@ -565,14 +589,16 @@ public class Attributes implements Cloneable, Map {
* @return the old value of the attribute or null if the attribute didn't * @return the old value of the attribute or null if the attribute didn't
* exist * exist
*/ */
public Object remove(Object name) { public Object remove(Object name)
{
return map.remove(name); return map.remove(name);
} }
/** /**
* Returns the number of defined attribute name/value pairs. * Returns the number of defined attribute name/value pairs.
*/ */
public int size() { public int size()
{
return map.size(); return map.size();
} }
...@@ -580,7 +606,8 @@ public class Attributes implements Cloneable, Map { ...@@ -580,7 +606,8 @@ public class Attributes implements Cloneable, Map {
* Returns all the values of the defined attribute name/value pairs as a * Returns all the values of the defined attribute name/value pairs as a
* Collection. * Collection.
*/ */
public Collection values() { public Collection values()
{
return map.values(); return map.values();
} }
} }
...@@ -44,8 +44,8 @@ import java.util.zip.ZipEntry; ...@@ -44,8 +44,8 @@ import java.util.zip.ZipEntry;
* @author Mark Wielaard (mark@klomp.org) * @author Mark Wielaard (mark@klomp.org)
*/ */
public class JarEntry extends ZipEntry { public class JarEntry extends ZipEntry
{
// (Packge local) fields // (Packge local) fields
Attributes attr; Attributes attr;
...@@ -64,7 +64,8 @@ public class JarEntry extends ZipEntry { ...@@ -64,7 +64,8 @@ public class JarEntry extends ZipEntry {
* than 65535 bytes * than 65535 bytes
*/ */
public JarEntry(String name) throws NullPointerException, public JarEntry(String name) throws NullPointerException,
IllegalArgumentException { IllegalArgumentException
{
super(name); super(name);
attr = null; attr = null;
certs = null; certs = null;
...@@ -77,7 +78,8 @@ public class JarEntry extends ZipEntry { ...@@ -77,7 +78,8 @@ public class JarEntry extends ZipEntry {
* *
* @param entry the ZipEntry whose fields should be copied * @param entry the ZipEntry whose fields should be copied
*/ */
public JarEntry(ZipEntry entry) { public JarEntry(ZipEntry entry)
{
super(entry); super(entry);
attr = null; attr = null;
certs = null; certs = null;
...@@ -89,11 +91,16 @@ public class JarEntry extends ZipEntry { ...@@ -89,11 +91,16 @@ public class JarEntry extends ZipEntry {
* *
* @param entry the jarEntry whose fields should be copied * @param entry the jarEntry whose fields should be copied
*/ */
public JarEntry(JarEntry entry) { public JarEntry(JarEntry entry)
{
super(entry); super(entry);
try { try
{
attr = entry.getAttributes(); attr = entry.getAttributes();
} catch(IOException _) {} }
catch (IOException _)
{
}
certs = entry.getCertificates(); certs = entry.getCertificates();
} }
...@@ -107,10 +114,14 @@ public class JarEntry extends ZipEntry { ...@@ -107,10 +114,14 @@ public class JarEntry extends ZipEntry {
* @exception IOException This will never be thrown. It is here for * @exception IOException This will never be thrown. It is here for
* binary compatibility. * binary compatibility.
*/ */
public Attributes getAttributes() throws IOException { public Attributes getAttributes() throws IOException
if (attr != null) { {
if (attr != null)
{
return (Attributes) attr.clone(); return (Attributes) attr.clone();
} else { }
else
{
return null; return null;
} }
} }
...@@ -129,10 +140,14 @@ public class JarEntry extends ZipEntry { ...@@ -129,10 +140,14 @@ public class JarEntry extends ZipEntry {
* *
* @return a copy of the certificates set for this entry * @return a copy of the certificates set for this entry
*/ */
public Certificate[] getCertificates() { public Certificate[] getCertificates()
if (certs != null) { {
return (Certificate []) certs.clone(); if (certs != null)
} else { {
return (Certificate[])certs.clone();
}
else
{
return null; return null;
} }
} }
......
...@@ -40,14 +40,15 @@ import java.util.zip.ZipException; ...@@ -40,14 +40,15 @@ import java.util.zip.ZipException;
* @author Mark Wielaard (mark@klomp.org) * @author Mark Wielaard (mark@klomp.org)
*/ */
public class JarException extends ZipException { public class JarException extends ZipException
{
// Constructors // Constructors
/** /**
* Create a new JarException without a descriptive error message. * Create a new JarException without a descriptive error message.
*/ */
public JarException() { public JarException()
{
super(); super();
} }
...@@ -59,7 +60,8 @@ public class JarException extends ZipException { ...@@ -59,7 +60,8 @@ public class JarException extends ZipException {
* *
* @param message The descriptive error message * @param message The descriptive error message
*/ */
public JarException(String message) { public JarException(String message)
{
super(message); super(message);
} }
} }
...@@ -47,8 +47,8 @@ import java.util.Enumeration; ...@@ -47,8 +47,8 @@ import java.util.Enumeration;
* @since 1.2 * @since 1.2
* @author Mark Wielaard (mark@klomp.org) * @author Mark Wielaard (mark@klomp.org)
*/ */
public class JarFile extends ZipFile { public class JarFile extends ZipFile
{
// Fields // Fields
/** The name of the manifest entry: META-INF/MANIFEST.MF */ /** The name of the manifest entry: META-INF/MANIFEST.MF */
...@@ -73,9 +73,9 @@ public class JarFile extends ZipFile { ...@@ -73,9 +73,9 @@ public class JarFile extends ZipFile {
* @exception FileNotFoundException if the fileName cannot be found * @exception FileNotFoundException if the fileName cannot be found
* @exception IOException if another IO exception occurs while reading * @exception IOException if another IO exception occurs while reading
*/ */
public JarFile(String fileName) throws FileNotFoundException, public JarFile(String fileName) throws FileNotFoundException, IOException
IOException { {
this (fileName, true); this(fileName, true);
} }
/** /**
...@@ -89,8 +89,8 @@ public class JarFile extends ZipFile { ...@@ -89,8 +89,8 @@ public class JarFile extends ZipFile {
* @exception IOException if another IO exception occurs while reading * @exception IOException if another IO exception occurs while reading
*/ */
public JarFile(String fileName, boolean verify) throws public JarFile(String fileName, boolean verify) throws
FileNotFoundException, FileNotFoundException, IOException
IOException { {
super(fileName); super(fileName);
manifest = readManifest(); manifest = readManifest();
if (verify) if (verify)
...@@ -105,9 +105,9 @@ public class JarFile extends ZipFile { ...@@ -105,9 +105,9 @@ public class JarFile extends ZipFile {
* @exception FileNotFoundException if the file does not exits * @exception FileNotFoundException if the file does not exits
* @exception IOException if another IO exception occurs while reading * @exception IOException if another IO exception occurs while reading
*/ */
public JarFile(File file) throws FileNotFoundException, public JarFile(File file) throws FileNotFoundException, IOException
IOException { {
this (file, true); this(file, true);
} }
/** /**
...@@ -121,7 +121,8 @@ public class JarFile extends ZipFile { ...@@ -121,7 +121,8 @@ public class JarFile extends ZipFile {
* @exception IOException if another IO exception occurs while reading * @exception IOException if another IO exception occurs while reading
*/ */
public JarFile(File file, boolean verify) throws FileNotFoundException, public JarFile(File file, boolean verify) throws FileNotFoundException,
IOException { IOException
{
super(file); super(file);
manifest = readManifest(); manifest = readManifest();
if (verify) if (verify)
...@@ -144,9 +145,8 @@ public class JarFile extends ZipFile { ...@@ -144,9 +145,8 @@ public class JarFile extends ZipFile {
* @since 1.3 * @since 1.3
*/ */
public JarFile(File file, boolean verify, int mode) throws public JarFile(File file, boolean verify, int mode) throws
FileNotFoundException, FileNotFoundException, IOException, IllegalArgumentException
IOException, {
IllegalArgumentException {
super(file, mode); super(file, mode);
manifest = readManifest(); manifest = readManifest();
if (verify) if (verify)
...@@ -158,9 +158,11 @@ public class JarFile extends ZipFile { ...@@ -158,9 +158,11 @@ public class JarFile extends ZipFile {
/** /**
* XXX - should verify the manifest file * XXX - should verify the manifest file
*/ */
private void verify() { private void verify()
{
// only check if manifest is not null // only check if manifest is not null
if (manifest == null) { if (manifest == null)
{
verify = false; verify = false;
return; return;
} }
...@@ -172,16 +174,23 @@ public class JarFile extends ZipFile { ...@@ -172,16 +174,23 @@ public class JarFile extends ZipFile {
/** /**
* Parses and returns the manifest if it exists, otherwise returns null. * Parses and returns the manifest if it exists, otherwise returns null.
*/ */
private Manifest readManifest() { private Manifest readManifest()
try { {
try
{
ZipEntry manEntry = super.getEntry(MANIFEST_NAME); ZipEntry manEntry = super.getEntry(MANIFEST_NAME);
if (manEntry != null) { if (manEntry != null)
{
InputStream in = super.getInputStream(manEntry); InputStream in = super.getInputStream(manEntry);
return new Manifest(in); return new Manifest(in);
} else { }
else
{
return null; return null;
} }
} catch (IOException ioe) { }
catch (IOException ioe)
{
return null; return null;
} }
} }
...@@ -192,7 +201,8 @@ public class JarFile extends ZipFile { ...@@ -192,7 +201,8 @@ public class JarFile extends ZipFile {
* *
* @exception IllegalStateException when the JarFile is already closed * @exception IllegalStateException when the JarFile is already closed
*/ */
public Enumeration entries() throws IllegalStateException { public Enumeration entries() throws IllegalStateException
{
return new JarEnumeration(super.entries()); return new JarEnumeration(super.entries());
} }
...@@ -201,22 +211,27 @@ public class JarFile extends ZipFile { ...@@ -201,22 +211,27 @@ public class JarFile extends ZipFile {
* JarEntry is created and the corresponding Attributes are looked up. * JarEntry is created and the corresponding Attributes are looked up.
* XXX - Should also look up the certificates. * XXX - Should also look up the certificates.
*/ */
private class JarEnumeration implements Enumeration { private class JarEnumeration implements Enumeration
{
private final Enumeration entries; private final Enumeration entries;
JarEnumeration(Enumeration e) { JarEnumeration(Enumeration e)
{
entries = e; entries = e;
} }
public boolean hasMoreElements() { public boolean hasMoreElements()
{
return entries.hasMoreElements(); return entries.hasMoreElements();
} }
public Object nextElement() { public Object nextElement()
{
ZipEntry zip = (ZipEntry) entries.nextElement(); ZipEntry zip = (ZipEntry) entries.nextElement();
JarEntry jar = new JarEntry(zip); JarEntry jar = new JarEntry(zip);
if (manifest != null) { if (manifest != null)
{
jar.attr = manifest.getAttributes(jar.getName()); jar.attr = manifest.getAttributes(jar.getName());
} }
// XXX jar.certs // XXX jar.certs
...@@ -229,11 +244,14 @@ public class JarFile extends ZipFile { ...@@ -229,11 +244,14 @@ public class JarFile extends ZipFile {
* It actually returns a JarEntry not a zipEntry * It actually returns a JarEntry not a zipEntry
* @param name XXX * @param name XXX
*/ */
public ZipEntry getEntry(String name) { public ZipEntry getEntry(String name)
{
ZipEntry entry = super.getEntry(name); ZipEntry entry = super.getEntry(name);
if (entry != null) { if (entry != null)
{
JarEntry jarEntry = new JarEntry(entry); JarEntry jarEntry = new JarEntry(entry);
if (manifest != null) { if (manifest != null)
{
jarEntry.attr = manifest.getAttributes(name); jarEntry.attr = manifest.getAttributes(name);
// XXX jarEntry.certs // XXX jarEntry.certs
} }
...@@ -249,8 +267,8 @@ public class JarFile extends ZipFile { ...@@ -249,8 +267,8 @@ public class JarFile extends ZipFile {
* @exception IOException XXX * @exception IOException XXX
*/ */
public synchronized InputStream getInputStream(ZipEntry entry) throws public synchronized InputStream getInputStream(ZipEntry entry) throws
ZipException, ZipException, IOException
IOException { {
return super.getInputStream(entry); // XXX verify return super.getInputStream(entry); // XXX verify
} }
...@@ -263,15 +281,17 @@ public class JarFile extends ZipFile { ...@@ -263,15 +281,17 @@ public class JarFile extends ZipFile {
* @param name the jar entry name to look up * @param name the jar entry name to look up
* @return the JarEntry if it exists, null otherwise * @return the JarEntry if it exists, null otherwise
*/ */
public JarEntry getJarEntry(String name) { public JarEntry getJarEntry(String name)
return (JarEntry)getEntry(name); {
return (JarEntry) getEntry(name);
} }
/** /**
* Returns the manifest for this JarFile or null when the JarFile does not * Returns the manifest for this JarFile or null when the JarFile does not
* contain a manifest file. * contain a manifest file.
*/ */
public Manifest getManifest() { public Manifest getManifest()
{
return manifest; return manifest;
} }
} }
...@@ -40,8 +40,8 @@ import java.util.zip.ZipInputStream; ...@@ -40,8 +40,8 @@ import java.util.zip.ZipInputStream;
* @author Mark Wielaard (mark@klomp.org) * @author Mark Wielaard (mark@klomp.org)
*/ */
public class JarInputStream extends ZipInputStream { public class JarInputStream extends ZipInputStream
{
// Fields // Fields
/** The manifest for this file or null when there was no manifest. */ /** The manifest for this file or null when there was no manifest. */
...@@ -64,7 +64,8 @@ public class JarInputStream extends ZipInputStream { ...@@ -64,7 +64,8 @@ public class JarInputStream extends ZipInputStream {
* @param in InputStream to read the jar from * @param in InputStream to read the jar from
* @exception IOException when an error occurs when opening or reading * @exception IOException when an error occurs when opening or reading
*/ */
public JarInputStream(InputStream in) throws IOException { public JarInputStream(InputStream in) throws IOException
{
this(in, true); this(in, true);
} }
...@@ -77,7 +78,8 @@ public class JarInputStream extends ZipInputStream { ...@@ -77,7 +78,8 @@ public class JarInputStream extends ZipInputStream {
* @param verify wheter or not to verify the manifest entries * @param verify wheter or not to verify the manifest entries
* @exception IOException when an error occurs when opening or reading * @exception IOException when an error occurs when opening or reading
*/ */
public JarInputStream(InputStream in, boolean verify) throws IOException { public JarInputStream(InputStream in, boolean verify) throws IOException
{
super(in); super(in);
readManifest(verify); readManifest(verify);
} }
...@@ -91,18 +93,22 @@ public class JarInputStream extends ZipInputStream { ...@@ -91,18 +93,22 @@ public class JarInputStream extends ZipInputStream {
* when false no check is performed * when false no check is performed
* @exception IOException if an error occurs while reading * @exception IOException if an error occurs while reading
*/ */
private void readManifest(boolean verify) throws IOException { private void readManifest(boolean verify) throws IOException
{
firstEntry = (JarEntry) super.getNextEntry(); firstEntry = (JarEntry) super.getNextEntry();
while ((firstEntry != null) && while ((firstEntry != null) &&
firstEntry.getName().startsWith("META-INF/")) { firstEntry.getName().startsWith("META-INF/"))
if(firstEntry.getName().equals(JarFile.MANIFEST_NAME)) { {
if (firstEntry.getName().equals(JarFile.MANIFEST_NAME))
{
manifest = new Manifest(this); manifest = new Manifest(this);
} }
firstEntry = (JarEntry) super.getNextEntry(); firstEntry = (JarEntry) super.getNextEntry();
} }
closeEntry(); closeEntry();
if (verify) { if (verify)
{
// XXX // XXX
} }
} }
...@@ -114,10 +120,12 @@ public class JarInputStream extends ZipInputStream { ...@@ -114,10 +120,12 @@ public class JarInputStream extends ZipInputStream {
* *
* @param name the name of the new entry * @param name the name of the new entry
*/ */
protected ZipEntry createZipEntry(String name) { protected ZipEntry createZipEntry(String name)
{
ZipEntry zipEntry = super.createZipEntry(name); ZipEntry zipEntry = super.createZipEntry(name);
JarEntry jarEntry = new JarEntry(zipEntry); JarEntry jarEntry = new JarEntry(zipEntry);
if (manifest != null) { if (manifest != null)
{
jarEntry.attr = manifest.getAttributes(name); jarEntry.attr = manifest.getAttributes(name);
} }
return jarEntry; return jarEntry;
...@@ -126,7 +134,8 @@ public class JarInputStream extends ZipInputStream { ...@@ -126,7 +134,8 @@ public class JarInputStream extends ZipInputStream {
/** /**
* Returns the Manifest for the jar file or null if there was no Manifest. * Returns the Manifest for the jar file or null if there was no Manifest.
*/ */
public Manifest getManifest() { public Manifest getManifest()
{
return manifest; return manifest;
} }
...@@ -139,12 +148,16 @@ public class JarInputStream extends ZipInputStream { ...@@ -139,12 +148,16 @@ public class JarInputStream extends ZipInputStream {
* *
* @exception IOException if an IO error occurs when reading the entry * @exception IOException if an IO error occurs when reading the entry
*/ */
public ZipEntry getNextEntry() throws IOException { public ZipEntry getNextEntry() throws IOException
{
ZipEntry entry; ZipEntry entry;
if (firstEntry != null) { if (firstEntry != null)
{
entry = firstEntry; entry = firstEntry;
firstEntry = null; firstEntry = null;
} else { }
else
{
entry = super.getNextEntry(); entry = super.getNextEntry();
} }
return entry; return entry;
...@@ -155,8 +168,9 @@ public class JarInputStream extends ZipInputStream { ...@@ -155,8 +168,9 @@ public class JarInputStream extends ZipInputStream {
* *
* @exception IOException if an IO error occurs when reading the entry * @exception IOException if an IO error occurs when reading the entry
*/ */
public JarEntry getNextJarEntry() throws IOException { public JarEntry getNextJarEntry() throws IOException
return (JarEntry)getNextEntry(); {
return (JarEntry) getNextEntry();
} }
/** /**
...@@ -168,7 +182,8 @@ public class JarInputStream extends ZipInputStream { ...@@ -168,7 +182,8 @@ public class JarInputStream extends ZipInputStream {
* @return XXX * @return XXX
* @exception IOException XXX * @exception IOException XXX
*/ */
public int read(byte[] buf, int off, int len) throws IOException { public int read(byte[]buf, int off, int len) throws IOException
{
// XXX if (verify) {} // XXX if (verify) {}
return super.read(buf, off, len); return super.read(buf, off, len);
} }
......
...@@ -39,8 +39,8 @@ import java.util.zip.ZipOutputStream; ...@@ -39,8 +39,8 @@ import java.util.zip.ZipOutputStream;
* @author Mark Wielaard (mark@klomp.org) * @author Mark Wielaard (mark@klomp.org)
*/ */
public class JarOutputStream extends ZipOutputStream { public class JarOutputStream extends ZipOutputStream
{
// Constructors // Constructors
/** /**
...@@ -49,7 +49,8 @@ public class JarOutputStream extends ZipOutputStream { ...@@ -49,7 +49,8 @@ public class JarOutputStream extends ZipOutputStream {
* @param out the stream to create the new jar on * @param out the stream to create the new jar on
* @exception IOException if something unexpected happend * @exception IOException if something unexpected happend
*/ */
public JarOutputStream(OutputStream out) throws IOException { public JarOutputStream(OutputStream out) throws IOException
{
this(out, null); this(out, null);
} }
...@@ -62,7 +63,8 @@ public class JarOutputStream extends ZipOutputStream { ...@@ -62,7 +63,8 @@ public class JarOutputStream extends ZipOutputStream {
* for no manifest entry * for no manifest entry
* @exception IOException if something unexpected happend * @exception IOException if something unexpected happend
*/ */
public JarOutputStream(OutputStream out, Manifest man) throws IOException { public JarOutputStream(OutputStream out, Manifest man) throws IOException
{
super(out); super(out);
if (man != null) if (man != null)
writeManifest(man); writeManifest(man);
...@@ -77,7 +79,8 @@ public class JarOutputStream extends ZipOutputStream { ...@@ -77,7 +79,8 @@ public class JarOutputStream extends ZipOutputStream {
* @param manifest the non null manifest to be written * @param manifest the non null manifest to be written
* @exception IOException if something unexpected happend * @exception IOException if something unexpected happend
*/ */
private void writeManifest(Manifest manifest) throws IOException { private void writeManifest(Manifest manifest) throws IOException
{
// Create a new Jar Entry for the Manifest // Create a new Jar Entry for the Manifest
JarEntry entry = new JarEntry(JarFile.MANIFEST_NAME); JarEntry entry = new JarEntry(JarFile.MANIFEST_NAME);
putNextEntry(entry); putNextEntry(entry);
...@@ -92,7 +95,8 @@ public class JarOutputStream extends ZipOutputStream { ...@@ -92,7 +95,8 @@ public class JarOutputStream extends ZipOutputStream {
* @param entry The information for the next entry * @param entry The information for the next entry
* @exception IOException when some unexpected I/O exception occured * @exception IOException when some unexpected I/O exception occured
*/ */
public void putNextEntry(ZipEntry entry) throws IOException { public void putNextEntry(ZipEntry entry) throws IOException
{
super.putNextEntry(entry); // XXX super.putNextEntry(entry); // XXX
} }
} }
...@@ -48,8 +48,8 @@ import java.util.Set; ...@@ -48,8 +48,8 @@ import java.util.Set;
* @since 1.2 * @since 1.2
* @author Mark Wielaard (mark@klomp.org) * @author Mark Wielaard (mark@klomp.org)
*/ */
public class Manifest implements Cloneable { public class Manifest implements Cloneable
{
// Fields // Fields
/** The main attributes of the manifest (jar file). */ /** The main attributes of the manifest (jar file). */
...@@ -63,7 +63,8 @@ public class Manifest implements Cloneable { ...@@ -63,7 +63,8 @@ public class Manifest implements Cloneable {
/** /**
* Creates a new empty Manifest. * Creates a new empty Manifest.
*/ */
public Manifest() { public Manifest()
{
mainAttr = new Attributes(); mainAttr = new Attributes();
entries = new Hashtable(); entries = new Hashtable();
} }
...@@ -78,7 +79,8 @@ public class Manifest implements Cloneable { ...@@ -78,7 +79,8 @@ public class Manifest implements Cloneable {
* @exception IOException when an i/o exception occurs or the input stream * @exception IOException when an i/o exception occurs or the input stream
* does not describe a valid manifest * does not describe a valid manifest
*/ */
public Manifest(InputStream in) throws IOException { public Manifest(InputStream in) throws IOException
{
this(); this();
read(in); read(in);
} }
...@@ -95,7 +97,8 @@ public class Manifest implements Cloneable { ...@@ -95,7 +97,8 @@ public class Manifest implements Cloneable {
* @see clone() * @see clone()
* @param man the Manifest to copy from * @param man the Manifest to copy from
*/ */
public Manifest (Manifest man) { public Manifest(Manifest man)
{
mainAttr = new Attributes(man.getMainAttributes()); mainAttr = new Attributes(man.getMainAttributes());
entries = new Hashtable(man.getEntries()); entries = new Hashtable(man.getEntries());
} }
...@@ -105,7 +108,8 @@ public class Manifest implements Cloneable { ...@@ -105,7 +108,8 @@ public class Manifest implements Cloneable {
/** /**
* Gets the main attributes of this Manifest. * Gets the main attributes of this Manifest.
*/ */
public Attributes getMainAttributes() { public Attributes getMainAttributes()
{
return mainAttr; return mainAttr;
} }
...@@ -114,7 +118,8 @@ public class Manifest implements Cloneable { ...@@ -114,7 +118,8 @@ public class Manifest implements Cloneable {
* in this manifest. Adding, changing or removing from this entries map * in this manifest. Adding, changing or removing from this entries map
* changes the entries of this manifest. * changes the entries of this manifest.
*/ */
public Map getEntries() { public Map getEntries()
{
return entries; return entries;
} }
...@@ -127,15 +132,17 @@ public class Manifest implements Cloneable { ...@@ -127,15 +132,17 @@ public class Manifest implements Cloneable {
* @param entryName the name of the entry to look up * @param entryName the name of the entry to look up
* @return the attributes associated with the entry or null when none * @return the attributes associated with the entry or null when none
*/ */
public Attributes getAttributes(String entryName) { public Attributes getAttributes(String entryName)
return (Attributes)getEntries().get(entryName); {
return (Attributes) getEntries().get(entryName);
} }
/** /**
* Clears the main attributes and removes all the entries from the * Clears the main attributes and removes all the entries from the
* manifest. * manifest.
*/ */
public void clear() { public void clear()
{
mainAttr.clear(); mainAttr.clear();
entries.clear(); entries.clear();
} }
...@@ -143,9 +150,10 @@ public class Manifest implements Cloneable { ...@@ -143,9 +150,10 @@ public class Manifest implements Cloneable {
/** /**
* XXX * XXX
*/ */
public void read(InputStream in) throws IOException { public void read(InputStream in) throws IOException
BufferedReader br = new BufferedReader( {
new InputStreamReader(in, "8859_1")); BufferedReader br =
new BufferedReader(new InputStreamReader(in, "8859_1"));
read_main_section(getMainAttributes(), br); read_main_section(getMainAttributes(), br);
read_individual_sections(getEntries(), br); read_individual_sections(getEntries(), br);
} }
...@@ -153,58 +161,72 @@ public class Manifest implements Cloneable { ...@@ -153,58 +161,72 @@ public class Manifest implements Cloneable {
// Private Static methods for reading the Manifest file from BufferedReader // Private Static methods for reading the Manifest file from BufferedReader
private static void read_main_section(Attributes attr, private static void read_main_section(Attributes attr,
BufferedReader br) throws BufferedReader br) throws IOException
IOException { {
read_version_info(attr, br); read_version_info(attr, br);
read_attributes(attr, br); read_attributes(attr, br);
} }
private static void read_version_info(Attributes attr, private static void read_version_info(Attributes attr,
BufferedReader br) throws BufferedReader br) throws IOException
IOException { {
String version_header = Attributes.Name.MANIFEST_VERSION.toString(); String version_header = Attributes.Name.MANIFEST_VERSION.toString();
try { try
{
String value = expect_header(version_header, br); String value = expect_header(version_header, br);
attr.putValue(version_header, value); attr.putValue(version_header, value);
} catch (IOException ioe) { }
throw new JarException( catch (IOException ioe)
"Manifest should start with a " + version_header {
+ ": " + ioe.getMessage()); throw new JarException("Manifest should start with a " +
version_header + ": " + ioe.getMessage());
} }
} }
private static String expect_header(String header, BufferedReader br) private static String expect_header(String header, BufferedReader br)
throws IOException { throws IOException
{
String s = br.readLine(); String s = br.readLine();
if (s == null) { if (s == null)
{
throw new JarException("unexpected end of file"); throw new JarException("unexpected end of file");
} }
return expect_header(header, br, s); return expect_header(header, br, s);
} }
private static String expect_header(String header, BufferedReader br, private static String expect_header(String header, BufferedReader br,
String s) throws IOException { String s) throws IOException
try { {
try
{
String name = s.substring(0, header.length() + 1); String name = s.substring(0, header.length() + 1);
if (name.equalsIgnoreCase(header + ":")) { if (name.equalsIgnoreCase(header + ":"))
{
String value_start = s.substring(header.length() + 2); String value_start = s.substring(header.length() + 2);
return read_header_value(value_start, br); return read_header_value(value_start, br);
} }
} catch (IndexOutOfBoundsException iobe) {} }
catch (IndexOutOfBoundsException iobe)
{
}
// If we arrive here, something went wrong // If we arrive here, something went wrong
throw new JarException("unexpected '" + s + "'"); throw new JarException("unexpected '" + s + "'");
} }
private static String read_header_value(String s, BufferedReader br) private static String read_header_value(String s, BufferedReader br)
throws IOException { throws IOException
{
boolean try_next = true; boolean try_next = true;
while (try_next) { while (try_next)
{
// Lets see if there is something on the next line // Lets see if there is something on the next line
br.mark(1); br.mark(1);
if (br.read() == ' ') { if (br.read() == ' ')
{
s += br.readLine(); s += br.readLine();
} else { }
else
{
br.reset(); br.reset();
try_next = false; try_next = false;
} }
...@@ -213,34 +235,40 @@ public class Manifest implements Cloneable { ...@@ -213,34 +235,40 @@ public class Manifest implements Cloneable {
} }
private static void read_attributes(Attributes attr, private static void read_attributes(Attributes attr,
BufferedReader br) throws BufferedReader br) throws IOException
IOException { {
String s = br.readLine(); String s = br.readLine();
while (s != null && (!s.equals(""))) { while (s != null && (!s.equals("")))
{
read_attribute(attr, s, br); read_attribute(attr, s, br);
s = br.readLine(); s = br.readLine();
} }
} }
private static void read_attribute(Attributes attr, String s, private static void read_attribute(Attributes attr, String s,
BufferedReader br) throws IOException { BufferedReader br) throws IOException
try { {
try
{
int colon = s.indexOf(": "); int colon = s.indexOf(": ");
String name = s.substring(0, colon); String name = s.substring(0, colon);
String value_start = s.substring(colon+2); String value_start = s.substring(colon + 2);
String value = read_header_value(value_start, br); String value = read_header_value(value_start, br);
attr.putValue(name, value); attr.putValue(name, value);
} catch (IndexOutOfBoundsException iobe) { }
throw new JarException( catch (IndexOutOfBoundsException iobe)
"Manifest contains a bad header: " + s); {
throw new JarException("Manifest contains a bad header: " + s);
} }
} }
private static void read_individual_sections(Map entries, private static void read_individual_sections(Map entries,
BufferedReader br) throws BufferedReader br) throws
IOException { IOException
{
String s = br.readLine(); String s = br.readLine();
while (s != null && (!s.equals(""))) { while (s != null && (!s.equals("")))
{
Attributes attr = read_section_name(s, br, entries); Attributes attr = read_section_name(s, br, entries);
read_attributes(attr, br); read_attributes(attr, br);
s = br.readLine(); s = br.readLine();
...@@ -248,31 +276,35 @@ public class Manifest implements Cloneable { ...@@ -248,31 +276,35 @@ public class Manifest implements Cloneable {
} }
private static Attributes read_section_name(String s, BufferedReader br, private static Attributes read_section_name(String s, BufferedReader br,
Map entries) throws Map entries) throws JarException
JarException { {
try { try
{
String name = expect_header("Name", br, s); String name = expect_header("Name", br, s);
Attributes attr = new Attributes(); Attributes attr = new Attributes();
entries.put(name, attr); entries.put(name, attr);
return attr; return attr;
} catch(IOException ioe) { }
catch (IOException ioe)
{
throw new JarException throw new JarException
("Section should start with a Name header: " ("Section should start with a Name header: " + ioe.getMessage());
+ ioe.getMessage());
} }
} }
/** /**
* XXX * XXX
*/ */
public void write(OutputStream out) throws IOException { public void write(OutputStream out) throws IOException
PrintWriter pw = new PrintWriter( {
new BufferedWriter( PrintWriter pw =
new OutputStreamWriter(out, "8859_1"))); new PrintWriter(new
BufferedWriter(new OutputStreamWriter(out, "8859_1")));
write_main_section(getMainAttributes(), pw); write_main_section(getMainAttributes(), pw);
pw.println(); pw.println();
write_individual_sections(getEntries(), pw); write_individual_sections(getEntries(), pw);
if (pw.checkError()) { if (pw.checkError())
{
throw new JarException("Error while writing manifest"); throw new JarException("Error while writing manifest");
} }
} }
...@@ -280,93 +312,107 @@ public class Manifest implements Cloneable { ...@@ -280,93 +312,107 @@ public class Manifest implements Cloneable {
// Private Static functions for writing the Manifest file to a PrintWriter // Private Static functions for writing the Manifest file to a PrintWriter
private static void write_main_section(Attributes attr, private static void write_main_section(Attributes attr,
PrintWriter pw) PrintWriter pw) throws JarException
throws JarException { {
write_version_info(attr, pw); write_version_info(attr, pw);
write_main_attributes(attr, pw); write_main_attributes(attr, pw);
} }
private static void write_version_info(Attributes attr, PrintWriter pw) { private static void write_version_info(Attributes attr, PrintWriter pw)
{
// First check if there is already a version attribute set // First check if there is already a version attribute set
String version = attr.getValue(Attributes.Name.MANIFEST_VERSION); String version = attr.getValue(Attributes.Name.MANIFEST_VERSION);
if (version == null) { if (version == null)
{
version = "1.0"; version = "1.0";
} }
write_header(Attributes.Name.MANIFEST_VERSION.toString(), version, pw); write_header(Attributes.Name.MANIFEST_VERSION.toString(), version, pw);
} }
private static void write_header(String name, String value, private static void write_header(String name, String value, PrintWriter pw)
PrintWriter pw) { {
pw.print(name + ": "); pw.print(name + ": ");
int last = 68 - name.length(); int last = 68 - name.length();
if (last > value.length()) { if (last > value.length())
{
pw.println(value); pw.println(value);
} else { }
else
{
pw.println(value.substring(0, last)); pw.println(value.substring(0, last));
} }
while (last < value.length()) { while (last < value.length())
{
pw.print(" "); pw.print(" ");
int end = (last + 69); int end = (last + 69);
if (end > value.length()) { if (end > value.length())
{
pw.println(value.substring(last)); pw.println(value.substring(last));
} else { }
else
{
pw.println(value.substring(last, end)); pw.println(value.substring(last, end));
} }
last = end; last = end;
} }
} }
private static void write_main_attributes(Attributes attr, private static void write_main_attributes(Attributes attr, PrintWriter pw)
PrintWriter pw) throws throws JarException
JarException { {
Iterator it = attr.entrySet().iterator(); Iterator it = attr.entrySet().iterator();
while(it.hasNext()) { while (it.hasNext())
Map.Entry entry = (Map.Entry)it.next(); {
Map.Entry entry = (Map.Entry) it.next();
// Don't print the manifest version again // Don't print the manifest version again
if (!Attributes.Name.MANIFEST_VERSION.equals(entry.getKey())) { if (!Attributes.Name.MANIFEST_VERSION.equals(entry.getKey()))
{
write_attribute_entry(entry, pw); write_attribute_entry(entry, pw);
} }
} }
} }
private static void write_attribute_entry(Map.Entry entry, private static void write_attribute_entry(Map.Entry entry, PrintWriter pw)
PrintWriter pw) throws throws JarException
JarException { {
String name = entry.getKey().toString(); String name = entry.getKey().toString();
String value = entry.getValue().toString(); String value = entry.getValue().toString();
if (name.equalsIgnoreCase("Name")) { if (name.equalsIgnoreCase("Name"))
{
throw new JarException("Attributes cannot be called 'Name'"); throw new JarException("Attributes cannot be called 'Name'");
} }
if (name.startsWith("From")) { if (name.startsWith("From"))
throw new JarException( {
"Header cannot start with the four letters 'From'" throw new
+ name); JarException("Header cannot start with the four letters 'From'" +
name);
} }
write_header(name, value, pw); write_header(name, value, pw);
} }
private static void write_individual_sections(Map entries, private static void write_individual_sections(Map entries, PrintWriter pw)
PrintWriter pw) throws JarException
throws JarException { {
Iterator it = entries.entrySet().iterator(); Iterator it = entries.entrySet().iterator();
while (it.hasNext()) { while (it.hasNext())
Map.Entry entry = (Map.Entry)it.next(); {
Map.Entry entry = (Map.Entry) it.next();
write_header("Name", entry.getKey().toString(), pw); write_header("Name", entry.getKey().toString(), pw);
write_entry_attributes((Attributes)entry.getValue(), pw); write_entry_attributes((Attributes) entry.getValue(), pw);
pw.println(); pw.println();
} }
} }
private static void write_entry_attributes(Attributes attr, private static void write_entry_attributes(Attributes attr, PrintWriter pw)
PrintWriter pw) throws throws JarException
JarException { {
Iterator it = attr.entrySet().iterator(); Iterator it = attr.entrySet().iterator();
while(it.hasNext()) { while (it.hasNext())
Map.Entry entry = (Map.Entry)it.next(); {
Map.Entry entry = (Map.Entry) it.next();
write_attribute_entry(entry, pw); write_attribute_entry(entry, pw);
} }
} }
...@@ -379,7 +425,8 @@ public class Manifest implements Cloneable { ...@@ -379,7 +425,8 @@ public class Manifest implements Cloneable {
* a particular entry also changes the attributes of that entry in the * a particular entry also changes the attributes of that entry in the
* original manifest. Calls <CODE>new Manifest(this)</CODE>. * original manifest. Calls <CODE>new Manifest(this)</CODE>.
*/ */
public Object clone() { public Object clone()
{
return new Manifest(this); return new Manifest(this);
} }
...@@ -389,17 +436,19 @@ public class Manifest implements Cloneable { ...@@ -389,17 +436,19 @@ public class Manifest implements Cloneable {
* Manifest and the main attributes and the entries of the other manifest * Manifest and the main attributes and the entries of the other manifest
* are equal to this one. * are equal to this one.
*/ */
public boolean equals(Object o) { public boolean equals(Object o)
{
return (o instanceof Manifest) && return (o instanceof Manifest) &&
(mainAttr.equals(((Manifest)o).mainAttr)) && (mainAttr.equals(((Manifest) o).mainAttr)) &&
(entries.equals(((Manifest)o).entries)); (entries.equals(((Manifest) o).entries));
} }
/** /**
* Calculates the hash code of the manifest. Implemented by a xor of the * Calculates the hash code of the manifest. Implemented by a xor of the
* hash code of the main attributes with the hash code of the entries map. * hash code of the main attributes with the hash code of the entries map.
*/ */
public int hashCode() { public int hashCode()
{
return mainAttr.hashCode() ^ entries.hashCode(); return mainAttr.hashCode() ^ entries.hashCode();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment