harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [91/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win.I...
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/BASE64Encoder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/BASE64Encoder.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/BASE64Encoder.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/BASE64Encoder.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,101 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+/**
+ * This class encodes strings or byte arrays into base 64 according to the the
+ * specification given by the RFC 1521 (5.2).
+ */
+public class BASE64Encoder {
+	static char digits[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+			'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
+			'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
+			'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+			'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+			'+', '/' };
+
+	/**
+	 * Constructs an instance of this class.
+	 */
+	private BASE64Encoder() {
+		super();
+	}
+
+	/**
+	 * This method encodes the byte array into a char array in base 64 according
+	 * to the specification given by the RFC 1521 (5.2).
+	 * 
+	 * @param data
+	 *            char[] the encoded char array
+	 * @return byte[] the byte array that needs to be encoded
+	 */
+	public static byte[] encode(byte[] data) {
+		int sourceChunks = data.length / 3;
+		int len = ((data.length + 2) / 3) * 4;
+		byte[] result = new byte[len];
+		int extraBytes = data.length - (sourceChunks * 3);
+		// Each 4 bytes of input (encoded) we end up with 3 bytes of output
+		int dataIndex = 0;
+		int resultIndex = 0;
+		int allBits = 0;
+		for (int i = 0; i < sourceChunks; i++) {
+			allBits = 0;
+			// Loop 3 times gathering input bits (3 * 8 = 24)
+			for (int j = 0; j < 3; j++) {
+				allBits = (allBits << 8) | (data[dataIndex++] & 0xff);
+			}
+
+			// Loop 4 times generating output bits (4 * 6 = 24)
+			for (int j = resultIndex + 3; j >= resultIndex; j--) {
+				result[j] = (byte) digits[(allBits & 0x3f)]; // Bottom 6 bits
+				allBits = allBits >>> 6;
+			}
+			resultIndex += 4; // processed 4 result bytes
+		}
+		// Now we do the extra bytes in case the original (non-encoded) data
+		// is not multiple of 4 bytes
+		switch (extraBytes) {
+		case 1:
+			allBits = data[dataIndex++]; // actual byte
+			allBits = allBits << 8; // 8 bits of zeroes
+			allBits = allBits << 8; // 8 bits of zeroes
+			// Loop 4 times generating output bits (4 * 6 = 24)
+			for (int j = resultIndex + 3; j >= resultIndex; j--) {
+				result[j] = (byte) digits[(allBits & 0x3f)]; // Bottom 6 bits
+				allBits = allBits >>> 6;
+			}
+			// 2 pad tags
+			result[result.length - 1] = (byte) '=';
+			result[result.length - 2] = (byte) '=';
+			break;
+		case 2:
+			allBits = data[dataIndex++]; // actual byte
+			allBits = (allBits << 8) | (data[dataIndex++] & 0xff); // actual
+																	// byte
+			allBits = allBits << 8; // 8 bits of zeroes
+			// Loop 4 times generating output bits (4 * 6 = 24)
+			for (int j = resultIndex + 3; j >= resultIndex; j--) {
+				result[j] = (byte) digits[(allBits & 0x3f)]; // Bottom 6 bits
+				allBits = allBits >>> 6;
+			}
+			// 1 pad tag
+			result[result.length - 1] = (byte) '=';
+			break;
+		}
+		return result;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/BinarySearch.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/BinarySearch.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/BinarySearch.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/BinarySearch.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,70 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+public class BinarySearch {
+
+	/**
+	 * Search the sorted characters in the string and return an exact index or
+	 * -1.
+	 * 
+	 * @param data
+	 *            the String to search
+	 * @param value
+	 *            the character to search for
+	 * @return the matching index, or -1
+	 */
+	public static int binarySearch(String data, char value) {
+		int low = 0, high = data.length() - 1;
+		while (low <= high) {
+			int mid = (low + high) >> 1;
+			char target = data.charAt(mid);
+			if (value == target)
+				return mid;
+			else if (value < target)
+				high = mid - 1;
+			else
+				low = mid + 1;
+		}
+		return -1;
+	}
+
+	/**
+	 * Search the sorted characters in the string and return the nearest index.
+	 * 
+	 * @param data
+	 *            the String to search
+	 * @param c
+	 *            the character to search for
+	 * @return the nearest index
+	 */
+	public static int binarySearchRange(String data, char c) {
+		char value = 0;
+		int low = 0, mid = -1, high = data.length() - 1;
+		while (low <= high) {
+			mid = (low + high) >> 1;
+			value = data.charAt(mid);
+			if (c > value)
+				low = mid + 1;
+			else if (c == value)
+				return mid;
+			else
+				high = mid - 1;
+		}
+		return mid - (c < value ? 1 : 0);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/DefaultPolicy.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/DefaultPolicy.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/DefaultPolicy.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/DefaultPolicy.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,686 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Constructor;
+import java.net.JarURLConnection;
+import java.net.MalformedURLException;
+import java.net.SocketPermission;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.AllPermission;
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Permissions;
+import java.security.Policy;
+import java.security.PrivilegedAction;
+import java.security.Security;
+import java.util.Enumeration;
+import java.util.PropertyPermission;
+import java.util.Vector;
+
+/**
+ * This is a policy class that supports security access based in policy files as
+ * defined in 1.2.2
+ */
+public class DefaultPolicy extends Policy {
+	// a list of grant entries with special criteria
+	private Vector grantList = new Vector();
+
+	// flag indicating that the policy has been read
+	private boolean policyRead = false;
+
+	public DefaultPolicy() {
+	}
+
+	/**
+	 * Answers a PermissionCollection describing what permissions are available
+	 * to the given CodeSource based on the current security policy.
+	 * <p>
+	 * Note that this method is <em>not</em> called for classes which are in
+	 * the system domain (i.e. system classes). System classes are
+	 * <em>always</em> given full permissions (i.e. AllPermission). This can
+	 * not be changed by installing a new Policy.
+	 * 
+	 * @param cs
+	 *            CodeSource the code source to compute the permissions for.
+	 * @return PermissionCollection the permissions the code source should have.
+	 */
+	public PermissionCollection getPermissions(CodeSource cs) {
+		// obtain the permissions list
+		final CodeSource codeSource = cs;
+		PrivilegedAction action = new PrivilegedAction() {
+			public Object run() {
+				return getPermissionsImpl(codeSource);
+			}
+		};
+
+		return (PermissionCollection) AccessController.doPrivileged(action,
+				null);
+	}
+
+	/**
+	 * Answers a PermissionCollection describing what permissions are available
+	 * to the given CodeSource based on the current security policy.
+	 * <p>
+	 * Note that this method is <em>not</em> called for classes which are in
+	 * the system domain (i.e. system classes). System classes are
+	 * <em>always</em> given full permissions (i.e. AllPermission). This can
+	 * not be changed by installing a new Policy.
+	 * 
+	 * @param cs
+	 *            CodeSource the code source to compute the permissions for.
+	 * @return PermissionCollection the permissions the code source should have.
+	 */
+	PermissionCollection getPermissionsImpl(CodeSource cs) {
+		// if the policy has not been read, read it in now
+		if (!policyRead) {
+			getSystemPolicy();
+		}
+
+		// see if the CodeSource matches any in the grantList
+
+		URL hisURL = cs.getLocation() != null ? toCanonicalURL(cs.getLocation())
+				: null;
+		PermissionCollection pc = new Permissions();
+		CodeSource hisCS = new CodeSource(hisURL, cs.getCertificates());
+		for (int i = 0; i < grantList.size(); i++) {
+			GrantHolder grant = (GrantHolder) grantList.elementAt(i);
+			// a GrantHolder with a null codesource means it applies to
+			// everything
+			if ((grant.getCodeSource() == null)
+					|| (grant.getCodeSource().implies(hisCS))) {
+				Permissions grantPermissions = grant.getPermissions();
+				Enumeration ePerm = grantPermissions.elements();
+				while (ePerm.hasMoreElements()) {
+					pc.add((Permission) ePerm.nextElement());
+				}
+			}
+		}
+		return pc;
+	}
+
+	/**
+	 * stores the contents of a grant entry from the policy file
+	 */
+	static class GrantHolder {
+		// holds the source these permissions apply to
+		private CodeSource codeSource;
+
+		// list of people the code must be signed by to have these permissions
+		// applied
+		private String signedBy;
+
+		// the list of permissions applied to code matching the criteria
+		private Permissions permissions;
+
+		/**
+		 * sets the codeSource for the receiver
+		 * 
+		 * @param codeSource
+		 *            CodeSource the code source these permissions apply to
+		 */
+		void setCodeSource(CodeSource codeSource) {
+			this.codeSource = codeSource;
+		}
+
+		/**
+		 * answers the codeSource of the receiver
+		 * 
+		 * @return CodeSource
+		 */
+		CodeSource getCodeSource() {
+			return this.codeSource;
+		}
+
+		/**
+		 * answers the permissions collection of the receiver
+		 * 
+		 * @return Permissions
+		 */
+		Permissions getPermissions() {
+			return this.permissions;
+		}
+
+		/**
+		 * set the code's signer(s)
+		 * 
+		 * @param signedBy
+		 *            String
+		 */
+		void setSigner(String signedBy) {
+			this.signedBy = signedBy;
+		}
+
+		/**
+		 * answers with the code's signer(s)
+		 * 
+		 * @return String
+		 */
+		String getSigner() {
+			return this.signedBy;
+		}
+
+		/**
+		 * adds a permission to the permissions list
+		 * 
+		 * @param permission
+		 *            Permission
+		 */
+		void addPermission(Permission permission) {
+			if (permissions == null)
+				permissions = new Permissions();
+			permissions.add(permission);
+		}
+	}
+
+	/**
+	 * reads and tokenizes the policy file
+	 */
+	static class PolicyTokenizer {
+		// character that terminates every line
+		private final static int EOL = '\n';
+
+		// token types
+		final static int TOK_CHAR = 0;
+
+		final static int TOK_STRING = 1;
+
+		final static int TOK_QUOTEDSTRING = 2;
+
+		// holds on to the stream
+		private InputStreamReader policyData;
+
+		private char[] inbuf = new char[1024];
+
+		private int inbufCount = 0, inbufPos = 0;
+
+		// flag to say when the EOF is reached
+		private boolean endOfFile = false;
+
+		// place where the current string token is stored
+		String sval;
+
+		// place where the current char token is stored
+		char cval;
+
+		private char[] buf = new char[120];
+
+		/**
+		 * Constructs a new instance of this class and sets the policy stream
+		 * 
+		 * @param policyData
+		 *            InputStream
+		 */
+		PolicyTokenizer(InputStreamReader policyData) {
+			this.policyData = policyData;
+		}
+
+		/**
+		 * Reads and throws away all characters until the end of the current
+		 * line
+		 */
+		private void ignoreToEOL() throws IOException {
+			while (true) {
+				if (inbufPos == inbufCount) {
+					if ((inbufCount = policyData.read(inbuf)) == -1) {
+						inbufPos = -1;
+						endOfFile = true;
+						break;
+					}
+					inbufPos = 0;
+				}
+				if (inbuf[inbufPos++] == EOL)
+					break; // & 0xff not required
+			}
+		}
+
+		/**
+		 * Reads and throws away all characters until the end of the slash star
+		 * comment
+		 */
+		private void findEndOfComment() throws IOException {
+			char lastChar = 0;
+			while (true) {
+				if (inbufPos == inbufCount) {
+					if ((inbufCount = policyData.read(inbuf)) == -1) {
+						inbufPos = -1;
+						endOfFile = true;
+						break;
+					}
+					inbufPos = 0;
+				}
+				char c = (char) inbuf[inbufPos++]; // & 0xff not required
+				if (c == '/' && lastChar == '*')
+					break;
+				lastChar = c;
+			}
+		}
+
+		/**
+		 * answers with the end of file flag's status
+		 * 
+		 * @return boolean
+		 */
+		boolean isAtEOF() {
+			return endOfFile;
+		}
+
+		/**
+		 * reads the next token in the stream and puts it in sval answers the
+		 * type of token that was read
+		 * 
+		 * @return int
+		 */
+		int nextToken() {
+			boolean insideQuotes = false;
+			int lastChar = ' ';
+
+			char c;
+			int length = 0;
+			try {
+				while (true) {
+					if (inbufPos == inbufCount) {
+						if ((inbufCount = policyData.read(inbuf)) == -1) {
+							inbufPos = -1;
+							endOfFile = true;
+							break;
+						}
+						inbufPos = 0;
+					}
+					c = inbuf[inbufPos++];
+
+					// new line or tab chars become spaces
+					if (c == '\n' || c == '\r' || c == '\t')
+						c = ' ';
+					// double backslashes are turned into single backslashes
+					if (c == '\\' && lastChar == '\\') {
+						lastChar = ' ';
+						continue;
+					}
+
+					if (insideQuotes) {
+						if (c == '"' && lastChar != '\\')
+							break;
+					} else {
+						// leading spaces are ignored. other spaces are token
+						// separators
+						if (c == ' ') {
+							if (length == 0)
+								continue;
+							break;
+						}
+						// semicolons, commas, and brackets outside quotes are
+						// also token separators
+						if (c == ';' || c == ',' || c == '{' || c == '}') {
+							// semicolons are also tokens, so push back the
+							// semi-colon if
+							// it is interpreted as a separator
+							if (length == 0) {
+								cval = c;
+								return TOK_CHAR;
+							}
+							inbufPos--;
+							break;
+						}
+						// handle quotes, but allow backslashed quotes
+						if (c == '"' && lastChar != '\\') {
+							if (length > 0) {
+								inbufPos--;
+								break;
+							}
+							insideQuotes = true;
+							continue;
+						}
+						// handle comments which are outside quotes
+						if (c == '/' && lastChar == '/') {
+							length = 0;
+							ignoreToEOL();
+							lastChar = ' ';
+							continue;
+						}
+						// handle /* */ comments
+						if (c == '*' && lastChar == '/') {
+							length--;
+							lastChar = c;
+							findEndOfComment();
+							continue;
+						}
+					}
+					if (length == buf.length) {
+						char[] newBuf = new char[buf.length * 2];
+						System.arraycopy(buf, 0, newBuf, 0, length);
+						buf = newBuf;
+					}
+					buf[length++] = c;
+					lastChar = c;
+				}
+			} catch (IOException e) {
+				endOfFile = true;
+			}
+			sval = new String(buf, 0, length);
+
+			// if inside a quoted string, then it was terminated by an end quote
+			if (insideQuotes)
+				return TOK_QUOTEDSTRING;
+			return TOK_STRING;
+		}
+
+		/**
+		 * reads and discards tokens until a matching one is found.
+		 * 
+		 * @param stopChar
+		 *            stop tossing away tokens after this one is encountered
+		 */
+		void skipTokens(char stopChar) {
+			while (!endOfFile) {
+				if (nextToken() == TOK_CHAR && cval == stopChar)
+					break;
+			}
+		}
+	}
+
+	/**
+	 * Parses policy information in the Policy File format and creates a
+	 * grantList with the entries. Does nothing if the Policy File has parse
+	 * errors
+	 * 
+	 * @param data
+	 *            InputStream Stream containing the policy data
+	 */
+	private void readPolicy(InputStream data, URL source, boolean allowExpand) {
+		policyRead = false;
+	}
+
+	/**
+	 * Answers with a new instance of the passed permissionClass or null if it
+	 * is not recognised.
+	 * 
+	 * @param permissionClass
+	 *            String The type of <CODE>Permission</CODE> it is expected to
+	 *            answer with
+	 * @param permissionName
+	 *            String The rights which may be needed for the <CODE>Permission</CODE>
+	 * @param permissionAction
+	 *            String The action to which the <CODE>Permission</CODE>
+	 *            applies
+	 * @return Permission
+	 */
+	Permission createPermission(String permissionClass, String permissionName,
+			String permissionAction) {
+
+		try {
+			Class pc = Class.forName(permissionClass);
+			Constructor pcc = pc.getConstructor(new Class[] { String.class,
+					String.class });
+
+			return (Permission) pcc.newInstance(new Object[] { permissionName,
+					permissionAction });
+		} catch (Exception e) {
+			return null;
+		}
+	}
+
+	/**
+	 * Reads the system policy
+	 */
+	private void getSystemPolicy() {
+		boolean allowExpandProperties = !"false".equalsIgnoreCase(Security
+				.getProperty("policy.expandProperties"));
+
+		// see if we're allowed to use command line specified properties,
+		// default of true
+		boolean allowPropertyPolicies = !"false".equalsIgnoreCase(Security
+				.getProperty("allowSystemProperty"));
+		// if we're allowed to use system defined properties and they specified
+		// a policy on the command line using -Djava.security.policy==someURL
+		// then it must be the only file loaded
+		if (allowPropertyPolicies) {
+			String policyFile = System.getProperty("java.security.policy");
+
+			// if the system property java.security.policy exists and
+			// the policy.allowSystemProperty is not false in the security
+			// properties file
+			if (policyFile != null) {
+				boolean exclusiveFile = policyFile.charAt(0) == '=';
+				// chop off the extra equals
+				if (exclusiveFile)
+					policyFile = policyFile.substring(1);
+				try {
+					URL policyURL;
+					try {
+						policyURL = new URL(policyFile);
+					} catch (MalformedURLException m) {
+						// Assume its a file in the current directory
+						policyURL = new URL("file:" + policyFile);
+					}
+					InputStream in = policyURL.openStream();
+					readPolicy(in, policyURL, allowExpandProperties);
+					in.close();
+				} catch (IOException e) {
+				}
+				if (exclusiveFile)
+					return;
+			}
+		}
+		// go through all the properties to read system defined policy files
+		int policyNum = 1;
+		String policyFile;
+		while ((policyFile = Security.getProperty("policy.url." + policyNum++)) != null) {
+			try {
+				URL policyURL = new URL(expandTags(policyFile, false, true)
+						.replace('\\', '/'));
+				InputStream in = policyURL.openStream();
+				readPolicy(in, policyURL, allowExpandProperties);
+				in.close();
+			} catch (IOException e) {
+			}
+		}
+
+		// if the policy can't be read then use the default one
+		if (!policyRead) {
+			// make sure the grant list is empty
+			grantList.removeAllElements();
+			// add the permissions for all code
+			GrantHolder defaultGrant = new GrantHolder();
+			Permission[] defaults = defaultSystemPermissionList();
+			for (int i = 0; i < defaults.length; ++i)
+				defaultGrant.addPermission(defaults[i]);
+			policyRead = true;
+
+			grantList.addElement(defaultGrant);
+
+			// Extensions get AllPermission
+			try {
+				String javaHome = System.getProperty("java.home");
+				CodeSource extensionCS = new CodeSource(new File(javaHome,
+						"lib/ext/*").toURL(),
+						(java.security.cert.Certificate[]) null);
+				GrantHolder extensionGrant = new GrantHolder();
+				extensionGrant.setCodeSource(extensionCS);
+				extensionGrant.addPermission(new AllPermission());
+				grantList.addElement(extensionGrant);
+			} catch (MalformedURLException e) {
+			}
+		}
+	}
+
+	/**
+	 * Causes the policy file to be re-read with the next call to getPermissions
+	 * 
+	 */
+	public void refresh() {
+		// clear the cached security policy
+		policyRead = false;
+		grantList.removeAllElements();
+	}
+
+	/**
+	 * Parses and expands property tags from the passed string. These tags occur
+	 * in the format ${propertyname} If the allowBlankProperties flag is set, it
+	 * answers with a null string should a property be not found.
+	 * 
+	 * @param text
+	 *            String String which may contain property tags
+	 * @param allowBlankProperties
+	 *            boolean Properties that don't expand are allowed?
+	 */
+	String expandTags(String text, boolean allowBlankProperties,
+			boolean allowExpand) {
+		if (!allowExpand)
+			return text;
+
+		StringBuffer textBuf = null;
+		int curPos = 0, length = text.length();
+		while (curPos < length) {
+			int nextToken = text.indexOf("${", curPos);
+			// if there are no more properties, add what remains of the string
+			if (nextToken == -1) {
+				if (curPos == 0)
+					return text;
+				textBuf.append(text.substring(curPos));
+				break;
+			}
+			// to avoid (most) StringBuffer growth make it twice as large
+			if (textBuf == null)
+				textBuf = new StringBuffer(text.length() * 2);
+			// where the closing brace is
+			int tagEnd = text.indexOf('}', nextToken);
+			// add the string up to the token start
+			textBuf.append(text.substring(curPos, nextToken));
+			if (tagEnd > nextToken) {
+				curPos = tagEnd + 1;
+				String tagVal = expandProperty(text.substring(nextToken + 2,
+						tagEnd));
+				if (tagVal != null) {
+					textBuf.append(tagVal);
+					// Don't create UNC paths. If the system property ends with
+					// a slash, remove any starting slash from the text to
+					// append.
+					// In the case where user.home is \,
+					// ${user.home}/.java.policy will expand //.java.policy
+					// which is a UNC path and very slow to resolve.
+					if (tagVal.length() > 0) {
+						char ch = tagVal.charAt(tagVal.length() - 1);
+						if ((ch == '\\' || ch == '/') && curPos < length) {
+							ch = text.charAt(curPos);
+							if (ch == '\\' || ch == '/')
+								curPos++;
+						}
+					}
+				} else if (!allowBlankProperties)
+					return null;
+			} else {
+				// if there is no closing brace
+				curPos = nextToken + 2;
+				textBuf.append("${");
+			}
+		}
+		return textBuf == null ? text : textBuf.toString();
+	}
+
+	/**
+	 * Answers a property tag with it's system property value
+	 * 
+	 * @param tag
+	 *            String The string value whose property gets answered.
+	 * @return String
+	 */
+	String expandProperty(String tag) {
+		// expand the abbreviated tag ${/} to ${file.separator}
+		if (tag.equals("/"))
+			tag = "file.separator";
+		return System.getProperty(tag);
+	}
+
+	/**
+	 * The following is a list of default permissions which are used in a case
+	 * where no system policy is available
+	 */
+	private static Permission[] defaultSystemPermissionList() {
+		return new Permission[] {
+				// Allow threads to stop themselves and exit.
+				// new RuntimePermission("stopThread"),
+				new RuntimePermission("exitVM"),
+				// Allow listening on unprivileged ports.
+				new SocketPermission("localhost:1024-", "listen"),
+				// Standard property access.
+				new PropertyPermission("java.version", "read"),
+				new PropertyPermission("java.vendor", "read"),
+				new PropertyPermission("java.vendor.url", "read"),
+				new PropertyPermission("java.class.version", "read"),
+				new PropertyPermission("os.name", "read"),
+				new PropertyPermission("os.version", "read"),
+				new PropertyPermission("os.arch", "read"),
+				new PropertyPermission("file.separator", "read"),
+				new PropertyPermission("path.separator", "read"),
+				new PropertyPermission("line.separator", "read"),
+				new PropertyPermission("java.specification.version", "read"),
+				new PropertyPermission("java.specification.vendor", "read"),
+				new PropertyPermission("java.specification.name", "read"),
+				new PropertyPermission("java.vm.specification.version", "read"),
+				new PropertyPermission("java.vm.specification.vendor", "read"),
+				new PropertyPermission("java.vm.specification.name", "read"),
+				new PropertyPermission("java.vm.version", "read"),
+				new PropertyPermission("java.vm.vendor", "read"),
+				new PropertyPermission("java.vm.name", "read"), };
+	}
+
+	private static URL toCanonicalURL(URL orgURL) {
+		if (orgURL.getProtocol().equals("jar"))
+			// get URL from JarURL
+			try {
+				// Create a URL for the resource the jar refers to
+				JarURLConnection jarCon = (JarURLConnection) orgURL
+						.openConnection();
+				String jarURL = toCanonicalURL(jarCon.getJarFileURL())
+						.toString();
+				String entryName = jarCon.getEntryName();
+				if (entryName == null)
+					entryName = "";
+				jarURL = new StringBuffer(jarURL.length() + entryName.length()
+						+ 2).append(jarURL).append("!/").append(entryName)
+						.toString();
+				return new URL("jar", null, -1, jarURL);
+			} catch (IOException ioe) {
+				// Continue using the jar URL.
+			}
+
+		if (orgURL.getProtocol().equals("file")) {
+			// canonize for comparison
+			String fileName;
+			if ((fileName = orgURL.getFile()) == null)
+				fileName = "";
+			String host = orgURL.getHost();
+			if (host != null && host.length() > 0)
+				fileName = new StringBuffer(host.length() + fileName.length()
+						+ 2).append("//").append(host).append(fileName)
+						.toString();
+			try {
+				return new File(fileName).toURL();
+			} catch (MalformedURLException ex) {
+			}
+		}
+
+		return orgURL;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/DeleteOnExit.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/DeleteOnExit.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/DeleteOnExit.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/DeleteOnExit.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,41 @@
+/* Copyright 2001, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+import java.io.File;
+import java.util.Vector;
+
+import com.ibm.oti.vm.VM;
+
+public class DeleteOnExit {
+	private static Vector deleteList = new Vector();
+
+	static {
+		VM.deleteOnExit();
+	}
+
+	public static void addFile(String toDelete) {
+		deleteList.addElement(toDelete);
+	}
+
+	public static void deleteOnExit() {
+		for (int i = 0; i < deleteList.size(); i++) {
+			String name = (String) deleteList.elementAt(i);
+			new File(name).delete();
+		}
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/ExternalMessages.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/ExternalMessages.properties?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/ExternalMessages.properties (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/ExternalMessages.properties Wed Nov 30 21:29:27 2005
@@ -0,0 +1,260 @@
+/*[INCLUDE-IF mJava14]*/
+#
+# Licensed Materials - Property of IBM,
+# (c) Copyright IBM Corp. 2000, 2005  All Rights Reserved
+#
+# External Messages for EN locale
+K0006=Negative index specified
+K0007=attempt to write after finish
+K0008=Cannot read version
+K0009=Missing version string\: {0}
+K000a=Entry is not named
+K000b=Invalid attribute {0}
+K000c=cannot resolve subclasses
+K000d=Unknown attribute
+K000e=Cannot add attributes to empty string
+K0014=Unquoted {0} in suffix\: {1}
+K0015=Unexpected {0} in fraction\: {1}
+K0016=Unexpected {0} in {1}
+K0017=Missing pattern before {0} in {1}
+K0018=Missing exponent format {0}
+K0019=Unterminated quote {0}
+K001a=Missing grouping format {0}
+K001b=Invalid exponent format {0}
+K001c=Invalid pattern char {0} in {1}
+K001d=Invalid argument number
+K001e=Missing element format
+K001f=Unknown element format
+K0020=Unknown format
+K002b=Unknown pattern character - '{0}'
+K002c=Access denied {0}
+K002e=Offset out of bounds
+K002f=Arguments out of bounds
+K0032=Address null or destination port out of range
+K0033=Unknown socket type
+K0034=Packet address mismatch with connected address
+K0035=Zero or negative buffer size
+K0036=Invalid negative timeout
+K0037=Connection already established
+K0038=No host name provided
+K0039=Attempted to join a non-multicast group
+K003a=Attempted to leave a non-multicast group
+K003c=TimeToLive out of bounds
+K003d=Socket is closed
+K003e=SOCKS connection failed\: {0}
+K003f=Unable to connect to SOCKS server\: {0}
+K0040=Invalid SOCKS client.
+K0041=Socket implementation does not support SOCKS.
+K0042=Socket implementation factory already set
+K0044=The factory has already been set
+K0045=Attempted to set a negative SoLinger
+K0046=Local port declared out of range
+K0047=buffer is null
+K0048=Invalid action specified\: {0}
+K0049=MinPort is greater than MaxPort
+K004a=Invalid port number specified
+K004b=Attempt to set factory more than once.
+K004c=Package is sealed
+K004d=Does not support writing to the input stream
+K004e=Duplicate Factory
+K004f=rounding necessary
+K0050=wrong rounding mode
+K0051=scale value < than zero
+K0052=Array index out of range\: {0}
+K0053=Package {0} already defined.
+K0055=String index out of range\: {0}
+K0056=Already destroyed
+K0057=Has threads
+K0058=size must be > 0
+K0059=Stream is closed
+K005a=Mark has been invalidated.
+K005b=BufferedReader is closed
+K005c=Invalid Mark.
+K005d=Writer is closed.
+K005e=size must be >\= 0
+K005f=Does not support writing to the output stream
+K0060=CharArrayReader is closed.
+K0062=Second byte at {0} does not match UTF8 Specification
+K0063=Third byte at {0} does not match UTF8 Specification
+K0064=Second or third byte at {0} does not match UTF8 Specification
+K0065=Input at {0} does not match UTF8 Specification
+K0068=String is too long
+K0069=File cannot compare to non File
+K006a=time must be positive
+K006b=Prefix must be at least 3 characters
+K006c=FileDescriptor is null
+K006d=actions invalid
+K006e=path is null
+K006f=invalid permission\: {0}
+K0070=InputStreamReader is closed.
+K0071=Error fetching SUID\: {0}
+K0072={0} computing SHA-1 / SUID
+K0073=OutputStreamWriter is closed.
+K0074=Not connected
+K0075=InputStream is closed
+K0076=Pipe broken
+K0077=Crc mismatch
+K0078=Pipe is closed
+K0079=Already connected
+K007a=Pipe already connected
+K007b=Pipe Not Connected
+K007e=Pushback buffer full
+K007f=Mark/Reset not supported
+K0080=Reader is closed
+K0081=Mode must be one of "r" or "rw"
+K0083=StringReader is closed.
+K0084=can only instantiate one BootstrapClassLoader
+K0086=Referenced reflect object is no longer valid
+K0087=Referenced reflect object is no longer valid\: {0}
+K0088=Incorrect end of BER tag
+K0089=Unknown type\: {0}
+K008a=Read {0} bytes trying to read {1} bytes from {2}
+K008b=Position\: {0}
+K008c=Invalid Base64 char\:{0}
+K008d=This protocol does not support input
+K008e=Does not support output
+K008f=This method does not support writing\: {0}
+K0090=can't open OutputStream after reading from an inputStream
+K0091=Cannot access request header fields after connection is set
+K0092=Cannot set method after connection is made
+K0093=Too many redirects
+K0094=Unable to change directories
+K0095=Could not establish data connection
+K0096=Unable to retrieve file\: {0}
+K0097=Unable to connect to server\: {0}
+K0098=Unable to log into server\: {0}
+K0099=Unable to configure data port
+K009a=Unable to store file
+K009b=Unable to set transfer type
+K00a2=Parsing policy file\: {0}, expected quoted {1}, found unquoted\: {2}
+K00a3=Parsing policy file\: {0}, found unexpected\: {1}
+K00a4=Content-Length underflow
+K00a5=Invalid parameter - {0}
+K00a8=Parsing policy file\: {0}, invalid codesource URL\: {1}
+K00ae=Size mismatch
+K00af=Invalid proxy port\: {0}
+K00b0=Proxy port out of range
+K00b1=Invalid port number
+K00b2=Content-Length exceeded
+K00b3=Unknown protocol\: {0}
+K00b6=No entries
+K00b7=File is closed
+K00c1=Illegal character
+K00cd=Failure to connect to SOCKS server.
+K00ce=Unable to connect to identd to verify user.
+K00cf=Failure - user ids do not match.
+K00d0=Success
+K00d1=Read null attempting to read class descriptor for an object
+K00d2=Wrong format\: 0x{0}
+K00d3=Read an exception
+K00d4={2} - {0} not compatible with {1}
+K00d5=Invalid typecode\: {0}
+K00d7=Wrong base type in\: {0}
+K00d8=Protocol not found\: {0}
+K00d9=Callback object cannot be null
+K00da=Incompatible class (SUID)\: {0} but expected {1}
+K00dc=IllegalAccessException
+K00e3=Could not create specified security manager\: {0}
+K00e4=Key usage is critical and cannot be used for digital signature purposes.
+K00e5=month\: {0}
+K00e6=day of month\: {0}
+K00e7=day of week\: {0}
+K00e8=time\: {0}
+K00e9=DST offset\: {0}
+K00ea=era\: {0}
+K00ed={0} is not an interface
+K00ee={0} is not visible from class loader
+K00ef={0} appears more than once
+K00f0=non-public interfaces must be in the same package
+K00f1=not a proxy instance
+K00f2=the methods named {0} must have the same return type
+K00f3=Timer was cancelled
+K00f5=Illegal delay to start the TimerTask
+K00f6=TimerTask is scheduled already
+K00f7=TimerTask is cancelled
+K00f8=day of week in month\: {0}
+K00f9=min or max digit count too large
+K00fa=min digits greater than max digits
+K00fb=min or max digits negative
+K00fc=Jar entry not specified
+K00fd=Invalid keystore
+K00fe=Incorrect password
+K0185=The alias already exists for a key entry.
+K018f=Can't convert to BMPString \: {0}
+K0190=No data to decode
+K0191=Invalid size, must be a multiple of 64 from 512 to 1024
+K0193=An identity with this name already exists in this scope
+K0194=An identity in the scope has the same public key
+K0195=The existing public key and the one contained in the certificate do not match.
+K0196=Certificate is missing
+K0199=Count out of range
+K01a0=End of stream condition
+K01a4=Already shutting down
+K01a5=Illegal shutdown hook\: {0}
+K01a6=Invalid filter
+K01b3=Incorrect number of arguments
+K01b4=Cannot convert {0} to {1}
+K01b6=Cannot find \!/
+K01c1=File is a Directory
+K01c2=Cannot create\: {0}
+K01c3=Unable to open\: {0}
+K01c4=Invalid zip file\: {0}
+K01c6=No Main-Class specified in manifest\: {0}
+K01d1=Signers of '{0}' do not match signers of other classes in package
+K01d2={1} - protected system package '{0}'
+K01ec=key size must be a multiple of 8 bits
+K01ed=key size must be at least 512 bits
+K01fe=Incomplete % sequence at\: {0}
+K01ff=Invalid % sequence ({0}) at\: {1}
+K0220=UTFDataFormatException
+K0222=No Manifest found in jar file\: {0}
+K0300=Unsupported encoding
+K0301=Not signed data
+K0302=Relative path
+K0303=Scheme-specific part expected
+K0304=Authority expected
+K0305=Illegal character in scheme
+K0306={0} in schemeSpecificPart
+K0307={0} in authority
+K0308={0} in path
+K0309={0} in query
+K030a={0} in fragment
+K030c=Expected host
+K030d=Illegal character in userinfo
+K030e=Expected a closing square bracket for ipv6 address
+K030f=Malformed ipv6 address
+K0310=Illegal character in host name
+K0311=Malformed ipv4 address
+K0312=URI is not absolute
+K0313=Incomplete % sequence
+K0314=Invalid % sequence ({0})
+K0315=Socket is already bound
+K0316=SocketAddress {0} not supported
+K0317=Host is unresolved\: {0}
+K0318=SocketAddress is null
+K031a=URI is not absolute\: {0}
+K031b=URI is not hierarchical\: {0}
+K031c=Expected file scheme in URI\: {0}
+K031d=Expected non-empty path in URI\: {0}
+K031e=Found {0} component in URI\: {1}
+K031f=Socket is not bound
+K0320=Socket is not connected
+K0321=Socket input is shutdown
+K0322=Not a supported ISO 4217 Currency Code\: {0}
+K0323=Not a supported ISO 3166 Country locale\: {0}
+K0324=Needs dictionary
+K0325=Port out of range\: {0}
+K0326={0} at index {1}\: {2}
+K0327={0}\: {1}
+K0328=Certificate not yet valid
+K0329=Certificate expired
+K0330=interface name is null
+K0331=address is null
+K0332=Invalid IP Address is neither 4 or 16 bytes\: {0}
+K0333=Urgent data not supported
+K0334=Cannot set network interface with null
+K0335=No addresses associated with Interface
+K0337=null type not allowed
+K0338=Address not associated with an interface - not set
+K0339=Invalid IP Address is neither 4 or 16 bytes
+K0340={0} incompatible with {1}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/FloatingPointParser.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/FloatingPointParser.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/FloatingPointParser.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/FloatingPointParser.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,289 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+/**
+ * Used to parse a string and return either a single or double precision
+ * floating point number.
+ */
+public final class FloatingPointParser {
+
+	private static final class StringExponentPair {
+		String s;
+
+		int e;
+
+		boolean negative;
+
+		StringExponentPair(String s, int e, boolean negative) {
+			this.s = s;
+			this.e = e;
+			this.negative = negative;
+		}
+	}
+
+	/**
+	 * Takes a String and an integer exponent. The String should hold a positive
+	 * integer value (or zero). The exponent will be used to calculate the
+	 * floating point number by taking the positive integer the String
+	 * represents and multiplying by 10 raised to the power of the of the
+	 * exponent. Returns the closest double value to the real number
+	 * 
+	 * @param s
+	 *            the String that will be parsed to a floating point
+	 * @param e
+	 *            an int represent the 10 to part
+	 * @return the double closest to the real number
+	 * 
+	 * @exception NumberFormatException
+	 *                if the String doesn't represent a positive integer value
+	 */
+	private static native double parseDblImpl(String s, int e);
+
+	/**
+	 * Takes a String and an integer exponent. The String should hold a positive
+	 * integer value (or zero). The exponent will be used to calculate the
+	 * floating point number by taking the positive integer the String
+	 * represents and multiplying by 10 raised to the power of the of the
+	 * exponent. Returns the closest float value to the real number
+	 * 
+	 * @param s
+	 *            the String that will be parsed to a floating point
+	 * @param e
+	 *            an int represent the 10 to part
+	 * @return the float closest to the real number
+	 * 
+	 * @exception NumberFormatException
+	 *                if the String doesn't represent a positive integer value
+	 */
+	private static native float parseFltImpl(String s, int e);
+
+	/**
+	 * Takes a String and does some initial parsing. Should return a
+	 * StringExponentPair containing a String with no leading or trailing white
+	 * space and trailing zeroes eliminated. The exponent of the
+	 * StringExponentPair will be used to calculate the floating point number by
+	 * taking the positive integer the String represents and multiplying by 10
+	 * raised to the power of the of the exponent.
+	 * 
+	 * @param s
+	 *            the String that will be parsed to a floating point
+	 * @param length
+	 *            the length of s
+	 * @return a StringExponentPair with necessary values
+	 * 
+	 * @exception NumberFormatException
+	 *                if the String doesn't pass basic tests
+	 */
+	private static StringExponentPair initialParse(String s, int length) {
+		boolean negative = false;
+		char c;
+		int start, end, decimal;
+		int e = 0;
+
+		start = 0;
+		if (length == 0)
+			throw new NumberFormatException(s);
+
+		c = s.charAt(length - 1);
+		if (c == 'D' || c == 'd' || c == 'F' || c == 'f') {
+			length--;
+			if (length == 0)
+				throw new NumberFormatException(s);
+		}
+
+		end = Math.max(s.indexOf('E'), s.indexOf('e'));
+		if (end > -1) {
+			if (end + 1 == length)
+				throw new NumberFormatException(s);
+
+			if (s.charAt(end + 1) == '+')
+				e = Integer.parseInt(s.substring(end + 2, length));
+			else
+				e = Integer.parseInt(s.substring(end + 1, length));
+		} else {
+			end = length;
+		}
+		if (length == 0)
+			throw new NumberFormatException(s);
+
+		c = s.charAt(start);
+		if (c == '-') {
+			++start;
+			--length;
+			negative = true;
+		} else if (c == '+') {
+			++start;
+			--length;
+		}
+		if (length == 0)
+			throw new NumberFormatException(s);
+
+		decimal = s.indexOf('.');
+		if (decimal > -1) {
+			e -= end - decimal - 1;
+			s = s.substring(start, decimal) + s.substring(decimal + 1, end);
+		} else {
+			s = s.substring(start, end);
+		}
+
+		if ((length = s.length()) == 0)
+			throw new NumberFormatException();
+
+		end = length;
+		while (end > 1 && s.charAt(end - 1) == '0')
+			--end;
+
+		start = 0;
+		while (start < end - 1 && s.charAt(start) == '0')
+			start++;
+
+		if (end != length || start != 0) {
+			e += length - end;
+			s = s.substring(start, end);
+		}
+
+		return new StringExponentPair(s, e, negative);
+	}
+
+	/*
+	 * Assumes the string is trimmed.
+	 */
+	private static double parseDblName(String namedDouble, int length) {
+		// Valid strings are only +Nan, NaN, -Nan, +Infinity, Infinity,
+		// -Infinity.
+		if ((length != 3) && (length != 4) && (length != 8) && (length != 9)) {
+			throw new NumberFormatException();
+		}
+
+		boolean negative = false;
+		int cmpstart = 0;
+		switch (namedDouble.charAt(0)) {
+		case '-':
+			negative = true; // fall through
+		case '+':
+			cmpstart = 1;
+		default:
+		}
+
+		if (namedDouble.regionMatches(false, cmpstart, "Infinity", 0, 8)) {
+			return negative ? Double.NEGATIVE_INFINITY
+					: Float.POSITIVE_INFINITY;
+		}
+
+		if (namedDouble.regionMatches(false, cmpstart, "NaN", 0, 3)) {
+			return Double.NaN;
+		}
+
+		throw new NumberFormatException();
+	}
+
+	/*
+	 * Assumes the string is trimmed.
+	 */
+	private static float parseFltName(String namedFloat, int length) {
+		// Valid strings are only +Nan, NaN, -Nan, +Infinity, Infinity,
+		// -Infinity.
+		if ((length != 3) && (length != 4) && (length != 8) && (length != 9)) {
+			throw new NumberFormatException();
+		}
+
+		boolean negative = false;
+		int cmpstart = 0;
+		switch (namedFloat.charAt(0)) {
+		case '-':
+			negative = true; // fall through
+		case '+':
+			cmpstart = 1;
+		default:
+		}
+
+		if (namedFloat.regionMatches(false, cmpstart, "Infinity", 0, 8)) {
+			return negative ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
+		}
+
+		if (namedFloat.regionMatches(false, cmpstart, "NaN", 0, 3)) {
+			return Float.NaN;
+		}
+
+		throw new NumberFormatException();
+	}
+
+	/**
+	 * Returns the closest double value to the real number in the string.
+	 * 
+	 * @param s
+	 *            the String that will be parsed to a floating point
+	 * @return the double closest to the real number
+	 * 
+	 * @exception NumberFormatException
+	 *                if the String doesn't represent a double
+	 */
+	public static double parseDouble(String s) {
+		s = s.trim();
+		int length = s.length();
+
+		if (length == 0) {
+			throw new NumberFormatException(s);
+		}
+
+		// See if this could be a named double
+		char last = s.charAt(length - 1);
+		if ((last == 'y') || (last == 'N')) {
+			return parseDblName(s, length);
+		}
+		StringExponentPair info = initialParse(s, length);
+
+		double result = parseDblImpl(info.s, info.e);
+		if (info.negative)
+			result = -result;
+
+		return result;
+	}
+
+	/**
+	 * Returns the closest float value to the real number in the string.
+	 * 
+	 * @param s
+	 *            the String that will be parsed to a floating point
+	 * @return the float closest to the real number
+	 * 
+	 * @exception NumberFormatException
+	 *                if the String doesn't represent a float
+	 */
+	public static float parseFloat(String s) {
+		s = s.trim();
+		int length = s.length();
+
+		if (length == 0) {
+			throw new NumberFormatException(s);
+		}
+
+		// See if this could be a named float
+		char last = s.charAt(length - 1);
+		if ((last == 'y') || (last == 'N')) {
+			return parseFltName(s, length);
+		}
+		StringExponentPair info = initialParse(s, length);
+
+		float result = parseFltImpl(info.s, info.e);
+		if (info.negative)
+			result = -result;
+
+		return result;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/Inet6Util.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/Inet6Util.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/Inet6Util.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/Inet6Util.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,492 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+/**
+ * Utility functions for IPV6 operations.
+ */
+public class Inet6Util {
+
+	/**
+	 * Creates an byte[] based on an ipAddressString. No error handling is
+	 * performed here.
+	 */
+	public static byte[] createByteArrayFromIPAddressString(
+			String ipAddressString) {
+
+		if (isValidIPV4Address(ipAddressString)) {
+			StringTokenizer tokenizer = new StringTokenizer(ipAddressString,
+					".");
+			String token = "";
+			int tempInt = 0;
+			byte[] byteAddress = new byte[4];
+			for (int i = 0; i < 4; i++) {
+				token = tokenizer.nextToken();
+				tempInt = Integer.parseInt(token);
+				byteAddress[i] = (byte) tempInt;
+			}
+
+			return byteAddress;
+		}
+		
+		if (ipAddressString.charAt(0) == '[') {
+			ipAddressString = ipAddressString.substring(1, ipAddressString
+					.length() - 1);
+		}
+
+		StringTokenizer tokenizer = new StringTokenizer(ipAddressString,
+				":.", true);
+		ArrayList hexStrings = new ArrayList();
+		ArrayList decStrings = new ArrayList();
+		String token = "";
+		String prevToken = "";
+		int doubleColonIndex = -1; // If a double colon exists, we need to
+									// insert 0s.
+
+		// Go through the tokens, including the seperators ':' and '.'
+		// When we hit a : or . the previous token will be added to either
+		// the hex list or decimal list. In the case where we hit a ::
+		// we will save the index of the hexStrings so we can add zeros
+		// in to fill out the string
+		while (tokenizer.hasMoreTokens()) {
+			prevToken = token;
+			token = tokenizer.nextToken();
+
+			if (token.equals(":")) {
+				if (prevToken.equals(":")) {
+					doubleColonIndex = hexStrings.size();
+				} else if (!prevToken.equals("")) {
+					hexStrings.add(prevToken);
+				}
+			} else if (token.equals(".")) {
+				decStrings.add(prevToken);
+			}
+		}
+
+		if (prevToken.equals(":")) {
+			if (token.equals(":")) {
+				doubleColonIndex = hexStrings.size();
+			} else {
+				hexStrings.add(token);
+			}
+		} else if (prevToken.equals(".")) {
+			decStrings.add(token);
+		}
+
+		// figure out how many hexStrings we should have
+		// also check if it is a IPv4 address
+		int hexStringsLength = 8;
+
+		// If we have an IPv4 address tagged on at the end, subtract
+		// 4 bytes, or 2 hex words from the total
+		if (decStrings.size() > 0) {
+			hexStringsLength -= 2;
+		}
+
+		// if we hit a double Colon add the appropriate hex strings
+		if (doubleColonIndex != -1) {
+			int numberToInsert = hexStringsLength - hexStrings.size();
+			for (int i = 0; i < numberToInsert; i++) {
+				hexStrings.add(doubleColonIndex, "0");
+			}
+		}
+
+		byte ipByteArray[] = new byte[16];
+
+		// Finally convert these strings to bytes...
+		for (int i = 0; i < hexStrings.size(); i++) {
+			convertToBytes((String) hexStrings.get(i), ipByteArray, i * 2);
+		}
+
+		// Now if there are any decimal values, we know where they go...
+		for (int i = 0; i < decStrings.size(); i++) {
+			ipByteArray[i + 12] = (byte) (Integer
+					.parseInt((String) decStrings.get(i)) & 255);
+		}
+
+		// now check to see if this guy is actually and IPv4 address
+		// an ipV4 address is ::FFFF:d.d.d.d
+		boolean ipV4 = true;
+		for (int i = 0; i < 10; i++) {
+			if (ipByteArray[i] != 0) {
+				ipV4 = false;
+				break;
+			}
+		}
+
+		if (ipByteArray[10] != -1 || ipByteArray[11] != -1) {
+			ipV4 = false;
+		}
+
+		if (ipV4) {
+			byte ipv4ByteArray[] = new byte[4];
+			for (int i = 0; i < 4; i++) {
+				ipv4ByteArray[i] = ipByteArray[i + 12];
+			}
+			return ipv4ByteArray;
+		}
+		
+		return ipByteArray;
+
+	}
+
+	static String createIPAddrStringFromByteArray(byte ipByteArray[]) {
+
+		if (ipByteArray.length == 4) {
+			return addressToString(bytesToInt(ipByteArray, 0));
+		}
+
+		if (ipByteArray.length == 16) {
+			if (isIPv4MappedAddress(ipByteArray)) {
+				byte ipv4ByteArray[] = new byte[4];
+				for (int i = 0; i < 4; i++) {
+					ipv4ByteArray[i] = ipByteArray[i + 12];
+				}
+				return addressToString(bytesToInt(ipv4ByteArray, 0));
+			}
+
+			StringBuffer buffer = new StringBuffer();
+			for (int i = 0; i < ipByteArray.length; i++) {
+				int j = (ipByteArray[i] & 0xf0) >>> 4;
+				buffer.append(hexCharacters[j]);
+				j = ipByteArray[i] & 0x0f;
+				buffer.append(hexCharacters[j]);
+				if (i % 2 != 0) {
+					buffer.append(":");
+				}
+			}
+			return buffer.toString().substring(0, buffer.length() - 1)
+					.toUpperCase();
+		}
+		return null;
+	}
+
+	static char[] hexCharacters = { '0', '1', '2', '3', '4', '5', '6', '7',
+			'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
+	/** Converts a 4 character hex word into a 2 byte word equivalent */
+	public static void convertToBytes(String hexWord, byte ipByteArray[],
+			int byteIndex) {
+
+		int hexWordLength = hexWord.length();
+		int hexWordIndex = 0;
+		ipByteArray[byteIndex] = 0;
+		ipByteArray[byteIndex + 1] = 0;
+		int charValue;
+
+		// high order 4 bits of first byte
+		if (hexWordLength > 3) {
+			charValue = getIntValue(hexWord.charAt(hexWordIndex++));
+			ipByteArray[byteIndex] = (byte) (ipByteArray[byteIndex] | (charValue << 4));
+		}
+
+		// low order 4 bits of the first byte
+		if (hexWordLength > 2) {
+			charValue = getIntValue(hexWord.charAt(hexWordIndex++));
+			ipByteArray[byteIndex] = (byte) (ipByteArray[byteIndex] | charValue);
+		}
+
+		// high order 4 bits of second byte
+		if (hexWordLength > 1) {
+			charValue = getIntValue(hexWord.charAt(hexWordIndex++));
+			ipByteArray[byteIndex + 1] = (byte) (ipByteArray[byteIndex + 1] | (charValue << 4));
+		}
+
+		// low order 4 bits of the first byte
+		charValue = getIntValue(hexWord.charAt(hexWordIndex));
+		ipByteArray[byteIndex + 1] = (byte) (ipByteArray[byteIndex + 1] | charValue & 15);
+	}
+
+	static int getIntValue(char c) {
+
+		switch (c) {
+		case '0':
+			return 0;
+		case '1':
+			return 1;
+		case '2':
+			return 2;
+		case '3':
+			return 3;
+		case '4':
+			return 4;
+		case '5':
+			return 5;
+		case '6':
+			return 6;
+		case '7':
+			return 7;
+		case '8':
+			return 8;
+		case '9':
+			return 9;
+		}
+
+		c = Character.toLowerCase(c);
+		switch (c) {
+		case 'a':
+			return 10;
+		case 'b':
+			return 11;
+		case 'c':
+			return 12;
+		case 'd':
+			return 13;
+		case 'e':
+			return 14;
+		case 'f':
+			return 15;
+		}
+		return 0;
+	}
+
+	private static boolean isIPv4MappedAddress(byte ipAddress[]) {
+
+		// Check if the address matches ::FFFF:d.d.d.d
+		// The first 10 bytes are 0. The next to are -1 (FF).
+		// The last 4 bytes are varied.
+		for (int i = 0; i < 10; i++) {
+			if (ipAddress[i] != 0) {
+				return false;
+			}
+		}
+
+		if (ipAddress[10] != -1 || ipAddress[11] != -1) {
+			return false;
+		}
+
+		return true;
+
+	}
+
+	/**
+	 * Takes the byte array and creates an integer out of four bytes starting at
+	 * start as the high-order byte. This method makes no checks on the validity
+	 * of the parameters.
+	 */
+	public static int bytesToInt(byte bytes[], int start) {
+		// First mask the byte with 255, as when a negative
+		// signed byte converts to an integer, it has bits
+		// on in the first 3 bytes, we are only concerned
+		// about the right-most 8 bits.
+		// Then shift the rightmost byte to align with its
+		// position in the integer.
+		int value = ((bytes[start + 3] & 255))
+				| ((bytes[start + 2] & 255) << 8)
+				| ((bytes[start + 1] & 255) << 16)
+				| ((bytes[start] & 255) << 24);
+		return value;
+	}
+
+	public static String addressToString(int value) {
+		return ((value >> 24) & 0xff) + "." + ((value >> 16) & 0xff) + "."
+				+ ((value >> 8) & 0xff) + "." + (value & 0xff);
+	}
+
+	public static boolean isValidIP6Address(String ipAddress) {
+		int length = ipAddress.length();
+		boolean doubleColon = false;
+		int numberOfColons = 0;
+		int numberOfPeriods = 0;
+		int numberOfPercent = 0;
+		String word = "";
+		char c = 0;
+		char prevChar = 0;
+		int offset = 0; // offset for [] ip addresses
+
+		if (length < 2)
+			return false;
+
+		for (int i = 0; i < length; i++) {
+			prevChar = c;
+			c = ipAddress.charAt(i);
+			switch (c) {
+
+			// case for an open bracket [x:x:x:...x]
+			case '[':
+				if (i != 0)
+					return false; // must be first character
+				if (ipAddress.charAt(length - 1) != ']')
+					return false; // must have a close ]
+				offset = 1;
+				if (length < 4)
+					return false;
+				break;
+
+			// case for a closed bracket at end of IP [x:x:x:...x]
+			case ']':
+				if (i != length - 1)
+					return false; // must be last charcter
+				if (ipAddress.charAt(0) != '[')
+					return false; // must have a open [
+				break;
+
+			// case for the last 32-bits represented as IPv4 x:x:x:x:x:x:d.d.d.d
+			case '.':
+				numberOfPeriods++;
+				if (numberOfPeriods > 3)
+					return false;
+				if (!isValidIP4Word(word))
+					return false;
+				if (numberOfColons != 6 && !doubleColon)
+					return false;
+				// a special case ::1:2:3:4:5:d.d.d.d allows 7 colons with an
+				// IPv4 ending, otherwise 7 :'s is bad
+				if (numberOfColons == 7 && ipAddress.charAt(0 + offset) != ':'
+						&& ipAddress.charAt(1 + offset) != ':')
+					return false;
+				word = "";
+				break;
+
+			case ':':
+				numberOfColons++;
+				if (numberOfColons > 7)
+					return false;
+				if (numberOfPeriods > 0)
+					return false;
+				if (prevChar == ':') {
+					if (doubleColon)
+						return false;
+					doubleColon = true;
+				}
+				word = "";
+				break;
+			case '%':
+				if (numberOfColons == 0)
+					return false;
+				numberOfPercent++;
+
+				// validate that the stuff after the % is valid
+				if ((i + 1) >= length) {
+					// in this case the percent is there but no number is
+					// available
+					return false;
+				}
+				try {
+					Integer.parseInt(ipAddress.substring(i + 1));
+				} catch (NumberFormatException e) {
+					// right now we just support an integer after the % so if
+					// this is not
+					// what is there then return
+					return false;
+				}
+				break;
+
+			default:
+				if (numberOfPercent == 0) {
+					if (word.length() > 3)
+						return false;
+					if (!isValidHexChar(c))
+						return false;
+				}
+				word += c;
+			}
+		}
+
+		// Check if we have an IPv4 ending
+		if (numberOfPeriods > 0) {
+			if (numberOfPeriods != 3 || !isValidIP4Word(word))
+				return false;
+		} else {
+			// If we're at then end and we haven't had 7 colons then there is a
+			// problem
+			// unless we encountered a doubleColon
+			if (numberOfColons != 7 && !doubleColon) {
+				return false;
+			}
+
+			// If we have an empty word at the end, it means we ended in either
+			// a : or a .
+			// If we did not end in :: then this is invalid
+			if (numberOfPercent == 0) {
+				if (word == "" && ipAddress.charAt(length - 1 - offset) != ':'
+						&& ipAddress.charAt(length - 2 - offset) != ':') {
+					return false;
+				}
+			}
+		}
+
+		return true;
+	}
+
+	public static boolean isValidIP4Word(String word) {
+		char c;
+		if (word.length() < 1 || word.length() > 3)
+			return false;
+		for (int i = 0; i < word.length(); i++) {
+			c = word.charAt(i);
+			if (!(c >= '0' && c <= '9'))
+				return false;
+		}
+		if (Integer.parseInt(word) > 255)
+			return false;
+		return true;
+	}
+
+	static boolean isValidHexChar(char c) {
+
+		return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')
+				|| (c >= 'a' && c <= 'f');
+	}
+
+	/**
+	 * Takes a string and parses it to see if it is a valid IPV4 address.
+	 * 
+	 * @return true, if the string represents an IPV4 address in dotted
+	 *         notation, false otherwise
+	 */
+	public static boolean isValidIPV4Address(String value) {
+
+		int periods = 0;
+		int i = 0;
+		int length = value.length();
+
+		if (length > 15)
+			return false;
+		char c = 0;
+		String word = "";
+		for (i = 0; i < length; i++) {
+			c = value.charAt(i);
+			if (c == '.') {
+				periods++;
+				if (periods > 3)
+					return false;
+				if (word == "")
+					return false;
+				if (Integer.parseInt(word) > 255)
+					return false;
+				word = "";
+			} else if (!(Character.isDigit(c)))
+				return false;
+			else {
+				if (word.length() > 2)
+					return false;
+				word += c;
+			}
+		}
+
+		if (word == "" || Integer.parseInt(word) > 255)
+			return false;
+		if (periods != 3)
+			return false;
+		return true;
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/InvalidJarIndexException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/InvalidJarIndexException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/InvalidJarIndexException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/InvalidJarIndexException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+/**
+ * InvalidJarIndexException is thrown when entries in META-INF/INDEX.LIST are
+ * inaccurate.
+ */
+public class InvalidJarIndexException extends RuntimeException {
+
+	/**
+	 * Constructs a new instance of this class.
+	 */
+	public InvalidJarIndexException() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its message filled in.
+	 * 
+	 * @param message
+	 *            String The message for the exception.
+	 */
+	public InvalidJarIndexException(String message) {
+		super(message);
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/JarUtils.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/JarUtils.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/JarUtils.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/JarUtils.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,117 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.GeneralSecurityException;
+import java.security.cert.Certificate;
+
+/**
+ * Helper class containing a number of static convenience methods for use in the
+ * processing of JAR files.
+ */
+public class JarUtils {
+
+	/**
+	 * Ensure that this utility class cannot be instantiated.
+	 */
+	private JarUtils() {
+		// NO OP
+	}
+
+	// ----------- Verification of a signed jar's signature file follows ------
+
+	/**
+	 * Convenience method to used to check that a jar's signature file and its
+	 * corresponding signature block file (both supplied as {@link InputStream}
+	 * objects) are valid and that neither has been tampered with in respect to
+	 * the other.
+	 * <p>
+	 * In particular, this method will verify that:
+	 * <ul>
+	 * <li>the signature block file contains a signature that could only have
+	 * been created with the private key corresponding to the public key whose
+	 * certificate chain is also included in the signature block file.
+	 * <li>the message digest of the signature file is precisely equivalent to
+	 * the message digest value taken from the decrypted signature block file.
+	 * Confirming this demonstrates that there has been no tampering on the
+	 * contents of the signature file since the signing took place.
+	 * 
+	 * @param signature
+	 *            the contents of a signed jar's signature file (.SF file) as an
+	 *            <code>InputStream</code>. This stream will be closed by the
+	 *            method immediately upon its contents being read.
+	 * @param signatureBlock
+	 *            the contents of a signed jar's binary signature block file as
+	 *            an <code>InputStream</code>. This stream will be closed by
+	 *            the method immediately upon its contents being read.
+	 * @return the certificate chains discovered in the supplied signature block
+	 *         file stream in an array of {@link Certificate}.
+	 * @throws IOException
+	 *             if there was an error encountered while reading from either
+	 *             of the supplied input streams.
+	 * @throws GeneralSecurityException
+	 *             if the signature verification process fails.
+	 */
+	public static Certificate[] verifySignature(InputStream signature,
+			InputStream signatureBlock) throws IOException,
+			GeneralSecurityException {
+		// STUB IMPLEMENTATION
+		return null;
+	}
+
+	// ----------- Creating a signed jar file follows --------------
+
+	/**
+	 * Creates the PKCS #7 version of a signed jar's digital signature which may
+	 * be directly used as the contents of the signature block file associated
+	 * with the signing. Receives the signed version of the digest (created
+	 * using the signing alias' private key) and constructs the PKCS #7 version
+	 * of the digital signature as a <code>byte</code> array.
+	 * 
+	 * @param encryptedDigest
+	 *            the signed version of the message digest value supplied in
+	 *            <code>digest</code>. This value will have been previously
+	 *            obtained by signing <code>digest</code> with the signer's
+	 *            private key using the signature algorithm specified in
+	 *            <code>signatureAlgorithm</code>.
+	 * @param signerCertificateChain
+	 *            the certificate chain associated with the alias signing the
+	 *            jar. This value will have been previously obtained as the
+	 *            result of a call to
+	 *            {@link java.security.KeyStore#getCertificateChain(String)}
+	 *            with the signer's alias.
+	 * @param digestAlgorithm
+	 *            the name of the message digest algorithm used to calculate the
+	 *            value supplied in parameter <code>digest</code>.
+	 * @param signatureAlgorithm
+	 *            the name of the signature algorithm used to calculate the
+	 *            value supplied in parameter <code>encryptedDigest</code>.
+	 * @return signature data in the PKCS #7 format which may be used as the
+	 *         complete contents of the signature block file (e.g. the
+	 *         <code>.DSA</code> or <code>.RSA</code> file) created for a
+	 *         given jar signing.
+	 * @throws IOException
+	 */
+	public static byte[] getSignatureBlockBytes(byte[] encryptedDigest,
+			Certificate[] signerCertificateChain, String digestAlgorithm,
+			String signatureAlgorithm) throws IOException {
+		// STUB IMPLEMENTATION
+		return new byte[0];
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/Msg.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/Msg.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/Msg.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/Msg.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,146 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import com.ibm.oti.vm.MsgHelp;
+
+/**
+ * This class retrieves strings from a resource bundle and returns them,
+ * formatting them with MessageFormat when required.
+ * <p>
+ * It is used by the system classes to provide national language support, by
+ * looking up messages in the <code>
+ *    com.ibm.oti.util.ExternalMessages
+ * </code>
+ * resource bundle. Note that if this file is not available, or an invalid key
+ * is looked up, or resource bundle support is not available, the key itself
+ * will be returned as the associated message. This means that the <em>KEY</em>
+ * should a reasonable human-readable (english) string.
+ * 
+ */
+public class Msg {
+
+	// ResourceBundle holding the system messages.
+	static private ResourceBundle bundle = null;
+
+	static {
+		// Attempt to load the messages.
+		try {
+			bundle = MsgHelp.setLocale(Locale.getDefault(),
+					"com.ibm.oti.util.ExternalMessages");
+		} catch (Throwable e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * Retrieves a message which has no arguments.
+	 * 
+	 * @param msg
+	 *            String the key to look up.
+	 * @return String the message for that key in the system message bundle.
+	 */
+	static public String getString(String msg) {
+		if (bundle == null)
+			return msg;
+		try {
+			return bundle.getString(msg);
+		} catch (MissingResourceException e) {
+			return msg;
+		}
+	}
+
+	/**
+	 * Retrieves a message which takes 1 argument.
+	 * 
+	 * @param msg
+	 *            String the key to look up.
+	 * @param arg
+	 *            Object the object to insert in the formatted output.
+	 * @return String the message for that key in the system message bundle.
+	 */
+	static public String getString(String msg, Object arg) {
+		return getString(msg, new Object[] { arg });
+	}
+
+	/**
+	 * Retrieves a message which takes 1 integer argument.
+	 * 
+	 * @param msg
+	 *            String the key to look up.
+	 * @param arg
+	 *            int the integer to insert in the formatted output.
+	 * @return String the message for that key in the system message bundle.
+	 */
+	static public String getString(String msg, int arg) {
+		return getString(msg, new Object[] { Integer.toString(arg) });
+	}
+
+	/**
+	 * Retrieves a message which takes 1 character argument.
+	 * 
+	 * @param msg
+	 *            String the key to look up.
+	 * @param arg
+	 *            char the character to insert in the formatted output.
+	 * @return String the message for that key in the system message bundle.
+	 */
+	static public String getString(String msg, char arg) {
+		return getString(msg, new Object[] { String.valueOf(arg) });
+	}
+
+	/**
+	 * Retrieves a message which takes 2 arguments.
+	 * 
+	 * @param msg
+	 *            String the key to look up.
+	 * @param arg1
+	 *            Object an object to insert in the formatted output.
+	 * @param arg2
+	 *            Object another object to insert in the formatted output.
+	 * @return String the message for that key in the system message bundle.
+	 */
+	static public String getString(String msg, Object arg1, Object arg2) {
+		return getString(msg, new Object[] { arg1, arg2 });
+	}
+
+	/**
+	 * Retrieves a message which takes several arguments.
+	 * 
+	 * @param msg
+	 *            String the key to look up.
+	 * @param args
+	 *            Object[] the objects to insert in the formatted output.
+	 * @return String the message for that key in the system message bundle.
+	 */
+	static public String getString(String msg, Object[] args) {
+		String format = msg;
+
+		if (bundle != null) {
+			try {
+				format = bundle.getString(msg);
+			} catch (MissingResourceException e) {
+			}
+		}
+
+		return MsgHelp.format(format, args);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/NumberConverter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/NumberConverter.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/NumberConverter.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/com/ibm/oti/util/NumberConverter.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,296 @@
+/* Copyright 1998, 2003 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.oti.util;
+
+
+public final class NumberConverter {
+
+	private int setCount; // number of times u and k have been gotten
+
+	private int getCount; // number of times u and k have been set
+
+	private int[] uArray = new int[64];
+
+	private int firstK;
+
+	private final static double invLogOfTenBaseTwo = Math.log(2.0)
+			/ Math.log(10.0);
+
+	private final static long[] TEN_TO_THE = new long[20];
+
+	static {
+		TEN_TO_THE[0] = 1L;
+		for (int i = 1; i < TEN_TO_THE.length; ++i) {
+			long previous = TEN_TO_THE[i - 1];
+			TEN_TO_THE[i] = (previous << 1) + (previous << 3);
+		}
+	}
+
+	private static NumberConverter getConverter() {
+		return new NumberConverter();
+	}
+
+	public static String convert(double input) {
+		return getConverter().convertD(input);
+	}
+
+	public static String convert(float input) {
+		return getConverter().convertF(input);
+	}
+
+	public String convertD(double inputNumber) {
+		int p = 1023 + 52; // the power offset (precision)
+		long signMask = 0x8000000000000000L; // the mask to get the sign of
+		// the number
+		long eMask = 0x7FF0000000000000L; // the mask to get the power bits
+		long fMask = 0x000FFFFFFFFFFFFFL; // the mask to get the significand
+		// bits
+
+		long inputNumberBits = Double.doubleToLongBits(inputNumber);
+		// the value of the sign... 0 is positive, ~0 is negative
+		String signString = (inputNumberBits & signMask) == 0 ? "" : "-";
+		// the value of the 'power bits' of the inputNumber
+		int e = (int) ((inputNumberBits & eMask) >> 52);
+		// the value of the 'significand bits' of the inputNumber
+		long f = inputNumberBits & fMask;
+		boolean mantissaIsZero = f == 0;
+		int pow = 0, numBits = 52;
+
+		if (e == 2047)
+			return mantissaIsZero ? signString + "Infinity" : "NaN";
+		if (e == 0) {
+			if (mantissaIsZero)
+				return signString + "0.0";
+			if (f == 1)
+				// special case to increase precision even though 2 *
+				// Double.MIN_VALUE is 1.0e-323
+				return signString + "4.9E-324";
+			pow = 1 - p; // a denormalized number
+			long ff = f;
+			while ((ff & 0x0010000000000000L) == 0) {
+				ff = ff << 1;
+				numBits--;
+			}
+		} else {
+			// 0 < e < 2047
+			// a "normalized" number
+			f = f | 0x0010000000000000L;
+			pow = e - p;
+		}
+
+		if (-59 < pow && pow < 6 || (pow == -59 && !mantissaIsZero))
+			longDigitGenerator(f, pow, e == 0, mantissaIsZero, numBits);
+		else
+			bigIntDigitGeneratorInstImpl(f, pow, e == 0, mantissaIsZero,
+					numBits);
+
+		if (inputNumber >= 1e7D || inputNumber <= -1e7D
+				|| (inputNumber > -1e-3D && inputNumber < 1e-3D))
+			return signString + freeFormatExponential();
+		
+		return signString + freeFormat();
+	}
+
+	public String convertF(float inputNumber) {
+		int p = 127 + 23; // the power offset (precision)
+		int signMask = 0x80000000; // the mask to get the sign of the number
+		int eMask = 0x7F800000; // the mask to get the power bits
+		int fMask = 0x007FFFFF; // the mask to get the significand bits
+
+		int inputNumberBits = Float.floatToIntBits(inputNumber);
+		// the value of the sign... 0 is positive, ~0 is negative
+		String signString = (inputNumberBits & signMask) == 0 ? "" : "-";
+		// the value of the 'power bits' of the inputNumber
+		int e = (inputNumberBits & eMask) >> 23;
+		// the value of the 'significand bits' of the inputNumber
+		int f = inputNumberBits & fMask;
+		boolean mantissaIsZero = f == 0;
+		int pow = 0, numBits = 23;
+
+		if (e == 255)
+			return mantissaIsZero ? signString + "Infinity" : "NaN";
+		if (e == 0) {
+			if (mantissaIsZero)
+				return signString + "0.0";
+			pow = 1 - p; // a denormalized number
+			if (f < 8) { // want more precision with smallest values
+				f = f << 2;
+				pow -= 2;
+			}
+			int ff = f;
+			while ((ff & 0x00800000) == 0) {
+				ff = ff << 1;
+				numBits--;
+			}
+		} else {
+			// 0 < e < 255
+			// a "normalized" number
+			f = f | 0x00800000;
+			pow = e - p;
+		}
+
+		if (-59 < pow && pow < 35 || (pow == -59 && !mantissaIsZero))
+			longDigitGenerator(f, pow, e == 0, mantissaIsZero, numBits);
+		else
+			bigIntDigitGeneratorInstImpl(f, pow, e == 0, mantissaIsZero,
+					numBits);
+		if (inputNumber >= 1e7f || inputNumber <= -1e7f
+				|| (inputNumber > -1e-3f && inputNumber < 1e-3f))
+			return signString + freeFormatExponential();
+		
+		return signString + freeFormat();
+	}
+
+	private String freeFormatExponential() {
+		// corresponds to process "Free-Format Exponential"
+		char[] formattedDecimal = new char[25];
+		formattedDecimal[0] = (char) ('0' + uArray[getCount++]);
+		formattedDecimal[1] = '.';
+		// the position the next character is to be inserted into
+		// formattedDecimal
+		int charPos = 2;
+
+		int k = firstK;
+		int expt = k;
+		while (true) {
+			k--;
+			if (getCount >= setCount)
+				break;
+
+			formattedDecimal[charPos++] = (char) ('0' + uArray[getCount++]);
+		}
+
+		if (k == expt - 1)
+			formattedDecimal[charPos++] = '0';
+		formattedDecimal[charPos++] = 'E';
+		return new String(formattedDecimal, 0, charPos)
+				+ Integer.toString(expt);
+	}
+
+	private String freeFormat() {
+		// corresponds to process "Free-Format"
+		char[] formattedDecimal = new char[25];
+		// the position the next character is to be inserted into
+		// formattedDecimal
+		int charPos = 0;
+		int k = firstK;
+		if (k < 0) {
+			formattedDecimal[0] = '0';
+			formattedDecimal[1] = '.';
+			charPos += 2;
+			for (int i = k + 1; i < 0; i++)
+				formattedDecimal[charPos++] = '0';
+		}
+
+		int U = uArray[getCount++];
+		do {
+			if (U != -1)
+				formattedDecimal[charPos++] = (char) ('0' + U);
+			else if (k >= -1)
+				formattedDecimal[charPos++] = '0';
+
+			if (k == 0)
+				formattedDecimal[charPos++] = '.';
+
+			k--;
+			U = getCount < setCount ? uArray[getCount++] : -1;
+		} while (U != -1 || k >= -1);
+		return new String(formattedDecimal, 0, charPos);
+	}
+
+	private native void bigIntDigitGeneratorInstImpl(long f, int e,
+			boolean isDenormalized, boolean mantissaIsZero, int p);
+
+	private void longDigitGenerator(long f, int e, boolean isDenormalized,
+			boolean mantissaIsZero, int p) {
+		long R, S, M;
+		if (e >= 0) {
+			M = 1l << e;
+			if (!mantissaIsZero) {
+				R = f << (e + 1);
+				S = 2;
+			} else {
+				R = f << (e + 2);
+				S = 4;
+			}
+		} else {
+			M = 1;
+			if (isDenormalized || !mantissaIsZero) {
+				R = f << 1;
+				S = 1l << (1 - e);
+			} else {
+				R = f << 2;
+				S = 1l << (2 - e);
+			}
+		}
+
+		int k = (int) Math.ceil((e + p - 1) * invLogOfTenBaseTwo - 1e-10);
+
+		if (k > 0) {
+			S = S * TEN_TO_THE[k];
+		} else if (k < 0) {
+			long scale = TEN_TO_THE[-k];
+			R = R * scale;
+			M = M == 1 ? scale : M * scale;
+		}
+
+		if (R + M > S) { // was M_plus
+			firstK = k;
+		} else {
+			firstK = k - 1;
+			R = R * 10;
+			M = M * 10;
+		}
+
+		getCount = setCount = 0; // reset indices
+		boolean low, high;
+		int U;
+		long[] Si = new long[] { S, S << 1, S << 2, S << 3 };
+		while (true) {
+			// set U to be floor (R / S) and R to be the remainder
+			// using a kind of "binary search" to find the answer.
+			// It's a lot quicker than actually dividing since we know
+			// the answer will be between 0 and 10
+			U = 0;
+			long remainder;
+			for (int i = 3; i >= 0; i--) {
+				remainder = R - Si[i];
+				if (remainder >= 0) {
+					R = remainder;
+					U += 1 << i;
+				}
+			}
+
+			low = R < M; // was M_minus
+			high = R + M > S; // was M_plus
+
+			if (low || high)
+				break;
+
+			R = R * 10;
+			M = M * 10;
+			uArray[setCount++] = U;
+		}
+		if (low && !high)
+			uArray[setCount++] = U;
+		else if (high && !low)
+			uArray[setCount++] = U + 1;
+		else if ((R << 1) < S)
+			uArray[setCount++] = U;
+		else
+			uArray[setCount++] = U + 1;
+	}
+}



Mime
View raw message