harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r410555 - in /incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar: Attributes.java InitManifest.java JarEntry.java
Date Wed, 31 May 2006 15:03:49 GMT
Author: tellison
Date: Wed May 31 08:03:48 2006
New Revision: 410555

URL: http://svn.apache.org/viewvc?rev=410555&view=rev
Log:
Source tidy-up and reformatting.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java?rev=410555&r1=410554&r2=410555&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
Wed May 31 08:03:48 2006
@@ -15,7 +15,6 @@
 
 package java.util.jar;
 
-
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
@@ -28,320 +27,326 @@
  */
 public class Attributes implements Cloneable, Map<Object, Object> {
 
-	protected Map<Object, Object> map;
+    protected Map<Object, Object> map;
+
+    public static class Name {
+        private String name;
+
+        private int hashCode;
+
+        public static final Name CLASS_PATH = new Name("Class-Path", false);
+
+        public static final Name MANIFEST_VERSION = new Name(
+                "Manifest-Version", false);
+
+        public static final Name MAIN_CLASS = new Name("Main-Class", false);
+
+        public static final Name SIGNATURE_VERSION = new Name(
+                "Signature-Version", false);
+
+        public static final Name CONTENT_TYPE = new Name("Content-Type", false);
+
+        public static final Name SEALED = new Name("Sealed", false);
+
+        public static final Name IMPLEMENTATION_TITLE = new Name(
+                "Implementation-Title", false);
+
+        public static final Name IMPLEMENTATION_VERSION = new Name(
+                "Implementation-Version", false);
+
+        public static final Name IMPLEMENTATION_VENDOR = new Name(
+                "Implementation-Vendor", false);
+
+        public static final Name SPECIFICATION_TITLE = new Name(
+                "Specification-Title", false);
+
+        public static final Name SPECIFICATION_VERSION = new Name(
+                "Specification-Version", false);
+
+        public static final Name SPECIFICATION_VENDOR = new Name(
+                "Specification-Vendor", false);
+
+        public static final Name EXTENSION_LIST = new Name("Extension-List",
+                false);
 
-	public static class Name {
-		private String name;
+        public static final Name EXTENSION_NAME = new Name("Extension-Name",
+                false);
 
-		private int hashCode;
+        public static final Name EXTENSION_INSTALLATION = new Name(
+                "Extension-Installation", false);
 
-		public static final Name CLASS_PATH = new Name("Class-Path", false);
+        public static final Name IMPLEMENTATION_VENDOR_ID = new Name(
+                "Implementation-Vendor-Id", false);
 
-		public static final Name MANIFEST_VERSION = new Name(
-				"Manifest-Version", false);
-
-		public static final Name MAIN_CLASS = new Name("Main-Class", false);
-
-		public static final Name SIGNATURE_VERSION = new Name(
-				"Signature-Version", false);
-
-		public static final Name CONTENT_TYPE = new Name("Content-Type", false);
-
-		public static final Name SEALED = new Name("Sealed", false);
-
-		public static final Name IMPLEMENTATION_TITLE = new Name(
-				"Implementation-Title", false);
-
-		public static final Name IMPLEMENTATION_VERSION = new Name(
-				"Implementation-Version", false);
-
-		public static final Name IMPLEMENTATION_VENDOR = new Name(
-				"Implementation-Vendor", false);
-
-		public static final Name SPECIFICATION_TITLE = new Name(
-				"Specification-Title", false);
-
-		public static final Name SPECIFICATION_VERSION = new Name(
-				"Specification-Version", false);
-
-		public static final Name SPECIFICATION_VENDOR = new Name(
-				"Specification-Vendor", false);
-
-		public static final Name EXTENSION_LIST = new Name("Extension-List",
-				false);
-
-		public static final Name EXTENSION_NAME = new Name("Extension-Name",
-				false);
-
-		public static final Name EXTENSION_INSTALLATION = new Name(
-				"Extension-Installation", false);
-
-		public static final Name IMPLEMENTATION_VENDOR_ID = new Name(
-				"Implementation-Vendor-Id", false);
-
-		public static final Name IMPLEMENTATION_URL = new Name(
-				"Implementation-URL", false);
-
-		public Name(String s) {
-			int i = s.length();
-			if (i == 0 || i > 70)
-				throw new IllegalArgumentException();
-			for (; --i >= 0;) {
-				char ch = s.charAt(i);
-				if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
-						|| ch == '_' || ch == '-' || (ch >= '0' && ch <= '9')))
-					throw new IllegalArgumentException(s);
-			}
-			name = s;
-		}
-
-		Name(String s, boolean ignored) {
-			name = s;
-		}
-
-		public String toString() {
-			return name;
-		}
-
-		public boolean equals(Object an) {
-			if (an == null)
-				return false;
-			return an.getClass() == this.getClass()
-					&& name.equalsIgnoreCase(((Name) an).name);
-		}
-
-		public int hashCode() {
-			if (hashCode == 0)
-				hashCode = name.toLowerCase().hashCode();
-			return hashCode;
-		}
-	}
-
-	/**
-	 * Constructs an Attributes instance
-	 */
-	public Attributes() {
-		map = new HashMap<Object, Object>();
-	}
-
-	/**
-	 * Constructs an Attributes instance obtaining keys and values from the
-	 * parameter Attributes, attrib
-	 * 
-	 * @param attrib
-	 *            The Attributes to obtain entries from.
-	 */
-	public Attributes(Attributes attrib) {
-		map = (Map<Object, Object>)((HashMap) attrib.map).clone();
-	}
-
-	/**
-	 * Constructs an Attributes instance with initial capacity of size size
-	 * 
-	 * @param size
-	 *            Initial size of this Attributes instance.
-	 */
-	public Attributes(int size) {
-		map = new HashMap<Object, Object>(size);
-	}
-
-	/**
-	 * Removes all key/value pairs from this Attributes.
-	 * 
-	 */
-	public void clear() {
-		map.clear();
-	}
-
-	/**
-	 * Determines whether this Attributes contains the specified key
-	 * 
-	 * 
-	 * @param key
-	 *            The key to search for.
-	 * @return true if the key is found, false otherwise
-	 */
-	public boolean containsKey(Object key) {
-		return map.containsKey(key);
-	}
-
-	/**
-	 * Determines whether this Attributes contains the specified value
-	 * 
-	 * @param value
-	 *            The value to search for.
-	 * @return true if the value is found, false otherwise
-	 */
-	public boolean containsValue(Object value) {
-		return map.containsValue(value);
-	}
-
-	/**
-	 * Returns a set containing MapEntry's for each of the key/value pairs
-	 * contained in this Attributes.
-	 * 
-	 * @return a set of MapEntry's
-	 */
-	public Set<Map.Entry<Object, Object>> entrySet() {
-		return map.entrySet();
-	}
-
-	/**
-	 * Returns the value associated with the parameter key
-	 * 
-	 * @param key
-	 *            The key to search for.
-	 * @return Object associated with key, or null if key does not exist.
-	 */
-	public Object get(Object key) {
-		return map.get(key);
-	}
-
-	/**
-	 * Determines whether this Attributes contains any keys
-	 * 
-	 * @return true if one or more keys exist, false otherwise
-	 */
-	public boolean isEmpty() {
-		return map.isEmpty();
-	}
-
-	/**
-	 * Returns a Set containing all the keys found in this Attributes.
-	 * 
-	 * @return a Set of all keys
-	 */
-	public Set<Object> keySet() {
-		return map.keySet();
-	}
-
-	/**
-	 * Store value in this Attributes and associate it with key.
-	 * 
-	 * @param key
-	 *            The key to associate with value.
-	 * @param value
-	 *            The value to store in this Attributes
-	 * @return The value being stored
-	 * 
-	 * @exception ClassCastException
-	 *                when key is not an Attributes.Name or value is not a
-	 *                String
-	 */
-	public Object put(Object key, Object value) {
-		return map.put((Name)key, (String)value);
-	}
-
-	/**
-	 * Store all the key.value pairs in the argument in this Attributes.
-	 * 
-	 * @param attrib
-	 *            the associations to store (must be of type Attributes).
-	 */
-	public void putAll(Map<?, ?> attrib) {
-        if( attrib == null ) {
+        public static final Name IMPLEMENTATION_URL = new Name(
+                "Implementation-URL", false);
+
+        public Name(String s) {
+            int i = s.length();
+            if (i == 0 || i > 70) {
+                throw new IllegalArgumentException();
+            }
+            for (; --i >= 0;) {
+                char ch = s.charAt(i);
+                if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' &&
ch <= 'Z')
+                        || ch == '_' || ch == '-' || (ch >= '0' && ch <= '9')))
{
+                    throw new IllegalArgumentException(s);
+                }
+            }
+            name = s;
+        }
+
+        Name(String s, boolean ignored) {
+            name = s;
+        }
+
+        public String toString() {
+            return name;
+        }
+
+        public boolean equals(Object an) {
+            if (an == null) {
+                return false;
+            }
+            return an.getClass() == this.getClass()
+                    && name.equalsIgnoreCase(((Name) an).name);
+        }
+
+        public int hashCode() {
+            if (hashCode == 0) {
+                hashCode = name.toLowerCase().hashCode();
+            }
+            return hashCode;
+        }
+    }
+
+    /**
+     * Constructs an Attributes instance
+     */
+    public Attributes() {
+        map = new HashMap<Object, Object>();
+    }
+
+    /**
+     * Constructs an Attributes instance obtaining keys and values from the
+     * parameter Attributes, attrib
+     * 
+     * @param attrib
+     *            The Attributes to obtain entries from.
+     */
+    public Attributes(Attributes attrib) {
+        map = (Map<Object, Object>) ((HashMap) attrib.map).clone();
+    }
+
+    /**
+     * Constructs an Attributes instance with initial capacity of size size
+     * 
+     * @param size
+     *            Initial size of this Attributes instance.
+     */
+    public Attributes(int size) {
+        map = new HashMap<Object, Object>(size);
+    }
+
+    /**
+     * Removes all key/value pairs from this Attributes.
+     * 
+     */
+    public void clear() {
+        map.clear();
+    }
+
+    /**
+     * Determines whether this Attributes contains the specified key
+     * 
+     * 
+     * @param key
+     *            The key to search for.
+     * @return true if the key is found, false otherwise
+     */
+    public boolean containsKey(Object key) {
+        return map.containsKey(key);
+    }
+
+    /**
+     * Determines whether this Attributes contains the specified value
+     * 
+     * @param value
+     *            The value to search for.
+     * @return true if the value is found, false otherwise
+     */
+    public boolean containsValue(Object value) {
+        return map.containsValue(value);
+    }
+
+    /**
+     * Returns a set containing MapEntry's for each of the key/value pairs
+     * contained in this Attributes.
+     * 
+     * @return a set of MapEntry's
+     */
+    public Set<Map.Entry<Object, Object>> entrySet() {
+        return map.entrySet();
+    }
+
+    /**
+     * Returns the value associated with the parameter key
+     * 
+     * @param key
+     *            The key to search for.
+     * @return Object associated with key, or null if key does not exist.
+     */
+    public Object get(Object key) {
+        return map.get(key);
+    }
+
+    /**
+     * Determines whether this Attributes contains any keys
+     * 
+     * @return true if one or more keys exist, false otherwise
+     */
+    public boolean isEmpty() {
+        return map.isEmpty();
+    }
+
+    /**
+     * Returns a Set containing all the keys found in this Attributes.
+     * 
+     * @return a Set of all keys
+     */
+    public Set<Object> keySet() {
+        return map.keySet();
+    }
+
+    /**
+     * Store value in this Attributes and associate it with key.
+     * 
+     * @param key
+     *            The key to associate with value.
+     * @param value
+     *            The value to store in this Attributes
+     * @return The value being stored
+     * 
+     * @exception ClassCastException
+     *                when key is not an Attributes.Name or value is not a
+     *                String
+     */
+    public Object put(Object key, Object value) {
+        return map.put(key, value);
+    }
+
+    /**
+     * Store all the key.value pairs in the argument in this Attributes.
+     * 
+     * @param attrib
+     *            the associations to store (must be of type Attributes).
+     */
+    public void putAll(Map<?, ?> attrib) {
+        if (attrib == null) {
             throw new ClassCastException();
         }
-		this.map.putAll((Attributes) attrib);
-	}
+        this.map.putAll(attrib);
+    }
+
+    /**
+     * Deletes the key/value pair with key key from this Attributes.
+     * 
+     * @param key
+     *            The key to remove
+     * @return the values associated with the removed key, null if not present.
+     */
+    public Object remove(Object key) {
+        return map.remove(key);
+    }
+
+    /**
+     * Returns the number of key.value pairs associated with this Attributes.
+     * 
+     * @return the size of this Attributes
+     */
+    public int size() {
+        return map.size();
+    }
+
+    /**
+     * Returns a Collection of all the values present in this Attributes.
+     * 
+     * @return a Collection of all values present
+     */
+    public Collection<Object> values() {
+        return map.values();
+    }
+
+    public Object clone() {
+        Attributes clone;
+        try {
+            clone = (Attributes) super.clone();
+        } catch (CloneNotSupportedException e) {
+            return null;
+        }
+        clone.map = (Map<Object, Object>) ((HashMap) this.map).clone();
+        return clone;
+    }
+
+    /**
+     * Returns the hashCode of this Attributes
+     * 
+     * @return the hashCode of this Object.
+     */
+    public int hashCode() {
+        return map.hashCode();
+    }
+
+    /**
+     * Determines if this Attributes and the parameter Attributes are equal. Two
+     * Attributes instances are equal if they contain the same keys and values.
+     * 
+     * @return true if the Attributes are equals, false otherwise
+     */
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof Attributes) {
+            return map.equals(((Attributes) obj).map);
+        }
+        return false;
+    }
 
-	/**
-	 * Deletes the key/value pair with key key from this Attributes.
-	 * 
-	 * @param key
-	 *            The key to remove
-	 * @return the values associated with the removed key, null if not present.
-	 */
-	public Object remove(Object key) {
-		return map.remove(key);
-	}
-
-	/**
-	 * Returns the number of key.value pairs associated with this Attributes.
-	 * 
-	 * @return the size of this Attributes
-	 */
-	public int size() {
-		return map.size();
-	}
-
-	/**
-	 * Returns a Collection of all the values present in this Attributes.
-	 * 
-	 * @return a Collection of all values present
-	 */
-	public Collection<Object> values() {
-		return map.values();
-	}
-
-	public Object clone() {
-		Attributes clone;
-		try {
-			clone = (Attributes) super.clone();
-		} catch (CloneNotSupportedException e) {
-			return null;
-		}
-		clone.map = (Map<Object, Object>) ((HashMap) this.map).clone();
-		return clone;
-	}
-
-	/**
-	 * Returns the hashCode of this Attributes
-	 * 
-	 * @return the hashCode of this Object.
-	 */
-	public int hashCode() {
-		return map.hashCode();
-	}
-
-	/**
-	 * Determines if this Attributes and the parameter Attributes are equal. Two
-	 * Attributes instances are equal if they contain the same keys and values.
-	 * 
-	 * @return true if the Attributes are equals, false otherwise
-	 */
-	public boolean equals(Object obj) {
-		if (this == obj)
-			return true;
-		if (obj instanceof Attributes)
-			return map.equals(((Attributes) obj).map);
-		return false;
-	}
-
-	/**
-	 * Returns the value associated with the parameter Attributes.Name key.
-	 * 
-	 * @param name
-	 *            The key to obtain the value for.
-	 * @return the String associated with name, or null if name is not a valid
-	 *         key
-	 */
-	public String getValue(Attributes.Name name) {
-		return (String) map.get(name);
-	}
-
-	/**
-	 * Returns the String associated with the parameter name.
-	 * 
-	 * @param name
-	 *            The key to obtain the value for.
-	 * @return the String associated with name, or null if name is not a valid
-	 *         key
-	 */
-	public String getValue(String name) {
-		return (String) map.get(new Attributes.Name(name));
-	}
-
-	/**
-	 * Stores value val against key name in this Attributes
-	 * 
-	 * @param name
-	 *            The key to store against.
-	 * @param val
-	 *            The value to store in this Attributes
-	 * @return the Value being stored
-	 */
-	public String putValue(String name, String val) {
-		return (String) map.put(new Attributes.Name(name), val);
-	}
+    /**
+     * Returns the value associated with the parameter Attributes.Name key.
+     * 
+     * @param name
+     *            The key to obtain the value for.
+     * @return the String associated with name, or null if name is not a valid
+     *         key
+     */
+    public String getValue(Attributes.Name name) {
+        return (String) map.get(name);
+    }
+
+    /**
+     * Returns the String associated with the parameter name.
+     * 
+     * @param name
+     *            The key to obtain the value for.
+     * @return the String associated with name, or null if name is not a valid
+     *         key
+     */
+    public String getValue(String name) {
+        return (String) map.get(new Attributes.Name(name));
+    }
+
+    /**
+     * Stores value val against key name in this Attributes
+     * 
+     * @param name
+     *            The key to store against.
+     * @param val
+     *            The value to store in this Attributes
+     * @return the Value being stored
+     */
+    public String putValue(String name, String val) {
+        return (String) map.put(new Attributes.Name(name), val);
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java?rev=410555&r1=410554&r2=410555&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
Wed May 31 08:03:48 2006
@@ -15,7 +15,6 @@
 
 package java.util.jar;
 
-
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -32,247 +31,265 @@
 import org.apache.harmony.luni.util.Util;
 
 class InitManifest {
-	private byte[] inbuf = new byte[1024];
+    private byte[] inbuf = new byte[1024];
 
-	private int inbufCount = 0, inbufPos = 0;
+    private int inbufCount = 0, inbufPos = 0;
 
-	private byte[] buffer = new byte[5];
+    private byte[] buffer = new byte[5];
 
-	private char[] charbuf = new char[0];
+    private char[] charbuf = new char[0];
 
-	private ByteArrayOutputStream out = new ByteArrayOutputStream(256);
-
-	private String encoding;
-
-	private boolean usingUTF8 = true;
-
-	private Map<String, Attributes.Name> attributeNames =
-        new HashMap<String, Attributes.Name>();
-
-	private byte[] mainAttributesChunk;
-
-	InitManifest(InputStream is, Attributes main, Map entries, Map chunks,
-			String verString) throws IOException {
-		encoding = (String) AccessController.doPrivileged(new PriviAction(
-				"manifest.read.encoding"));
-		if ("".equals(encoding)) {
-			encoding = null;
-		}
-
-		Attributes current = main;
-		ArrayList<String> list = new ArrayList<String>();
-
-		//Return the chunk of main attributes in the manifest.
-		mainAttributesChunk = nextChunk(is,list);		
-
-		Iterator it = list.iterator();
-		while (it.hasNext())
-			addAttribute((String) it.next(), current);
-
-		// Check for version attribute
-		if (verString != null && main.getValue(verString) == null)
-			throw new IOException(Msg.getString("K0009", verString));
-
-		list.clear();
-		byte[] chunk = null;
-		while (chunks == null ? readLines(is, list) : (chunk = nextChunk(is,
-				list)) != null) {
-			it = list.iterator();
-			String line = (String) it.next();
-			if (line.length() < 7
-					|| !line.substring(0, 5).toLowerCase().equals("name:"))
-				throw new IOException(Msg.getString("K000a"));
-			// Name: length required space char
-			String name = line.substring(6, line.length());
-			current = new Attributes(12);
-			if (chunks != null)
-				chunks.put(name, chunk);
-			entries.put(name, current);
-			while (it.hasNext())
-				addAttribute((String) it.next(), current);
-			list.clear();
-		}
-
-	}
-
-	byte[] getMainAttributesChunk()
-	{
-		return mainAttributesChunk;
-	}
-
-	private void addLine(int length, List<String> lines) throws IOException {
-		if (encoding != null) {
-			lines.add(new String(buffer, 0, length, encoding));
-		} else {
-			if (usingUTF8) {
-				try {
-					if (charbuf.length < length)
-						charbuf = new char[length];
-					lines.add(Util.convertUTF8WithBuf(buffer, charbuf, 0,
-							length));
-				} catch (UTFDataFormatException e) {
-					usingUTF8 = false;
-				}
-			}
-			if (!usingUTF8) {
-				if (charbuf.length < length)
-					charbuf = new char[length];
-				// If invalid UTF8, convert bytes to chars setting the upper
-				// bytes to zeros				
-				int charOffset = 0;
-				int offset = 0;
-				for (int i = length; --i >= 0;) {
-					charbuf[charOffset++] = (char) ((int) buffer[offset++] & 0xff);
-				}		
-				lines.add(new String(charbuf, 0, length));
-			}
-		}
-	}
-
-	private byte[] nextChunk(InputStream in, List<String> lines) throws IOException {
-		if (inbufCount == -1)
-			return null;
-		byte next;
-		int pos = 0;
-		boolean blankline = false, lastCr = false;
-		out.reset();
-		while (true) {
-			if (inbufPos == inbufCount) {
-				if ((inbufCount = in.read(inbuf)) == -1) {
-					if (out.size() == 0)
-						return null;
-					if (blankline)
-						addLine(pos, lines);
-					return out.toByteArray();
+    private ByteArrayOutputStream out = new ByteArrayOutputStream(256);
+
+    private String encoding;
+
+    private boolean usingUTF8 = true;
+
+    private Map<String, Attributes.Name> attributeNames = new HashMap<String, Attributes.Name>();
+
+    private byte[] mainAttributesChunk;
+
+    InitManifest(InputStream is, Attributes main, Map entries, Map chunks,
+            String verString) throws IOException {
+        encoding = (String) AccessController.doPrivileged(new PriviAction(
+                "manifest.read.encoding"));
+        if ("".equals(encoding)) {
+            encoding = null;
+        }
+
+        Attributes current = main;
+        ArrayList<String> list = new ArrayList<String>();
+
+        // Return the chunk of main attributes in the manifest.
+        mainAttributesChunk = nextChunk(is, list);
+
+        Iterator it = list.iterator();
+        while (it.hasNext()) {
+            addAttribute((String) it.next(), current);
+        }
+
+        // Check for version attribute
+        if (verString != null && main.getValue(verString) == null) {
+            throw new IOException(Msg.getString("K0009", verString));
+        }
+
+        list.clear();
+        byte[] chunk = null;
+        while (chunks == null ? readLines(is, list) : (chunk = nextChunk(is,
+                list)) != null) {
+            it = list.iterator();
+            String line = (String) it.next();
+            if (line.length() < 7
+                    || !line.substring(0, 5).toLowerCase().equals("name:")) {
+                throw new IOException(Msg.getString("K000a"));
+            }
+            // Name: length required space char
+            String name = line.substring(6, line.length());
+            current = new Attributes(12);
+            if (chunks != null) {
+                chunks.put(name, chunk);
+            }
+            entries.put(name, current);
+            while (it.hasNext()) {
+                addAttribute((String) it.next(), current);
+            }
+            list.clear();
+        }
+
+    }
+
+    byte[] getMainAttributesChunk() {
+        return mainAttributesChunk;
+    }
+
+    private void addLine(int length, List<String> lines) throws IOException {
+        if (encoding != null) {
+            lines.add(new String(buffer, 0, length, encoding));
+        } else {
+            if (usingUTF8) {
+                try {
+                    if (charbuf.length < length) {
+                        charbuf = new char[length];
+                    }
+                    lines.add(Util.convertUTF8WithBuf(buffer, charbuf, 0,
+                            length));
+                } catch (UTFDataFormatException e) {
+                    usingUTF8 = false;
+                }
+            }
+            if (!usingUTF8) {
+                if (charbuf.length < length) {
+                    charbuf = new char[length];
+                }
+                // If invalid UTF8, convert bytes to chars setting the upper
+                // bytes to zeros
+                int charOffset = 0;
+                int offset = 0;
+                for (int i = length; --i >= 0;) {
+                    charbuf[charOffset++] = (char) (buffer[offset++] & 0xff);
+                }
+                lines.add(new String(charbuf, 0, length));
+            }
+        }
+    }
+
+    private byte[] nextChunk(InputStream in, List<String> lines)
+            throws IOException {
+        if (inbufCount == -1) {
+            return null;
+        }
+        byte next;
+        int pos = 0;
+        boolean blankline = false, lastCr = false;
+        out.reset();
+        while (true) {
+            if (inbufPos == inbufCount) {
+                if ((inbufCount = in.read(inbuf)) == -1) {
+                    if (out.size() == 0) {
+                        return null;
+                    }
+                    if (blankline) {
+                        addLine(pos, lines);
+                    }
+                    return out.toByteArray();
+                } else {
+                    if (inbufCount == inbuf.length && in.available() == 0) {
+                        /* KA000 = "line too long" */
+                        throw new IOException(Msg.getString("KA000"));
+                    }
+                }
+                inbufPos = 0;
+            }
+            next = inbuf[inbufPos++];
+            if (lastCr) {
+                if (next != '\n') {
+                    inbufPos--;
+                    next = '\r';
+                } else {
+                    if (out.size() == 0) {
+                        continue;
+                    }
+                    out.write('\r');
+                }
+                lastCr = false;
+            } else if (next == '\r') {
+                lastCr = true;
+                continue;
+            }
+            if (blankline) {
+                if (next == ' ') {
+                    out.write(next);
+                    blankline = false;
+                    continue;
+                }
+                addLine(pos, lines);
+                if (next == '\n') {
+                    out.write(next);
+                    return out.toByteArray();
+                }
+                pos = 0;
+            } else if (next == '\n') {
+                if (out.size() == 0) {
+                    continue;
+                }
+                out.write(next);
+                blankline = true;
+                continue;
+            }
+            blankline = false;
+            out.write(next);
+            if (pos == buffer.length) {
+                byte[] newBuf = new byte[buffer.length * 2];
+                System.arraycopy(buffer, 0, newBuf, 0, buffer.length);
+                buffer = newBuf;
+            }
+            buffer[pos++] = next;
+        }
+    }
+
+    private boolean readLines(InputStream in, List<String> lines)
+            throws IOException {
+        if (inbufCount == -1) {
+            return false;
+        }
+        byte next;
+        int pos = 0;
+        boolean blankline = false, lastCr = false;
+        while (true) {
+            if (inbufPos == inbufCount) {
+                if ((inbufCount = in.read(inbuf)) == -1) {
+                    if (blankline) {
+                        addLine(pos, lines);
+                    }
+                    return lines.size() != 0;
                 } else {
                     if (inbufCount == inbuf.length && in.available() == 0) {
                         /* KA000 = "line too long" */
                         throw new IOException(Msg.getString("KA000"));
-				}
-                } 
-				inbufPos = 0;
-			}
-			next = inbuf[inbufPos++];
-			if (lastCr) {
-				if (next != '\n') {
-					inbufPos--;
-					next = '\r';
-				} else {
-					if (out.size() == 0)
-						continue;
-					out.write('\r');
-				}
-				lastCr = false;
-			} else if (next == '\r') {
-				lastCr = true;
-				continue;
-			}
-			if (blankline) {
-				if (next == ' ') {
-					out.write(next);
-					blankline = false;
-					continue;
-				}
-				addLine(pos, lines);
-				if (next == '\n') {
-					out.write(next);
-					return out.toByteArray();
-				}
-				pos = 0;
-			} else if (next == '\n') {
-				if (out.size() == 0)
-					continue;
-				out.write(next);
-				blankline = true;
-				continue;
-			}
-			blankline = false;
-			out.write(next);
-			if (pos == buffer.length) {
-				byte[] newBuf = new byte[buffer.length * 2];
-				System.arraycopy(buffer, 0, newBuf, 0, buffer.length);
-				buffer = newBuf;
-			}
-			buffer[pos++] = next;
-		}
-	}
-
-	private boolean readLines(InputStream in, List<String> lines) throws IOException {
-		if (inbufCount == -1)
-			return false;
-		byte next;
-		int pos = 0;
-		boolean blankline = false, lastCr = false;
-		while (true) {
-			if (inbufPos == inbufCount) {
-				if ((inbufCount = in.read(inbuf)) == -1) {
-					if (blankline)
-						addLine(pos, lines);
-					return lines.size() != 0;
-				} else {
-					if (inbufCount == inbuf.length && in.available() == 0) {
-						/* KA000 = "line too long" */
-						throw new IOException(Msg.getString("KA000"));
-					}
-				} 
-				inbufPos = 0;
-			}
-			next = inbuf[inbufPos++];
-			if (lastCr) {
-				if (next != '\n') {
-					inbufPos--;
-					next = '\r';
-				}
-				lastCr = false;
-			} else if (next == '\r') {
-				lastCr = true;
-				continue;
-			}
-			if (blankline) {
-				if (next == ' ') {
-					blankline = false;
-					continue;
-				}
-				addLine(pos, lines);
-				if (next == '\n')
-					return true;
-				pos = 0;
-			} else if (next == '\n') {
-				if (pos == 0 && lines.size() == 0)
-					continue;
-				blankline = true;
-				continue;
-			}
-			blankline = false;
-			if (pos == buffer.length) {
-				byte[] newBuf = new byte[buffer.length * 2];
-				System.arraycopy(buffer, 0, newBuf, 0, buffer.length);
-				buffer = newBuf;
-			}
-			buffer[pos++] = next;
-		}
-	}
-
-	/* Get the next attribute and add it */
-	private void addAttribute(String line, Attributes current)
-			throws IOException {
-		String header;
-		int hdrIdx = line.indexOf(':');
-		if (hdrIdx < 1)
-			throw new IOException(Msg.getString("K000b", line));
-		header = line.substring(0, hdrIdx);
-		Attributes.Name name = (Attributes.Name) attributeNames.get(header);
-		if (name == null) {
-			try {
-				name = new Attributes.Name(header);
-			} catch (IllegalArgumentException e) {
-				throw new IOException(e.toString());
-			}
-			attributeNames.put(header, name);
-		}
-		if (hdrIdx + 1 >= line.length() || line.charAt(hdrIdx + 1) != ' ')
-			throw new IOException(Msg.getString("K000b", line));
-		// +2 due to required SPACE char
-		current.put(name, line.substring(hdrIdx + 2, line.length()));
-	}
+                    }
+                }
+                inbufPos = 0;
+            }
+            next = inbuf[inbufPos++];
+            if (lastCr) {
+                if (next != '\n') {
+                    inbufPos--;
+                    next = '\r';
+                }
+                lastCr = false;
+            } else if (next == '\r') {
+                lastCr = true;
+                continue;
+            }
+            if (blankline) {
+                if (next == ' ') {
+                    blankline = false;
+                    continue;
+                }
+                addLine(pos, lines);
+                if (next == '\n') {
+                    return true;
+                }
+                pos = 0;
+            } else if (next == '\n') {
+                if (pos == 0 && lines.size() == 0) {
+                    continue;
+                }
+                blankline = true;
+                continue;
+            }
+            blankline = false;
+            if (pos == buffer.length) {
+                byte[] newBuf = new byte[buffer.length * 2];
+                System.arraycopy(buffer, 0, newBuf, 0, buffer.length);
+                buffer = newBuf;
+            }
+            buffer[pos++] = next;
+        }
+    }
+
+    /* Get the next attribute and add it */
+    private void addAttribute(String line, Attributes current)
+            throws IOException {
+        String header;
+        int hdrIdx = line.indexOf(':');
+        if (hdrIdx < 1) {
+            throw new IOException(Msg.getString("K000b", line));
+        }
+        header = line.substring(0, hdrIdx);
+        Attributes.Name name = attributeNames.get(header);
+        if (name == null) {
+            try {
+                name = new Attributes.Name(header);
+            } catch (IllegalArgumentException e) {
+                throw new IOException(e.toString());
+            }
+            attributeNames.put(header, name);
+        }
+        if (hdrIdx + 1 >= line.length() || line.charAt(hdrIdx + 1) != ' ') {
+            throw new IOException(Msg.getString("K000b", line));
+        }
+        // +2 due to required SPACE char
+        current.put(name, line.substring(hdrIdx + 2, line.length()));
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java?rev=410555&r1=410554&r2=410555&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarEntry.java
Wed May 31 08:03:48 2006
@@ -29,170 +29,172 @@
 import javax.security.auth.x500.X500Principal;
 
 public class JarEntry extends ZipEntry {
-	private Attributes attributes;
+    private Attributes attributes;
 
-	JarFile parentJar;
+    JarFile parentJar;
 
-	Certificate certificates[];
+    Certificate certificates[];
 
-	CodeSigner signers[];
+    CodeSigner signers[];
 
-	// Cached factory used to build CertPath-s in <code>getCodeSigners()</code>.
-	private CertificateFactory factory;
-
-	private boolean isFactoryChecked = false;
-
-	/**
-	 * Create a new JarEntry named name
-	 * 
-	 * @param name
-	 *            The name of the new JarEntry
-	 */
-	public JarEntry(String name) {
-		super(name);
-	}
-
-	/**
-	 * Create a new JarEntry using the values obtained from entry.
-	 * 
-	 * @param entry
-	 *            The ZipEntry to obtain values from.
-	 */
-	public JarEntry(ZipEntry entry) {
-		super(entry);
-	}
-
-	/**
-	 * Returns the Attributes object associated with this entry or null if none
-	 * exists.
-	 * 
-	 * @return java.util.jar.Attributes Attributes for this entry
-	 * @exception java.io.IOException
-	 *                If an error occurs obtaining the Attributes
-	 */
-	public Attributes getAttributes() throws IOException {
-		if (attributes != null || parentJar == null)
-			return attributes;
-		Manifest manifest = parentJar.getManifest();
-		if (manifest == null)
-			return null;
-		return attributes = manifest.getAttributes(getName());
-	}
-
-	/**
-	 * Returns an array of Certificate Objects associated with this entry or
-	 * null if none exist.
-	 * 
-	 * @return java.security.cert.Certificate[] Certificates for this entry
-	 */
-	public Certificate[] getCertificates() {
-		return certificates;
-	}
-
-	void setAttributes(Attributes attrib) {
-		attributes = attrib;
-	}
-
-	/**
-	 * Create a new JarEntry using the values obtained from je.
-	 * 
-	 * @param je
-	 *            The JarEntry to obtain values from
-	 */
-	public JarEntry(JarEntry je) {
-		super(je);
-		parentJar = je.parentJar;
-		attributes = je.attributes;
-		certificates = je.certificates;
-		signers = je.signers;
-
-	}
-
-	/**
-	 * Returns the code signers for the jar entry. If there is no such code
-	 * signers, returns null. Only when the jar entry has been completely
-	 * verified by reading till the end of the jar entry, can the method be
-	 * called. Or else the method will return null.
-	 * 
-	 * @return the code signers for the jar entry.
-	 */
-	public CodeSigner[] getCodeSigners() {
-		if (null == signers) {
-			signers = getCodeSigners(certificates);
-
-		}
-		if (null == signers) {
-			return null;
-		}
-
-		CodeSigner[] tmp = new CodeSigner[signers.length];
-		System.arraycopy(signers, 0, tmp, 0, tmp.length);
-		return tmp;
-
-	}
-
-	private CodeSigner[] getCodeSigners(Certificate[] certs) {
-
-		X500Principal prevIssuer = null;
-		ArrayList<Certificate> list = new ArrayList<Certificate>(certs.length);
-		ArrayList<CodeSigner> asigners = new ArrayList<CodeSigner>();
-
-		for (int i = 0; i < certs.length; i++) {
-			if (!(certs[i] instanceof X509Certificate)) {
-				// Only X509CErtificate-s are taken into account - see API spec.
-				continue;
-			}
-			X509Certificate x509 = (X509Certificate) certs[i];
-			if (null != prevIssuer) {
-				X500Principal subj = x509.getSubjectX500Principal();
-				if (!prevIssuer.equals(subj)) {
-					// Ok, this ends the previous chain,
-					// so transform this one into CertPath ...
-					addCodeSigner(asigners, list);
-					// ... and start a new one
-					list.clear();
-				}// else { it's still the same chain }
-
-			}
-			prevIssuer = x509.getIssuerX500Principal();
-			list.add(x509);
-		}
-		if (!list.isEmpty()) {
-			addCodeSigner(asigners, list);
-		}
-		if (asigners.isEmpty()) {
-			// 'signers' is 'null' already
-			return null;
-		}
-
-		CodeSigner[] tmp = new CodeSigner[asigners.size()];
-		asigners.toArray(tmp);
-		return tmp;
-
-	}
-
-	private void addCodeSigner(ArrayList<CodeSigner> asigners,
-			List<Certificate> list) {
-		CertPath certPath = null;
-		if (!isFactoryChecked) {
-			try {
-				factory = CertificateFactory.getInstance("X.509");
-			} catch (CertificateException ex) {
-				// do nothing
-			} finally {
-				isFactoryChecked = true;
-			}
-		}
-		if (null == factory) {
-			return;
-		}
-		try {
-			certPath = factory.generateCertPath(list);
-		} catch (CertificateException ex) {
-			// do nothing
-		}
-		if (null != certPath) {
-			asigners.add(new CodeSigner(certPath, null));
-		}
-	}
+    // Cached factory used to build CertPath-s in <code>getCodeSigners()</code>.
+    private CertificateFactory factory;
+
+    private boolean isFactoryChecked = false;
+
+    /**
+     * Create a new JarEntry named name
+     * 
+     * @param name
+     *            The name of the new JarEntry
+     */
+    public JarEntry(String name) {
+        super(name);
+    }
+
+    /**
+     * Create a new JarEntry using the values obtained from entry.
+     * 
+     * @param entry
+     *            The ZipEntry to obtain values from.
+     */
+    public JarEntry(ZipEntry entry) {
+        super(entry);
+    }
+
+    /**
+     * Returns the Attributes object associated with this entry or null if none
+     * exists.
+     * 
+     * @return java.util.jar.Attributes Attributes for this entry
+     * @exception java.io.IOException
+     *                If an error occurs obtaining the Attributes
+     */
+    public Attributes getAttributes() throws IOException {
+        if (attributes != null || parentJar == null) {
+            return attributes;
+        }
+        Manifest manifest = parentJar.getManifest();
+        if (manifest == null) {
+            return null;
+        }
+        return attributes = manifest.getAttributes(getName());
+    }
+
+    /**
+     * Returns an array of Certificate Objects associated with this entry or
+     * null if none exist.
+     * 
+     * @return java.security.cert.Certificate[] Certificates for this entry
+     */
+    public Certificate[] getCertificates() {
+        return certificates;
+    }
+
+    void setAttributes(Attributes attrib) {
+        attributes = attrib;
+    }
+
+    /**
+     * Create a new JarEntry using the values obtained from je.
+     * 
+     * @param je
+     *            The JarEntry to obtain values from
+     */
+    public JarEntry(JarEntry je) {
+        super(je);
+        parentJar = je.parentJar;
+        attributes = je.attributes;
+        certificates = je.certificates;
+        signers = je.signers;
+
+    }
+
+    /**
+     * Returns the code signers for the jar entry. If there is no such code
+     * signers, returns null. Only when the jar entry has been completely
+     * verified by reading till the end of the jar entry, can the method be
+     * called. Or else the method will return null.
+     * 
+     * @return the code signers for the jar entry.
+     */
+    public CodeSigner[] getCodeSigners() {
+        if (null == signers) {
+            signers = getCodeSigners(certificates);
+
+        }
+        if (null == signers) {
+            return null;
+        }
+
+        CodeSigner[] tmp = new CodeSigner[signers.length];
+        System.arraycopy(signers, 0, tmp, 0, tmp.length);
+        return tmp;
+
+    }
+
+    private CodeSigner[] getCodeSigners(Certificate[] certs) {
+
+        X500Principal prevIssuer = null;
+        ArrayList<Certificate> list = new ArrayList<Certificate>(certs.length);
+        ArrayList<CodeSigner> asigners = new ArrayList<CodeSigner>();
+
+        for (Certificate element : certs) {
+            if (!(element instanceof X509Certificate)) {
+                // Only X509CErtificate-s are taken into account - see API spec.
+                continue;
+            }
+            X509Certificate x509 = (X509Certificate) element;
+            if (null != prevIssuer) {
+                X500Principal subj = x509.getSubjectX500Principal();
+                if (!prevIssuer.equals(subj)) {
+                    // Ok, this ends the previous chain,
+                    // so transform this one into CertPath ...
+                    addCodeSigner(asigners, list);
+                    // ... and start a new one
+                    list.clear();
+                }// else { it's still the same chain }
+
+            }
+            prevIssuer = x509.getIssuerX500Principal();
+            list.add(x509);
+        }
+        if (!list.isEmpty()) {
+            addCodeSigner(asigners, list);
+        }
+        if (asigners.isEmpty()) {
+            // 'signers' is 'null' already
+            return null;
+        }
+
+        CodeSigner[] tmp = new CodeSigner[asigners.size()];
+        asigners.toArray(tmp);
+        return tmp;
+
+    }
+
+    private void addCodeSigner(ArrayList<CodeSigner> asigners,
+            List<Certificate> list) {
+        CertPath certPath = null;
+        if (!isFactoryChecked) {
+            try {
+                factory = CertificateFactory.getInstance("X.509");
+            } catch (CertificateException ex) {
+                // do nothing
+            } finally {
+                isFactoryChecked = true;
+            }
+        }
+        if (null == factory) {
+            return;
+        }
+        try {
+            certPath = factory.generateCertPath(list);
+        } catch (CertificateException ex) {
+            // do nothing
+        }
+        if (null != certPath) {
+            asigners.add(new CodeSigner(certPath, null));
+        }
+    }
 }



Mime
View raw message