Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 12849 invoked from network); 26 Apr 2009 12:31:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Apr 2009 12:31:12 -0000 Received: (qmail 45051 invoked by uid 500); 26 Apr 2009 12:31:12 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 45014 invoked by uid 500); 26 Apr 2009 12:31:12 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 45005 invoked by uid 99); 26 Apr 2009 12:31:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Apr 2009 12:31:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Apr 2009 12:31:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2A52F2388D0A; Sun, 26 Apr 2009 12:30:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r768698 [14/18] - in /harmony/enhanced/classlib/branches/java6: ./ modules/annotation/src/main/java/java/lang/annotation/ modules/archive/src/main/java/java/util/jar/ modules/archive/src/main/java/java/util/zip/ modules/auth/src/main/java/c... Date: Sun, 26 Apr 2009 12:30:06 -0000 To: commits@harmony.apache.org From: qiuxx@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090426123014.2A52F2388D0A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Properties.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Properties.java?rev=768698&r1=768697&r2=768698&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Properties.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Properties.java Sun Apr 26 12:30:01 2009 @@ -58,13 +58,13 @@ * @see Hashtable * @see java.lang.System#getProperties */ -public class Properties extends Hashtable { - - private static final long serialVersionUID = 4112578634029874840L; +public class Properties extends Hashtable { + + private static final long serialVersionUID = 4112578634029874840L; private transient DocumentBuilder builder = null; - private static final String PROP_DTD_NAME = "http://java.sun.com/dtd/properties.dtd"; //$NON-NLS-1$ + private static final String PROP_DTD_NAME = "http://java.sun.com/dtd/properties.dtd"; private static final String PROP_DTD = "" + " " @@ -72,210 +72,210 @@ + " " + " " + " "; + + /** + * The default values for this Properties. + */ + protected Properties defaults; + + private static final int NONE = 0, SLASH = 1, UNICODE = 2, CONTINUE = 3, + KEY_DONE = 4, IGNORE = 5; + + /** + * Constructs a new Properties object. + */ + public Properties() { + super(); + } + + /** + * Constructs a new Properties object using the specified default + * properties. + * + * @param properties + * the default properties + */ + public Properties(Properties properties) { + defaults = properties; + } - /** - * The default values for this Properties. - */ - protected Properties defaults; - - private static final int NONE = 0, SLASH = 1, UNICODE = 2, CONTINUE = 3, - KEY_DONE = 4, IGNORE = 5; - - /** - * Constructs a new Properties object. - */ - public Properties() { - super(); - } - - /** - * Constructs a new Properties object using the specified default - * properties. - * - * @param properties - * the default properties - */ - public Properties(Properties properties) { - defaults = properties; - } - - @SuppressWarnings("nls") + @SuppressWarnings("nls") private void dumpString(StringBuilder buffer, String string, boolean key) { - int i = 0; - if (!key && i < string.length() && string.charAt(i) == ' ') { - buffer.append("\\ "); //$NON-NLS-1$ - i++; - } - - for (; i < string.length(); i++) { - char ch = string.charAt(i); - switch (ch) { - case '\t': - buffer.append("\\t"); //$NON-NLS-1$ - break; - case '\n': - buffer.append("\\n"); //$NON-NLS-1$ - break; - case '\f': - buffer.append("\\f"); //$NON-NLS-1$ - break; - case '\r': - buffer.append("\\r"); //$NON-NLS-1$ - break; - default: - if ("\\#!=:".indexOf(ch) >= 0 || (key && ch == ' ')) { + int i = 0; + if (!key && i < string.length() && string.charAt(i) == ' ') { + buffer.append("\\ "); //$NON-NLS-1$ + i++; + } + + for (; i < string.length(); i++) { + char ch = string.charAt(i); + switch (ch) { + case '\t': + buffer.append("\\t"); //$NON-NLS-1$ + break; + case '\n': + buffer.append("\\n"); //$NON-NLS-1$ + break; + case '\f': + buffer.append("\\f"); //$NON-NLS-1$ + break; + case '\r': + buffer.append("\\r"); //$NON-NLS-1$ + break; + default: + if ("\\#!=:".indexOf(ch) >= 0 || (key && ch == ' ')) { buffer.append('\\'); } - if (ch >= ' ' && ch <= '~') { - buffer.append(ch); - } else { - String hex = Integer.toHexString(ch); - buffer.append("\\u"); //$NON-NLS-1$ - for (int j = 0; j < 4 - hex.length(); j++) { + if (ch >= ' ' && ch <= '~') { + buffer.append(ch); + } else { + String hex = Integer.toHexString(ch); + buffer.append("\\u"); //$NON-NLS-1$ + for (int j = 0; j < 4 - hex.length(); j++) { buffer.append("0"); //$NON-NLS-1$ } - buffer.append(hex); - } - } - } - } - - /** - * Searches for the property with the specified name. If the property is not - * found, look in the default properties. If the property is not found in - * the default properties, answer null. - * - * @param name - * the name of the property to find - * @return the named property value - */ - public String getProperty(String name) { - Object result = super.get(name); - String property = result instanceof String ? (String) result : null; - if (property == null && defaults != null) { - property = defaults.getProperty(name); - } - return property; - } - - /** - * Searches for the property with the specified name. If the property is not - * found, look in the default properties. If the property is not found in - * the default properties, answer the specified default. - * - * @param name - * the name of the property to find - * @param defaultValue - * the default value - * @return the named property value - */ - public String getProperty(String name, String defaultValue) { - Object result = super.get(name); - String property = result instanceof String ? (String) result : null; - if (property == null && defaults != null) { - property = defaults.getProperty(name); - } - if (property == null) { + buffer.append(hex); + } + } + } + } + + /** + * Searches for the property with the specified name. If the property is not + * found, look in the default properties. If the property is not found in + * the default properties, answer null. + * + * @param name + * the name of the property to find + * @return the named property value + */ + public String getProperty(String name) { + Object result = super.get(name); + String property = result instanceof String ? (String) result : null; + if (property == null && defaults != null) { + property = defaults.getProperty(name); + } + return property; + } + + /** + * Searches for the property with the specified name. If the property is not + * found, look in the default properties. If the property is not found in + * the default properties, answer the specified default. + * + * @param name + * the name of the property to find + * @param defaultValue + * the default value + * @return the named property value + */ + public String getProperty(String name, String defaultValue) { + Object result = super.get(name); + String property = result instanceof String ? (String) result : null; + if (property == null && defaults != null) { + property = defaults.getProperty(name); + } + if (property == null) { return defaultValue; } - return property; - } + return property; + } - /** - * Lists the mappings in this Properties to the specified PrintStream in a - * human readable form. - * - * @param out - * the PrintStream - */ - public void list(PrintStream out) { - if (out == null) { + /** + * Lists the mappings in this Properties to the specified PrintStream in a + * human readable form. + * + * @param out + * the PrintStream + */ + public void list(PrintStream out) { + if (out == null) { throw new NullPointerException(); } - StringBuffer buffer = new StringBuffer(80); - Enumeration keys = propertyNames(); - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - buffer.append(key); - buffer.append('='); - String property = (String) super.get(key); - Properties def = defaults; - while (property == null) { - property = (String) def.get(key); - def = def.defaults; - } - if (property.length() > 40) { - buffer.append(property.substring(0, 37)); - buffer.append("..."); //$NON-NLS-1$ - } else { + StringBuffer buffer = new StringBuffer(80); + Enumeration keys = propertyNames(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + buffer.append(key); + buffer.append('='); + String property = (String) super.get(key); + Properties def = defaults; + while (property == null) { + property = (String) def.get(key); + def = def.defaults; + } + if (property.length() > 40) { + buffer.append(property.substring(0, 37)); + buffer.append("..."); //$NON-NLS-1$ + } else { buffer.append(property); } - out.println(buffer.toString()); - buffer.setLength(0); - } - } - - /** - * Lists the mappings in this Properties to the specified PrintWriter in a - * human readable form. - * - * @param writer - * the PrintWriter - */ - public void list(PrintWriter writer) { - if (writer == null) { + out.println(buffer.toString()); + buffer.setLength(0); + } + } + + /** + * Lists the mappings in this Properties to the specified PrintWriter in a + * human readable form. + * + * @param writer + * the PrintWriter + */ + public void list(PrintWriter writer) { + if (writer == null) { throw new NullPointerException(); } - StringBuffer buffer = new StringBuffer(80); - Enumeration keys = propertyNames(); - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - buffer.append(key); - buffer.append('='); - String property = (String) super.get(key); - Properties def = defaults; - while (property == null) { - property = (String) def.get(key); - def = def.defaults; - } - if (property.length() > 40) { - buffer.append(property.substring(0, 37)); - buffer.append("..."); //$NON-NLS-1$ - } else { + StringBuffer buffer = new StringBuffer(80); + Enumeration keys = propertyNames(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + buffer.append(key); + buffer.append('='); + String property = (String) super.get(key); + Properties def = defaults; + while (property == null) { + property = (String) def.get(key); + def = def.defaults; + } + if (property.length() > 40) { + buffer.append(property.substring(0, 37)); + buffer.append("..."); //$NON-NLS-1$ + } else { buffer.append(property); } - writer.println(buffer.toString()); - buffer.setLength(0); - } - } - - /** - * Loads properties from the specified InputStream. The properties are of - * the form key=value, one property per line. - * - * @param in - * the input stream - * @throws IOException - */ - public synchronized void load(InputStream in) throws IOException { - if (in == null) { - throw new NullPointerException(); - } - int mode = NONE, unicode = 0, count = 0; - char nextChar, buf[] = new char[40]; - int offset = 0, keyLength = -1, intVal; - boolean firstChar = true; - BufferedInputStream bis = new BufferedInputStream(in); + writer.println(buffer.toString()); + buffer.setLength(0); + } + } + + /** + * Loads properties from the specified InputStream. The properties are of + * the form key=value, one property per line. + * + * @param in + * the input stream + * @throws IOException + */ + @SuppressWarnings("fallthrough") + public synchronized void load(InputStream in) throws IOException { + if (in == null) { + throw new NullPointerException(); + } + int mode = NONE, unicode = 0, count = 0; + char nextChar, buf[] = new char[40]; + int offset = 0, keyLength = -1, intVal; + boolean firstChar = true; + BufferedInputStream bis = new BufferedInputStream(in); - while (true) { - intVal = bis.read(); + while (true) { + intVal = bis.read(); if (intVal == -1) { // if mode is UNICODE but has less than 4 hex digits, should // throw an IllegalArgumentException // luni.08=Invalid Unicode sequence: expected format \\uxxxx if (mode == UNICODE && count < 4) { - throw new IllegalArgumentException(Messages - .getString("luni.08")); //$NON-NLS-1$ + throw new IllegalArgumentException(Messages.getString("luni.08")); //$NON-NLS-1$ } // if mode is SLASH and no data is read, should append '\u0000' // to buf @@ -286,144 +286,144 @@ } nextChar = (char) (intVal & 0xff); - if (offset == buf.length) { - char[] newBuf = new char[buf.length * 2]; - System.arraycopy(buf, 0, newBuf, 0, offset); - buf = newBuf; - } - if (mode == UNICODE) { - int digit = Character.digit(nextChar, 16); - if (digit >= 0) { - unicode = (unicode << 4) + digit; - if (++count < 4) { + if (offset == buf.length) { + char[] newBuf = new char[buf.length * 2]; + System.arraycopy(buf, 0, newBuf, 0, offset); + buf = newBuf; + } + if (mode == UNICODE) { + int digit = Character.digit(nextChar, 16); + if (digit >= 0) { + unicode = (unicode << 4) + digit; + if (++count < 4) { continue; } - } else if (count <= 4) { + } else { // luni.09=Invalid Unicode sequence: illegal character - throw new IllegalArgumentException(Messages - .getString("luni.09")); //$NON-NLS-1$ - } - mode = NONE; - buf[offset++] = (char) unicode; - if (nextChar != '\n') { - continue; - } - } - if (mode == SLASH) { - mode = NONE; - switch (nextChar) { - case '\r': - mode = CONTINUE; // Look for a following \n - continue; - case '\n': - mode = IGNORE; // Ignore whitespace on the next line - continue; - case 'b': - nextChar = '\b'; - break; - case 'f': - nextChar = '\f'; - break; - case 'n': - nextChar = '\n'; - break; - case 'r': - nextChar = '\r'; - break; - case 't': - nextChar = '\t'; - break; - case 'u': - mode = UNICODE; - unicode = count = 0; - continue; + throw new IllegalArgumentException(Messages.getString("luni.09")); //$NON-NLS-1$ } - } else { - switch (nextChar) { - case '#': - case '!': - if (firstChar) { - while (true) { + mode = NONE; + buf[offset++] = (char) unicode; + if (nextChar != '\n') { + continue; + } + } + if (mode == SLASH) { + mode = NONE; + switch (nextChar) { + case '\r': + mode = CONTINUE; // Look for a following \n + continue; + case '\n': + mode = IGNORE; // Ignore whitespace on the next line + continue; + case 'b': + nextChar = '\b'; + break; + case 'f': + nextChar = '\f'; + break; + case 'n': + nextChar = '\n'; + break; + case 'r': + nextChar = '\r'; + break; + case 't': + nextChar = '\t'; + break; + case 'u': + mode = UNICODE; + unicode = count = 0; + continue; + } + } else { + switch (nextChar) { + case '#': + case '!': + if (firstChar) { + while (true) { intVal = bis.read(); - if (intVal == -1) + if (intVal == -1) { break; + } // & 0xff not required nextChar = (char) intVal; if (nextChar == '\r' || nextChar == '\n') { break; } - } - continue; - } - break; - case '\n': - if (mode == CONTINUE) { // Part of a \r\n sequence - mode = IGNORE; // Ignore whitespace on the next line - continue; - } - // fall into the next case - case '\r': - mode = NONE; - firstChar = true; - if (offset > 0) { - if (keyLength == -1) { - keyLength = offset; - } - String temp = new String(buf, 0, offset); - put(temp.substring(0, keyLength), temp - .substring(keyLength)); - } - keyLength = -1; - offset = 0; - continue; - case '\\': - if (mode == KEY_DONE) { - keyLength = offset; - } - mode = SLASH; - continue; - case ':': - case '=': - if (keyLength == -1) { // if parsing the key - mode = NONE; - keyLength = offset; - continue; - } - break; - } - if (Character.isWhitespace(nextChar)) { - if (mode == CONTINUE) { + } + continue; + } + break; + case '\n': + if (mode == CONTINUE) { // Part of a \r\n sequence + mode = IGNORE; // Ignore whitespace on the next line + continue; + } + // fall into the next case + case '\r': + mode = NONE; + firstChar = true; + if (offset > 0) { + if (keyLength == -1) { + keyLength = offset; + } + String temp = new String(buf, 0, offset); + put(temp.substring(0, keyLength), temp + .substring(keyLength)); + } + keyLength = -1; + offset = 0; + continue; + case '\\': + if (mode == KEY_DONE) { + keyLength = offset; + } + mode = SLASH; + continue; + case ':': + case '=': + if (keyLength == -1) { // if parsing the key + mode = NONE; + keyLength = offset; + continue; + } + break; + } + if (Character.isWhitespace(nextChar)) { + if (mode == CONTINUE) { mode = IGNORE; } - // if key length == 0 or value length == 0 - if (offset == 0 || offset == keyLength || mode == IGNORE) { - continue; - } - if (keyLength == -1) { // if parsing the key - mode = KEY_DONE; + // if key length == 0 or value length == 0 + if (offset == 0 || offset == keyLength || mode == IGNORE) { continue; } - } - if (mode == IGNORE || mode == CONTINUE) { + if (keyLength == -1) { // if parsing the key + mode = KEY_DONE; + continue; + } + } + if (mode == IGNORE || mode == CONTINUE) { mode = NONE; } - } - firstChar = false; - if (mode == KEY_DONE) { - keyLength = offset; - mode = NONE; - } - buf[offset++] = nextChar; - } - if (keyLength == -1 && offset > 0) { + } + firstChar = false; + if (mode == KEY_DONE) { + keyLength = offset; + mode = NONE; + } + buf[offset++] = nextChar; + } + if(keyLength==-1 && offset>0){ keyLength = offset; } - if (keyLength >= 0) { - String temp = new String(buf, 0, offset); - put(temp.substring(0, keyLength), temp.substring(keyLength)); - } - } - + if (keyLength >= 0) { + String temp = new String(buf, 0, offset); + put(temp.substring(0, keyLength), temp.substring(keyLength)); + } + } + /** * Loads properties from the specified InputStream. The properties are of * the form key=value, one property per line. It may be not @@ -435,9 +435,6 @@ * @since 1.6 */ public synchronized void load(Reader reader) throws IOException { - if (reader == null) { - throw new NullPointerException(); - } int mode = NONE, unicode = 0, count = 0; char nextChar, buf[] = new char[40]; int offset = 0, keyLength = -1, intVal; @@ -446,21 +443,7 @@ while (true) { intVal = br.read(); - if (intVal == -1) { - // if mode is UNICODE but has less than 4 hex digits, should - // throw an IllegalArgumentException - // luni.08=Invalid Unicode sequence: expected format \\uxxxx - if (mode == UNICODE && count < 4) { - throw new IllegalArgumentException(Messages - .getString("luni.08")); //$NON-NLS-1$ - } - // if mode is SLASH and no data is read, should append '\u0000' - // to buf - if (mode == SLASH) { - buf[offset++] = '\u0000'; - } - break; - } + if (intVal == -1) break; nextChar = (char) intVal; if (offset == buf.length) { @@ -477,8 +460,7 @@ } } else if (count <= 4) { // luni.09=Invalid Unicode sequence: illegal character - throw new IllegalArgumentException(Messages - .getString("luni.09")); //$NON-NLS-1$ + throw new IllegalArgumentException(Messages.getString("luni.09")); } mode = NONE; buf[offset++] = (char) unicode; @@ -523,13 +505,11 @@ if (firstChar) { while (true) { intVal = br.read(); - if (intVal == -1) - break; + if (intVal == -1) break; nextChar = (char) intVal; // & 0xff - // not - // required - if (nextChar == '\r' || nextChar == '\n' - || nextChar == '\u0085') { + // not + // required + if (nextChar == '\r' || nextChar == '\n' || nextChar == '\u0085') { break; } } @@ -541,7 +521,7 @@ mode = IGNORE; // Ignore whitespace on the next line continue; } - // fall into the next case + // fall into the next case case '\u0085': case '\r': mode = NONE; @@ -596,39 +576,48 @@ } buf[offset++] = nextChar; } + if (mode == UNICODE && count <= 4) { + // luni.08=Invalid Unicode sequence: expected format \\uxxxx + throw new IllegalArgumentException(Messages.getString("luni.08")); + } if (keyLength == -1 && offset > 0) { keyLength = offset; } if (keyLength >= 0) { String temp = new String(buf, 0, offset); - put(temp.substring(0, keyLength), temp.substring(keyLength)); + String key = temp.substring(0, keyLength); + String value = temp.substring(keyLength); + if (mode == SLASH) { + value += "\u0000"; + } + put(key, value); } - } + } - /** + /** * Answers all of the property names that this Properties contains. * * @return an Enumeration containing the names of all properties */ - public Enumeration propertyNames() { - if (defaults == null) { + public Enumeration propertyNames() { + if (defaults == null) { return keys(); } Hashtable set = new Hashtable(defaults .size() + size()); - Enumeration keys = defaults.propertyNames(); - while (keys.hasMoreElements()) { - set.put(keys.nextElement(), set); - } - keys = keys(); - while (keys.hasMoreElements()) { - set.put(keys.nextElement(), set); - } - return set.keys(); - } - + Enumeration keys = defaults.propertyNames(); + while (keys.hasMoreElements()) { + set.put(keys.nextElement(), set); + } + keys = keys(); + while (keys.hasMoreElements()) { + set.put(keys.nextElement(), set); + } + return set.keys(); + } + /** * Answers a set of keys in this property list whoes key and value are * strings. @@ -636,109 +625,108 @@ * @return a set of keys in the property list * * @since 1.6 - */ - public Set stringPropertyNames() { - HashSet set = new HashSet(); + */ + public Set stringPropertyNames(){ + HashSet set = new HashSet(); Enumeration keys = propertyNames(); while (keys.hasMoreElements()) { - Object key = keys.nextElement(); + Object key = keys.nextElement(); if (key instanceof String) { Object value = this.get(key); - if (value == null) { + if (value == null){ value = this.defaults.get(key); } - if (value instanceof String) { - set.add((String) key); + if (value instanceof String){ + set.add((String)key); } - } + } } return Collections.unmodifiableSet(set); } - /** - * Saves the mappings in this Properties to the specified OutputStream, - * putting the specified comment at the beginning. The output from this - * method is suitable for being read by the load() method. - * - * @param out - * the OutputStream - * @param comment - * the comment - * - * @exception ClassCastException - * when the key or value of a mapping is not a String - * - * @deprecated Does not throw an IOException, use store() - */ - @Deprecated + /** + * Saves the mappings in this Properties to the specified OutputStream, + * putting the specified comment at the beginning. The output from this + * method is suitable for being read by the load() method. + * + * @param out + * the OutputStream + * @param comment + * the comment + * + * @exception ClassCastException + * when the key or value of a mapping is not a String + * + * @deprecated Does not throw an IOException, use store() + */ + @Deprecated public void save(OutputStream out, String comment) { - try { - store(out, comment); - } catch (IOException e) { - // ignore - } - } - - /** - * Maps the specified key to the specified value. If the key already exists, - * the old value is replaced. The key and value cannot be null. - * - * @param name - * the key - * @param value - * the value - * @return the old value mapped to the key, or null - */ - public Object setProperty(String name, String value) { - return put(name, value); - } - - private static String lineSeparator; - - /** - * Stores the mappings in this Properties to the specified OutputStream, - * putting the specified comment at the beginning. The output from this - * method is suitable for being read by the load() method. - * - * @param out - * the OutputStream - * @param comment - * the comment - * @throws IOException - * - * @exception ClassCastException - * when the key or value of a mapping is not a String - */ - public synchronized void store(OutputStream out, String comments) - throws IOException { - if (lineSeparator == null) { - lineSeparator = AccessController - .doPrivileged(new PriviAction("line.separator")); //$NON-NLS-1$ - } - - StringBuilder buffer = new StringBuilder(200); - OutputStreamWriter writer = new OutputStreamWriter(out, "ISO8859_1"); //$NON-NLS-1$ - if (comments != null) { + try { + store(out, comment); + } catch (IOException e) { + } + } + + /** + * Maps the specified key to the specified value. If the key already exists, + * the old value is replaced. The key and value cannot be null. + * + * @param name + * the key + * @param value + * the value + * @return the old value mapped to the key, or null + */ + public Object setProperty(String name, String value) { + return put(name, value); + } + + private static String lineSeparator; + + /** + * Stores the mappings in this Properties to the specified OutputStream, + * putting the specified comment at the beginning. The output from this + * method is suitable for being read by the load() method. + * + * @param out + * the OutputStream + * @param comment + * the comment + * @throws IOException + * + * @exception ClassCastException + * when the key or value of a mapping is not a String + */ + public synchronized void store(OutputStream out, String comments) + throws IOException { + if (lineSeparator == null) { + lineSeparator = AccessController + .doPrivileged(new PriviAction("line.separator")); //$NON-NLS-1$ + } + + StringBuilder buffer = new StringBuilder(200); + OutputStreamWriter writer = new OutputStreamWriter(out, "ISO8859_1"); //$NON-NLS-1$ + if (comments != null) { writer.write("#"); //$NON-NLS-1$ writer.write(comments); - writer.write(lineSeparator); + writer.write(lineSeparator); } writer.write("#"); //$NON-NLS-1$ writer.write(new Date().toString()); - writer.write(lineSeparator); - - for (Map.Entry entry : entrySet()) { - String key = (String) entry.getKey(); - dumpString(buffer, key, true); - buffer.append('='); - dumpString(buffer, (String) entry.getValue(), false); - buffer.append(lineSeparator); - writer.write(buffer.toString()); - buffer.setLength(0); - } - writer.flush(); - } + writer.write(lineSeparator); + for (Map.Entry entry : entrySet()) { + String key = (String) entry.getKey(); + dumpString(buffer, key, true); + buffer.append('='); + dumpString(buffer, (String) entry.getValue(), false); + buffer.append(lineSeparator); + writer.write(buffer.toString()); + buffer.setLength(0); + } + writer.flush(); + } + /** * Stores the mappings in this Properties to the specified OutputStream, * putting the specified comment at the beginning. The output from this @@ -748,12 +736,11 @@ * the writer * @param comments * the comment - * @throws IOException - * if any I/O exception occurs - * @since 1.6 + * @throws IOException + * if any I/O exception occurs + * @since 1.6 */ - public synchronized void store(Writer writer, String comments) - throws IOException { + public synchronized void store(Writer writer, String comments) throws IOException { if (lineSeparator == null) { lineSeparator = AccessController .doPrivileged(new PriviAction("line.separator")); //$NON-NLS-1$ @@ -762,11 +749,11 @@ if (comments != null) { writer.write("#"); //$NON-NLS-1$ writer.write(comments); - writer.write(lineSeparator); + writer.write(lineSeparator); } writer.write("#"); //$NON-NLS-1$ writer.write(new Date().toString()); - writer.write(lineSeparator); + writer.write(lineSeparator); for (Map.Entry entry : entrySet()) { String key = (String) entry.getKey(); @@ -780,23 +767,23 @@ writer.flush(); } - public synchronized void loadFromXML(InputStream in) throws IOException, - InvalidPropertiesFormatException { + public synchronized void loadFromXML(InputStream in) + throws IOException, InvalidPropertiesFormatException { if (in == null) { throw new NullPointerException(); } - + if (builder == null) { DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); factory.setValidating(true); - + try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new Error(e); } - + builder.setErrorHandler(new ErrorHandler() { public void warning(SAXParseException e) throws SAXException { throw e; @@ -810,7 +797,7 @@ throw e; } }); - + builder.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { @@ -825,20 +812,20 @@ } }); } - + try { Document doc = builder.parse(in); - NodeList entries = doc.getElementsByTagName("entry"); + NodeList entries = doc.getElementsByTagName("entry"); if (entries == null) { return; } int entriesListLength = entries.getLength(); - + for (int i = 0; i < entriesListLength; i++) { Element entry = (Element) entries.item(i); String key = entry.getAttribute("key"); String value = entry.getTextContent(); - + /* * key != null & value != null but key or(and) value can be * empty String @@ -851,25 +838,25 @@ throw new InvalidPropertiesFormatException(e); } } - + public void storeToXML(OutputStream os, String comment) throws IOException { - storeToXML(os, comment, "UTF-8"); + storeToXML(os, comment, "UTF-8"); //$NON-NLS-1$ } - + public synchronized void storeToXML(OutputStream os, String comment, String encoding) throws IOException { if (os == null || encoding == null) { throw new NullPointerException(); } - + /* * We can write to XML file using encoding parameter but note that some * aliases for encodings are not supported by the XML parser. Thus we * have to know canonical name for encoding used to store data in XML * since the XML parser must recognize encoding name used to store data. */ - + String encodingCanonicalName; try { encodingCanonicalName = Charset.forName(encoding).name(); @@ -885,17 +872,17 @@ PrintStream printStream = new PrintStream(os, false, encodingCanonicalName); - + printStream.print(""); - + printStream.print(""); - + printStream.println(""); - + if (comment != null) { printStream.print(""); printStream.print(substitutePredefinedEntries(comment)); @@ -914,9 +901,9 @@ printStream.println(""); printStream.flush(); } - + private String substitutePredefinedEntries(String s) { - + /* * substitution for predefined character entities to use them safely in * XML @@ -924,5 +911,5 @@ return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll( ">", ">").replaceAll("\u0027", "'").replaceAll("\"", """); - } + } } Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Scanner.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Scanner.java?rev=768698&r1=768697&r2=768698&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Scanner.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Scanner.java Sun Apr 26 12:30:01 2009 @@ -372,10 +372,12 @@ * bug is fixed. */ int oldLimit = buffer.limit(); - buffer.limit(horizonLineSeparator); + // Considering the look ahead feature, the line terminator should be involved as RI + buffer.limit(horizonLineSeparator + terminatorLength); // ========== To deal with regex bug ==================== - matcher.region(findStartIndex, horizonLineSeparator); + // Considering the look ahead feature, the line terminator should be involved as RI + matcher.region(findStartIndex, horizonLineSeparator + terminatorLength); if (matcher.find()) { // The scanner advances past the input that matched findStartIndex = matcher.end(); @@ -384,6 +386,18 @@ if (horizonLineSeparator == matcher.end()) { findStartIndex += terminatorLength; } + // the line terminator itself should not be a part of + // the match result according to the Spec + if (horizonLineSeparator != bufferLength + && (horizonLineSeparator + terminatorLength == matcher + .end())) { + // ========== To deal with regex bug ==================== + buffer.limit(oldLimit); + // ========== To deal with regex bug ==================== + + matchSuccessful = false; + return null; + } matchSuccessful = true; // ========== To deal with regex bug ==================== Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c?rev=768698&r1=768697&r2=768698&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c Sun Apr 26 12:30:01 2009 @@ -36,6 +36,12 @@ #include "IFileSystem.h" #include "OSFileSystem.h" +#ifdef ZOS +#define FD_BIAS 1000 +#else +#define FD_BIAS 0 +#endif /* ZOS */ + typedef int OSSOCKET; typedef struct hysocket_struct { @@ -55,6 +61,7 @@ int rc; int waitMode = (waitFlag) ? F_SETLKW : F_SETLK; struct flock lock = { 0 }; + jlong lockHandle = handle - FD_BIAS; // If start or length overflow the max values we can represent, then max them out. #if __WORDSIZE==32 @@ -85,7 +92,7 @@ do { - rc = fcntl (handle, waitMode, &lock); + rc = fcntl (lockHandle, waitMode, &lock); } while ((rc < 0) && (errno == EINTR)); @@ -100,6 +107,7 @@ { int rc; struct flock lock = { 0 }; + jlong lockHandle = handle - FD_BIAS; // If start or length overflow the max values we can represent, then max them out. #if __WORDSIZE==32 @@ -121,7 +129,7 @@ do { - rc = fcntl (handle, F_SETLKW, &lock); + rc = fcntl (lockHandle, F_SETLKW, &lock); } while ((rc < 0) && (errno == EINTR)); Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedOutputStreamTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedOutputStreamTest.java?rev=768698&r1=768697&r2=768698&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedOutputStreamTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/BufferedOutputStreamTest.java Sun Apr 26 12:30:01 2009 @@ -52,6 +52,49 @@ os.write(fileString.getBytes(), 0, 500); } + public void test_flush_Constructor_NullStream() throws IOException { + BufferedOutputStream buffos = new java.io.BufferedOutputStream(null); + try { + buffos.flush(); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } + try { + buffos.close(); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } + + buffos = new java.io.BufferedOutputStream(null, 10); + try { + buffos.flush(); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } + try { + buffos.close(); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } + + try { + new java.io.BufferedOutputStream(null, 0); + fail("should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // Expected + } + try { + new java.io.BufferedOutputStream(null, -1); + fail("should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // Expected + } + } + /** * @tests java.io.BufferedOutputStream#flush() */ @@ -99,8 +142,8 @@ bais.available() >= 1000); byte[] wbytes = new byte[1013]; bais.read(wbytes, 0, 1013); - assertTrue("Incorrect bytes written", fileString.substring(0, 1013) - .equals(new String(wbytes, 0, wbytes.length))); + assertEquals("Incorrect bytes written", new String(wbytes, 0, + wbytes.length), fileString.substring(0, 1013)); // regression test for HARMONY-4177 MockOutputStream mos = new MockOutputStream(5); @@ -215,8 +258,44 @@ // expected } + try { + bos.write(byteArray, 0, byteArray.length + 1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + try { + bos.write(byteArray, 1, byteArray.length); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + try { + bos.write(byteArray, -1, byteArray.length); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + try { + bos.write(byteArray, byteArray.length, -1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + bos.write(byteArray, byteArray.length, 0); + try { + bos.write(byteArray, byteArray.length, 1); + fail("should throw ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + bos.write(byteArray, 0, 0); bos.write(byteArray, 0, 1); + bos.write(byteArray, 1, byteArray.length - 1); bos.write(byteArray, 0, byteArray.length); try { @@ -566,20 +645,186 @@ assertEquals("Incorrect byte written", 't', wbytes[0]); } + public void test_write_Close() throws IOException { + BufferedOutputStream buffos = new BufferedOutputStream( + new ByteArrayOutputStream()); + buffos.write(new byte[0]); + try { + buffos.write(null); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } + byte[] buffer = "1234567890".getBytes(); + + buffos.write(Integer.MIN_VALUE); + buffos.write(Integer.MAX_VALUE); + buffos.write(buffer, 0, 10); + buffos.flush(); + + buffos.close(); + + buffos.write(Integer.MIN_VALUE); + buffos.write(Integer.MAX_VALUE); + buffos.write(buffer, 0, 10); + buffos.flush(); + } + + public void test_write_Scenario1() throws IOException { + ByteArrayOutputStream byteArrayos = new ByteArrayOutputStream(); + ByteArrayInputStream byteArrayis = null; + byte[] buffer = "1234567890".getBytes(); + + BufferedOutputStream buffos = new BufferedOutputStream(byteArrayos, 10); + buffos.write(buffer, 0, 10); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes written, not buffered", 10, byteArrayis.available()); + buffos.flush(); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes not written after flush", 10, byteArrayis + .available()); + for (int i = 0; i < 10; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + + buffos.write(buffer, 0, 10); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes written, not buffered", 20, byteArrayis.available()); + buffos.flush(); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes not written after flush", 20, byteArrayis + .available()); + for (int i = 0; i < 10; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + for (int i = 0; i < 10; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + + buffos.write(buffer, 0, 10); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes written, not buffered", 30, byteArrayis.available()); + buffos.flush(); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes not written after flush", 30, byteArrayis + .available()); + for (int i = 0; i < 10; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + for (int i = 0; i < 10; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + for (int i = 0; i < 10; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + } + + public void test_write_Scenario2() throws IOException { + ByteArrayOutputStream byteArrayos = new ByteArrayOutputStream(); + ByteArrayInputStream byteArrayis = null; + byte[] buffer = "1234567890".getBytes(); + + BufferedOutputStream buffos = new BufferedOutputStream(byteArrayos, 20); + buffos.write(buffer, 0, 10); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes written, not buffered", 0, byteArrayis.available()); + buffos.flush(); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes not written after flush", 10, byteArrayis + .available()); + for (int i = 0; i < 10; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + + byte[] buffer2 = new byte[] { 'a', 'b', 'c', 'd' }; + buffos.write(buffer2, 0, 4); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes written, not buffered", 10, byteArrayis.available()); + buffos.flush(); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes not written after flush", 14, byteArrayis + .available()); + for (int i = 0; i < 10; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + for (int i = 0; i < 4; i++) { + assertEquals(buffer2[i], byteArrayis.read()); + } + + buffos.close(); + + byte[] buffer3 = new byte[] { 'e', 'f', 'g', 'h', 'i' }; + buffos.write(buffer3, 0, 5); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes written, not buffered", 14, byteArrayis.available()); + buffos.flush(); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes not written after flush", 19, byteArrayis + .available()); + for (int i = 0; i < 10; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + for (int i = 0; i < 4; i++) { + assertEquals(buffer2[i], byteArrayis.read()); + } + for (int i = 0; i < 5; i++) { + assertEquals(buffer3[i], byteArrayis.read()); + } + + buffos.write(new byte[] { 'j', 'k' }); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes written, not buffered", 19, byteArrayis.available()); + buffos.flush(); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes not written after flush", 21, byteArrayis + .available()); + } + + public void test_write_Scenario3() throws IOException { + ByteArrayOutputStream byteArrayos = new ByteArrayOutputStream(); + ByteArrayInputStream byteArrayis = null; + byte[] buffer = "1234567890".getBytes(); + + BufferedOutputStream buffos = new BufferedOutputStream(byteArrayos, 5); + buffos.write(buffer, 0, 4); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes written, not buffered", 0, byteArrayis.available()); + buffos.flush(); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes not written after flush", 4, byteArrayis + .available()); + for (int i = 0; i < 4; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + + buffos.write(buffer, 0, 5); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes written, not buffered", 9, byteArrayis.available()); + buffos.flush(); + byteArrayis = new ByteArrayInputStream(byteArrayos.toByteArray()); + assertEquals("Bytes not written after flush", 9, byteArrayis + .available()); + for (int i = 0; i < 4; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + for (int i = 0; i < 5; i++) { + assertEquals(buffer[i], byteArrayis.read()); + } + } + /** * Tears down the fixture, for example, close a network connection. This * method is called after a test is executed. */ - protected void tearDown() { - try { - if (bais != null) - bais.close(); - if (os != null) - os.close(); - if (baos != null) - baos.close(); - } catch (Exception e) { - System.out.println("Exception during tearDown" + e.toString()); + protected void tearDown() throws IOException { + if (bais != null) { + bais.close(); + } + if (os != null) { + os.close(); + } + if (baos != null) { + baos.close(); } } } Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/WriterTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/WriterTest.java?rev=768698&r1=768697&r2=768698&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/WriterTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/WriterTest.java Sun Apr 26 12:30:01 2009 @@ -68,9 +68,7 @@ // Regression for HARMONY-51 Object lock = new Object(); Writer wr = new MockLockWriter(lock); - // FIXME This test should be added to the exclusion list until - // Thread.holdsLock works on IBM VME -// wr.write("Some string"); + wr.write("Some string"); wr.close(); } Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=768698&r1=768697&r2=768698&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java Sun Apr 26 12:30:01 2009 @@ -499,19 +499,6 @@ } theSocket.close(); - // Now validate that we get a interrupted exception if we try to connect - // to an address on which nobody is accepting connections and the - // timeout expired - theSocket = new Socket(); - try { - theSocket.connect(new InetSocketAddress(InetAddress.getLocalHost(), - 1), 200); - fail("No interrupted exception when connecting to address nobody listening on with short timeout 200"); - } catch (SocketTimeoutException e) { - // Expected - } - theSocket.close(); - // Now validate that we get the right exception if we connect when we // are already connected server = new ServerSocket(0); @@ -819,83 +806,6 @@ is.close(); client.close(); server.close(); - - // Simple read/write test over the IO streams - final ServerSocket pingServer = new ServerSocket(0); - Runnable runnable = new Runnable() { - public void run() { - try { - Socket worker = pingServer.accept(); - pingServer.close(); - InputStream in = worker.getInputStream(); - in.read(); - OutputStream out = worker.getOutputStream(); - out.write(new byte[42]); - worker.close(); - } catch (IOException e) { - fail(e.getMessage()); - } - } - }; - Thread thread = new Thread(runnable, "Socket.getInputStream"); - thread.start(); - - Socket pingClient = new Socket(InetAddress.getLocalHost(), pingServer - .getLocalPort()); - - // Busy wait until the client is connected. - int c = 0; - while (!pingClient.isConnected()) { - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } - if (++c > 4) { - fail("thread is not alive"); - } - } - - // Write some data to the server to provoke it - OutputStream out = pingClient.getOutputStream(); - out.write(new byte[256]); - - InputStream in = pingClient.getInputStream(); - in.read(new byte[42]); - if (isUnix()) { - try { - in.read(); - fail("Should throw SocketException"); - } catch (SocketException e) { - // expected - } - } else { - // Check EOF - assertEquals(-1, in.read()); - } - - in.close(); - - if (isUnix()) { - try { - in.read(); - fail("Should throw SocketException"); - } catch (SocketException e) { - // expected - } - try { - in.read(new byte[5]); - fail("Should throw SocketException"); - } catch (SocketException e) { - // expected - } - } else { - // No exception when reading a closed stream - assertEquals(-1, in.read()); - assertEquals(-1, in.read(new byte[5])); - } - - pingClient.close(); - pingServer.close(); } private boolean isUnix() { @@ -1169,12 +1079,6 @@ pingClient.close(); sinkServer.close(); - // Regression test for HARMONY-2934 - Socket socket = new Socket("127.0.0.1", 0, false); - OutputStream o = socket.getOutputStream(); - o.write(1); - socket.close(); - // Regression test for HARMONY-873 ServerSocket ss2 = new ServerSocket(0); Socket s = new Socket("127.0.0.1", ss2.getLocalPort()); Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/FormatterTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/FormatterTest.java?rev=768698&r1=768697&r2=768698&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/FormatterTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/FormatterTest.java Sun Apr 26 12:30:01 2009 @@ -1807,24 +1807,24 @@ china.set(Calendar.MILLISECOND, 609); final Object[][] lowerCaseGermanTriple = { - {0L, 'a', "Do"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'a', "So"}, //$NON-NLS-2$ - {-1000L, 'a', "Do"}, //$NON-NLS-2$ - {new Date(1147327147578L), 'a', "Do"}, //$NON-NLS-2$ - {paris, 'a', "Mo"}, //$NON-NLS-2$ - {china, 'a', "Mo"}, //$NON-NLS-2$ + {0L, 'a', "Do."}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'a', "So."}, //$NON-NLS-2$ + {-1000L, 'a', "Do."}, //$NON-NLS-2$ + {new Date(1147327147578L), 'a', "Do."}, //$NON-NLS-2$ + {paris, 'a', "Mo."}, //$NON-NLS-2$ + {china, 'a', "Mo."}, //$NON-NLS-2$ {0L, 'b', "Jan"}, //$NON-NLS-2$ {Long.MAX_VALUE, 'b', "Aug"}, //$NON-NLS-2$ {-1000L, 'b', "Jan"}, //$NON-NLS-2$ {new Date(1147327147578L), 'b', "Mai"}, //$NON-NLS-2$ {paris, 'b', "Mai"}, //$NON-NLS-2$ {china, 'b', "Mai"}, //$NON-NLS-2$ - {0L, 'c', "Do Jan 01 08:00:00 CST 1970"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'c', "So Aug 17 15:12:55 CST 292278994"}, //$NON-NLS-2$ - {-1000L, 'c', "Do Jan 01 07:59:59 CST 1970"}, //$NON-NLS-2$ - {new Date(1147327147578L), 'c', "Do Mai 11 13:59:07 CST 2006"}, //$NON-NLS-2$ - {paris, 'c', "Mo Mai 08 12:00:00 CEST 2006"}, //$NON-NLS-2$ - {china, 'c', "Mo Mai 08 12:00:00 GMT-08:00 2006"}, //$NON-NLS-2$ + {0L, 'c', "Do. Jan 01 08:00:00 GMT+08:00 1970"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'c', "So. Aug 17 15:18:47 GMT+08:00 292278994"}, //$NON-NLS-2$ + {-1000L, 'c', "Do. Jan 01 07:59:59 GMT+08:00 1970"}, //$NON-NLS-2$ + {new Date(1147327147578L), 'c', "Do. Mai 11 13:59:07 GMT+08:00 2006"}, //$NON-NLS-2$ + {paris, 'c', "Mo. Mai 08 12:00:00 MESZ 2006"}, //$NON-NLS-2$ + {china, 'c', "Mo. Mai 08 12:00:00 GMT-08:00 2006"}, //$NON-NLS-2$ {0L, 'd', "01"}, //$NON-NLS-2$ {Long.MAX_VALUE, 'd', "17"}, //$NON-NLS-2$ {-1000L, 'd', "01"}, //$NON-NLS-2$ @@ -1867,18 +1867,18 @@ {new Date(1147327147578L), 'm', "05"}, //$NON-NLS-2$ {paris, 'm', "05"}, //$NON-NLS-2$ {china, 'm', "05"}, //$NON-NLS-2$ - {0L, 'p', "am"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'p', "pm"}, //$NON-NLS-2$ - {-1000L, 'p', "am"}, //$NON-NLS-2$ - {new Date(1147327147578L), 'p', "pm"}, //$NON-NLS-2$ - {paris, 'p', "pm"}, //$NON-NLS-2$ - {china, 'p', "pm"}, //$NON-NLS-2$ - {0L, 'r', "08:00:00 AM"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'r', "03:12:55 PM"}, //$NON-NLS-2$ - {-1000L, 'r', "07:59:59 AM"}, //$NON-NLS-2$ - {new Date(1147327147578L), 'r', "01:59:07 PM"}, //$NON-NLS-2$ - {paris, 'r', "12:00:00 PM"}, //$NON-NLS-2$ - {china, 'r', "12:00:00 PM"}, //$NON-NLS-2$ + {0L, 'p', "vorm."}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'p', "nachm."}, //$NON-NLS-2$ + {-1000L, 'p', "vorm."}, //$NON-NLS-2$ + {new Date(1147327147578L), 'p', "nachm."}, //$NON-NLS-2$ + {paris, 'p', "nachm."}, //$NON-NLS-2$ + {china, 'p', "nachm."}, //$NON-NLS-2$ + {0L, 'r', "08:00:00 vorm."}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'r', "03:18:47 nachm."}, //$NON-NLS-2$ + {-1000L, 'r', "07:59:59 vorm."}, //$NON-NLS-2$ + {new Date(1147327147578L), 'r', "01:59:07 nachm."}, //$NON-NLS-2$ + {paris, 'r', "12:00:00 nachm."}, //$NON-NLS-2$ + {china, 'r', "12:00:00 nachm."}, //$NON-NLS-2$ {0L, 's', "0"}, //$NON-NLS-2$ {Long.MAX_VALUE, 's', "9223372036854775"}, //$NON-NLS-2$ {-1000L, 's', "-1"}, //$NON-NLS-2$ @@ -1913,12 +1913,12 @@ {new Date(1147327147578L), 'b', "mai"}, //$NON-NLS-2$ {paris, 'b', "mai"}, //$NON-NLS-2$ {china, 'b', "mai"}, //$NON-NLS-2$ - {0L, 'c', "jeu. janv. 01 08:00:00 CST 1970"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'c', "dim. ao\u00fbt 17 15:12:55 CST 292278994"}, //$NON-NLS-2$ - {-1000L, 'c', "jeu. janv. 01 07:59:59 CST 1970"}, //$NON-NLS-2$ - {new Date(1147327147578L), 'c', "jeu. mai 11 13:59:07 CST 2006"}, //$NON-NLS-2$ - {paris, 'c', "lun. mai 08 12:00:00 CEST 2006"}, //$NON-NLS-2$ - {china, 'c', "lun. mai 08 12:00:00 GMT-08:00 2006"}, //$NON-NLS-2$ + {0L, 'c', "jeu. janv. 01 08:00:00 UTC+08:00 1970"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'c', "dim. ao\u00fbt 17 15:18:47 UTC+08:00 292278994"}, //$NON-NLS-2$ + {-1000L, 'c', "jeu. janv. 01 07:59:59 UTC+08:00 1970"}, //$NON-NLS-2$ + {new Date(1147327147578L), 'c', "jeu. mai 11 13:59:07 UTC+08:00 2006"}, //$NON-NLS-2$ + {paris, 'c', "lun. mai 08 12:00:00 HAEC 2006"}, //$NON-NLS-2$ + {china, 'c', "lun. mai 08 12:00:00 UTC-08:00 2006"}, //$NON-NLS-2$ {0L, 'd', "01"}, //$NON-NLS-2$ {Long.MAX_VALUE, 'd', "17"}, //$NON-NLS-2$ {-1000L, 'd', "01"}, //$NON-NLS-2$ @@ -1968,7 +1968,7 @@ {paris, 'p', "pm"}, //$NON-NLS-2$ {china, 'p', "pm"}, //$NON-NLS-2$ {0L, 'r', "08:00:00 AM"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'r', "03:12:55 PM"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'r', "03:18:47 PM"}, //$NON-NLS-2$ {-1000L, 'r', "07:59:59 AM"}, //$NON-NLS-2$ {new Date(1147327147578L), 'r', "01:59:07 PM"}, //$NON-NLS-2$ {paris, 'r', "12:00:00 PM"}, //$NON-NLS-2$ @@ -2001,18 +2001,18 @@ {new Date(1147327147578L), 'a', "\u6728"}, //$NON-NLS-2$ {paris, 'a', "\u6708"}, //$NON-NLS-2$ {china, 'a', "\u6708"}, //$NON-NLS-2$ - {0L, 'b', "1"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'b', "8"}, //$NON-NLS-2$ - {-1000L, 'b', "1"}, //$NON-NLS-2$ - {new Date(1147327147578L), 'b', "5"}, //$NON-NLS-2$ - {paris, 'b', "5"}, //$NON-NLS-2$ - {china, 'b', "5"}, //$NON-NLS-2$ - {0L, 'c', "\u6728 1 01 08:00:00 CST 1970"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'c', "\u65e5 8 17 15:12:55 CST 292278994"}, //$NON-NLS-2$ - {-1000L, 'c', "\u6728 1 01 07:59:59 CST 1970"}, //$NON-NLS-2$ - {new Date(1147327147578L), 'c', "\u6728 5 11 13:59:07 CST 2006"}, //$NON-NLS-2$ - {paris, 'c', "\u6708 5 08 12:00:00 CEST 2006"}, //$NON-NLS-2$ - {china, 'c', "\u6708 5 08 12:00:00 GMT-08:00 2006"}, //$NON-NLS-2$ + {0L, 'b', "1\u6708"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'b', "8\u6708"}, //$NON-NLS-2$ + {-1000L, 'b', "1\u6708"}, //$NON-NLS-2$ + {new Date(1147327147578L), 'b', "5\u6708"}, //$NON-NLS-2$ + {paris, 'b', "5\u6708"}, //$NON-NLS-2$ + {china, 'b', "5\u6708"}, //$NON-NLS-2$ + {0L, 'c', "\u6728 1\u6708 01 08:00:00 GMT+08:00 1970"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'c', "\u65e5 8\u6708 17 15:18:47 GMT+08:00 292278994"}, //$NON-NLS-2$ + {-1000L, 'c', "\u6728 1\u6708 01 07:59:59 GMT+08:00 1970"}, //$NON-NLS-2$ + {new Date(1147327147578L), 'c', "\u6728 5\u6708 11 13:59:07 GMT+08:00 2006"}, //$NON-NLS-2$ + {paris, 'c', "\u6708 5\u6708 08 12:00:00 GMT+02:00 2006"}, //$NON-NLS-2$ + {china, 'c', "\u6708 5\u6708 08 12:00:00 GMT-08:00 2006"}, //$NON-NLS-2$ {0L, 'd', "01"}, //$NON-NLS-2$ {Long.MAX_VALUE, 'd', "17"}, //$NON-NLS-2$ {-1000L, 'd', "01"}, //$NON-NLS-2$ @@ -2025,12 +2025,12 @@ {new Date(1147327147578L), 'e', "11"}, //$NON-NLS-2$ {paris, 'e', "8"}, //$NON-NLS-2$ {china, 'e', "8"}, //$NON-NLS-2$ - {0L, 'h', "1"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'h', "8"}, //$NON-NLS-2$ - {-1000L, 'h', "1"}, //$NON-NLS-2$ - {new Date(1147327147578L), 'h', "5"}, //$NON-NLS-2$ - {paris, 'h', "5"}, //$NON-NLS-2$ - {china, 'h', "5"}, //$NON-NLS-2$ + {0L, 'h', "1\u6708"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'h', "8\u6708"}, //$NON-NLS-2$ + {-1000L, 'h', "1\u6708"}, //$NON-NLS-2$ + {new Date(1147327147578L), 'h', "5\u6708"}, //$NON-NLS-2$ + {paris, 'h', "5\u6708"}, //$NON-NLS-2$ + {china, 'h', "5\u6708"}, //$NON-NLS-2$ {0L, 'j', "001"}, //$NON-NLS-2$ {Long.MAX_VALUE, 'j', "229"}, //$NON-NLS-2$ {-1000L, 'j', "001"}, //$NON-NLS-2$ @@ -2062,7 +2062,7 @@ {paris, 'p', "\u5348\u5f8c"}, //$NON-NLS-2$ {china, 'p', "\u5348\u5f8c"}, //$NON-NLS-2$ {0L, 'r', "08:00:00 \u5348\u524d"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'r', "03:12:55 \u5348\u5f8c"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'r', "03:18:47 \u5348\u5f8c"}, //$NON-NLS-2$ {-1000L, 'r', "07:59:59 \u5348\u524d"}, //$NON-NLS-2$ {new Date(1147327147578L), 'r', "01:59:07 \u5348\u5f8c"}, //$NON-NLS-2$ {paris, 'r', "12:00:00 \u5348\u5f8c"}, //$NON-NLS-2$ @@ -2098,7 +2098,7 @@ f = new Formatter(Locale.GERMAN); f.format(formatSpecifier, lowerCaseGermanTriple[i][input]); assertEquals("Format pattern: " + formatSpecifier //$NON-NLS-2$ - + " Argument: " + lowerCaseGermanTriple[i][pattern], //$NON-NLS-2$ + + " Argument: " + lowerCaseGermanTriple[i][input], //$NON-NLS-2$ lowerCaseGermanTriple[i][output], f.toString()); f = new Formatter(Locale.GERMAN); @@ -2186,7 +2186,7 @@ {paris, 'L', "453"}, //$NON-NLS-2$ {china, 'L', "609"}, //$NON-NLS-2$ {0L, 'M', "00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'M', "12"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'M', "18"}, //$NON-NLS-2$ {-1000L, 'M', "59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'M', "59"}, //$NON-NLS-2$ {paris, 'M', "00"}, //$NON-NLS-2$ @@ -2204,19 +2204,19 @@ {paris, 'Q', "1147082400453"}, //$NON-NLS-2$ {china, 'Q', "1147118400609"}, //$NON-NLS-2$ {0L, 'R', "08:00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'R', "15:12"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'R', "15:18"}, //$NON-NLS-2$ {-1000L, 'R', "07:59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'R', "13:59"}, //$NON-NLS-2$ {paris, 'R', "12:00"}, //$NON-NLS-2$ {china, 'R', "12:00"}, //$NON-NLS-2$ {0L, 'S', "00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'S', "55"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'S', "47"}, //$NON-NLS-2$ {-1000L, 'S', "59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'S', "07"}, //$NON-NLS-2$ {paris, 'S', "00"}, //$NON-NLS-2$ {china, 'S', "00"}, //$NON-NLS-2$ {0L, 'T', "08:00:00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'T', "15:12:55"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'T', "15:18:47"}, //$NON-NLS-2$ {-1000L, 'T', "07:59:59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'T', "13:59:07"}, //$NON-NLS-2$ {paris, 'T', "12:00:00"}, //$NON-NLS-2$ @@ -2286,7 +2286,7 @@ {paris, 'L', "453"}, //$NON-NLS-2$ {china, 'L', "609"}, //$NON-NLS-2$ {0L, 'M', "00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'M', "12"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'M', "18"}, //$NON-NLS-2$ {-1000L, 'M', "59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'M', "59"}, //$NON-NLS-2$ {paris, 'M', "00"}, //$NON-NLS-2$ @@ -2304,19 +2304,19 @@ {paris, 'Q', "1147082400453"}, //$NON-NLS-2$ {china, 'Q', "1147118400609"}, //$NON-NLS-2$ {0L, 'R', "08:00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'R', "15:12"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'R', "15:18"}, //$NON-NLS-2$ {-1000L, 'R', "07:59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'R', "13:59"}, //$NON-NLS-2$ {paris, 'R', "12:00"}, //$NON-NLS-2$ {china, 'R', "12:00"}, //$NON-NLS-2$ {0L, 'S', "00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'S', "55"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'S', "47"}, //$NON-NLS-2$ {-1000L, 'S', "59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'S', "07"}, //$NON-NLS-2$ {paris, 'S', "00"}, //$NON-NLS-2$ {china, 'S', "00"}, //$NON-NLS-2$ {0L, 'T', "08:00:00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'T', "15:12:55"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'T', "15:18:47"}, //$NON-NLS-2$ {-1000L, 'T', "07:59:59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'T', "13:59:07"}, //$NON-NLS-2$ {paris, 'T', "12:00:00"}, //$NON-NLS-2$ @@ -2386,7 +2386,7 @@ {paris, 'L', "453"}, //$NON-NLS-2$ {china, 'L', "609"}, //$NON-NLS-2$ {0L, 'M', "00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'M', "12"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'M', "18"}, //$NON-NLS-2$ {-1000L, 'M', "59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'M', "59"}, //$NON-NLS-2$ {paris, 'M', "00"}, //$NON-NLS-2$ @@ -2404,19 +2404,19 @@ {paris, 'Q', "1147082400453"}, //$NON-NLS-2$ {china, 'Q', "1147118400609"}, //$NON-NLS-2$ {0L, 'R', "08:00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'R', "15:12"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'R', "15:18"}, //$NON-NLS-2$ {-1000L, 'R', "07:59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'R', "13:59"}, //$NON-NLS-2$ {paris, 'R', "12:00"}, //$NON-NLS-2$ {china, 'R', "12:00"}, //$NON-NLS-2$ {0L, 'S', "00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'S', "55"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'S', "47"}, //$NON-NLS-2$ {-1000L, 'S', "59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'S', "07"}, //$NON-NLS-2$ {paris, 'S', "00"}, //$NON-NLS-2$ {china, 'S', "00"}, //$NON-NLS-2$ {0L, 'T', "08:00:00"}, //$NON-NLS-2$ - {Long.MAX_VALUE, 'T', "15:12:55"}, //$NON-NLS-2$ + {Long.MAX_VALUE, 'T', "15:18:47"}, //$NON-NLS-2$ {-1000L, 'T', "07:59:59"}, //$NON-NLS-2$ {new Date(1147327147578L), 'T', "13:59:07"}, //$NON-NLS-2$ {paris, 'T', "12:00:00"}, //$NON-NLS-2$