harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Regis <xu.re...@gmail.com>
Subject Re: svn commit: r768169 - /harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Properties.java
Date Fri, 24 Apr 2009 09:47:40 GMT
It seems the trunk is already formatted, so I just do it in java6 branch.

Tim Ellison wrote:
> Isn't this just going to cause merge pain?
> 
> Better to reformat the HEAD and after merging format the Java 6 code
> similarly.
> 
> Regards,
> Tim
> 
> regisxu@apache.org wrote:
>> Author: regisxu
>> Date: Fri Apr 24 06:36:03 2009
>> New Revision: 768169
>>
>> URL: http://svn.apache.org/viewvc?rev=768169&view=rev
>> Log:
>> Format code of Properties.java, no functional change
>>
>> Modified:
>>     harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Properties.java
>>
>> 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=768169&r1=768168&r2=768169&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
Fri Apr 24 06:36:03 2009
>> @@ -58,13 +58,13 @@
>>   * @see Hashtable
>>   * @see java.lang.System#getProperties
>>   */
>> -public class Properties extends Hashtable<Object,Object> {
>> -	
>> -	private static final long serialVersionUID = 4112578634029874840L;
>> +public class Properties extends Hashtable<Object, Object> {
>> +
>> +    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";
>> +    private static final String PROP_DTD_NAME = "http://java.sun.com/dtd/properties.dtd";
//$NON-NLS-1$
>>  
>>      private static final String PROP_DTD = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
>>              + "    <!ELEMENT properties (comment?, entry*) >"
>> @@ -72,203 +72,203 @@
>>              + "    <!ELEMENT comment (#PCDATA) >"
>>              + "    <!ELEMENT entry (#PCDATA) >"
>>              + "    <!ATTLIST entry key CDATA #REQUIRED >";
>> -	
>> -	/**
>> -	 * 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")
>> +    /**
>> +     * 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")
>>      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 <code>key=value</code>, 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 <code>key=value</code>, 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);
>>  
>> -		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
>> @@ -284,18 +284,18 @@
>>                  }
>>                  break;
>>              }
>> -                        nextChar = (char) (intVal & 0xff);
>> +            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) {
>> @@ -303,127 +303,127 @@
>>                      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;
>> -				}
>> -			} else {
>> -				switch (nextChar) {
>> -				case '#':
>> -				case '!':
>> -					if (firstChar) {
>> -						while (true) {
>> -                                                    intVal = bis.read();
>> -                                                    if (intVal == -1) break;
>> -                                                    nextChar = (char) intVal;  
// & 0xff
>> -										// not
>> -										// required
>> -                                                    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) {
>> +                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)
>> +                                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) {
>>                          mode = IGNORE;
>>                      }
>> -					// if key length == 0 or value length == 0
>> -					if (offset == 0 || offset == keyLength || 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;
>> -						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 <code>key=value</code>, one property per line. It may
be not
>> @@ -477,7 +477,8 @@
>>                      }
>>                  } else if (count <= 4) {
>>                      // luni.09=Invalid Unicode sequence: illegal character
>> -                    throw new IllegalArgumentException(Messages.getString("luni.09"));
>> +                    throw new IllegalArgumentException(Messages
>> +                            .getString("luni.09")); //$NON-NLS-1$
>>                  }
>>                  mode = NONE;
>>                  buf[offset++] = (char) unicode;
>> @@ -522,11 +523,13 @@
>>                      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;
>>                              }
>>                          }
>> @@ -538,7 +541,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;
>> @@ -600,32 +603,32 @@
>>              String temp = new String(buf, 0, offset);
>>              put(temp.substring(0, keyLength), temp.substring(keyLength));
>>          }
>> -    }   
>> +    }
>>  
>> -	/**
>> +    /**
>>       * 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<Object, Object> set = new Hashtable<Object, Object>(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.
>> @@ -633,108 +636,109 @@
>>       * @return a set of keys in the property list
>>       * 
>>       * @since 1.6
>> -     */    
>> -    public Set<String> stringPropertyNames(){
>> -        HashSet<String> set = new HashSet<String>();        
>> +     */
>> +    public Set<String> stringPropertyNames() {
>> +        HashSet<String> set = new HashSet<String>();
>>          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) {
>> -		}
>> -	}
>> -
>> -	/**
>> -	 * 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<String>("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) {
>> +            // 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<String>("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); 
>> +        writer.write(lineSeparator);
>> +
>> +        for (Map.Entry<Object, Object> 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();
>> +    }
>>  
>> -		for (Map.Entry<Object, Object> 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
>> @@ -744,11 +748,12 @@
>>       *            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<String>("line.separator"));
//$NON-NLS-1$
>> @@ -757,11 +762,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<Object, Object> entry : entrySet()) {
>>              String key = (String) entry.getKey();
>> @@ -775,23 +780,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;
>> @@ -805,7 +810,7 @@
>>                      throw e;
>>                  }
>>              });
>> -            
>> +
>>              builder.setEntityResolver(new EntityResolver() {
>>                  public InputSource resolveEntity(String publicId,
>>                          String systemId) throws SAXException, IOException {
>> @@ -820,20 +825,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
>> @@ -846,25 +851,25 @@
>>              throw new InvalidPropertiesFormatException(e);
>>          }
>>      }
>> -    
>> +
>>      public void storeToXML(OutputStream os, String comment) throws IOException {
>>          storeToXML(os, comment, "UTF-8");
>>      }
>> -    
>> +
>>      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();
>> @@ -880,17 +885,17 @@
>>  
>>          PrintStream printStream = new PrintStream(os, false,
>>                  encodingCanonicalName);
>> -        
>> +
>>          printStream.print("<?xml version=\"1.0\" encoding=\"");
>>          printStream.print(encodingCanonicalName);
>>          printStream.println("\"?>");
>> -        
>> +
>>          printStream.print("<!DOCTYPE properties SYSTEM \"");
>>          printStream.print(PROP_DTD_NAME);
>>          printStream.println("\">");
>> -        
>> +
>>          printStream.println("<properties>");
>> -        
>> +
>>          if (comment != null) {
>>              printStream.print("<comment>");
>>              printStream.print(substitutePredefinedEntries(comment));
>> @@ -909,9 +914,9 @@
>>          printStream.println("</properties>");
>>          printStream.flush();
>>      }
>> -    
>> +
>>      private String substitutePredefinedEntries(String s) {
>> -        
>> +
>>          /*
>>           * substitution for predefined character entities to use them safely in
>>           * XML
>> @@ -919,5 +924,5 @@
>>          return s.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(
>>                  ">", "&gt;").replaceAll("\u0027", "&apos;").replaceAll("\"",
>>                  "&quot;");
>> -    }	
>> +    }
>>  }
>>
>>
>>
> 


-- 
Best Regards,
Regis.

Mime
View raw message