jdk/src/share/classes/java/util/Properties.java
author mchung
Wed, 14 Sep 2011 08:33:34 -0700
changeset 10587 654c00a794b6
parent 9266 121fb370f179
child 11676 7e75ec031b97
permissions -rw-r--r--
6915797: Remove sun.tools.jar.JarImageSource that is not used 7090178: Move java.util.XMLUtils to another package to avoid split package Reviewed-by: alanb, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6882
diff changeset
     2
 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3705
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3705
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3705
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3705
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3705
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.PrintWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.Writer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.OutputStreamWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.BufferedWriter;
10587
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
    37
import java.lang.reflect.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The <code>Properties</code> class represents a persistent set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * properties. The <code>Properties</code> can be saved to a stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * or loaded from a stream. Each key and its corresponding value in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the property list is a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * A property list can contain another property list as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * "defaults"; this second property list is searched if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the property key is not found in the original property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Because <code>Properties</code> inherits from <code>Hashtable</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <code>put</code> and <code>putAll</code> methods can be applied to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>Properties</code> object.  Their use is strongly discouraged as they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * allow the caller to insert entries whose keys or values are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <code>Strings</code>.  The <code>setProperty</code> method should be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * instead.  If the <code>store</code> or <code>save</code> method is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * on a "compromised" <code>Properties</code> object that contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * non-<code>String</code> key or value, the call will fail. Similarly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * the call to the <code>propertyNames</code> or <code>list</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * will fail if it is called on a "compromised" <code>Properties</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * object that contains a non-<code>String</code> key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * The {@link #load(java.io.Reader) load(Reader)} <tt>/</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * {@link #store(java.io.Writer, java.lang.String) store(Writer, String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * methods load and store properties from and to a character based stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * in a simple line-oriented format specified below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * The {@link #load(java.io.InputStream) load(InputStream)} <tt>/</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * {@link #store(java.io.OutputStream, java.lang.String) store(OutputStream, String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * methods work the same way as the load(Reader)/store(Writer, String) pair, except
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * the input/output stream is encoded in ISO 8859-1 character encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Characters that cannot be directly represented in this encoding can be written using
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
    72
 * Unicode escapes as defined in section 3.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
    73
 * <cite>The Java&trade; Language Specification</cite>;
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
    74
 * only a single 'u' character is allowed in an escape
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * sequence. The native2ascii tool can be used to convert property files to and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * from other character encodings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p> The {@link #loadFromXML(InputStream)} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * #storeToXML(OutputStream, String, String)} methods load and store properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * in a simple XML format.  By default the UTF-8 character encoding is used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * however a specific encoding may be specified if required.  An XML properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * document has the following DOCTYPE declaration:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * &lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Note that the system URI (http://java.sun.com/dtd/properties.dtd) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <i>not</i> accessed when exporting or importing properties; it merely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * serves as a string to uniquely identify the DTD, which is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *    &lt;!-- DTD for properties --&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *    &lt;!ELEMENT properties ( comment?, entry* ) &gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *    &lt;!ATTLIST properties version CDATA #FIXED "1.0"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *    &lt;!ELEMENT comment (#PCDATA) &gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *    &lt;!ELEMENT entry (#PCDATA) &gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *    &lt;!ATTLIST entry key CDATA #REQUIRED&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
3705
6d494ca143b8 6875861: javadoc build warning on java.util.Properites from unconventional @see ordering
darcy
parents: 2
diff changeset
   106
 * <p>This class is thread-safe: multiple threads can share a single
6d494ca143b8 6875861: javadoc build warning on java.util.Properites from unconventional @see ordering
darcy
parents: 2
diff changeset
   107
 * <tt>Properties</tt> object without the need for external synchronization.
6d494ca143b8 6875861: javadoc build warning on java.util.Properites from unconventional @see ordering
darcy
parents: 2
diff changeset
   108
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * @see <a href="../../../technotes/tools/solaris/native2ascii.html">native2ascii tool for Solaris</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * @see <a href="../../../technotes/tools/windows/native2ascii.html">native2ascii tool for Windows</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * @author  Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * @author  Michael McCloskey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * @author  Xueming Shen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
class Properties extends Hashtable<Object,Object> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * use serialVersionUID from JDK 1.1.X for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     private static final long serialVersionUID = 4112578634029874840L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * A property list that contains default values for any keys not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * found in this property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected Properties defaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Creates an empty property list with no default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public Properties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Creates an empty property list with the specified defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param   defaults   the defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public Properties(Properties defaults) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        this.defaults = defaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Calls the <tt>Hashtable</tt> method <code>put</code>. Provided for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * parallelism with the <tt>getProperty</tt> method. Enforces use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * strings for property keys and values. The value returned is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * result of the <tt>Hashtable</tt> call to <code>put</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param key the key to be placed into this property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param value the value corresponding to <tt>key</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @return     the previous value of the specified key in this property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *             list, or <code>null</code> if it did not have one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @see #getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @since    1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public synchronized Object setProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Reads a property list (key and element pairs) from the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * character stream in a simple line-oriented format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Properties are processed in terms of lines. There are two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * kinds of line, <i>natural lines</i> and <i>logical lines</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * A natural line is defined as a line of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * characters that is terminated either by a set of line terminator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * characters (<code>\n</code> or <code>\r</code> or <code>\r\n</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * or by the end of the stream. A natural line may be either a blank line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * a comment line, or hold all or some of a key-element pair. A logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * line holds all the data of a key-element pair, which may be spread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * out across several adjacent natural lines by escaping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * the line terminator sequence with a backslash character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <code>\</code>.  Note that a comment line cannot be extended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * in this manner; every natural line that is a comment must have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * its own comment indicator, as described below. Lines are read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * input until the end of the stream is reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * A natural line that contains only white space characters is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * considered blank and is ignored.  A comment line has an ASCII
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <code>'#'</code> or <code>'!'</code> as its first non-white
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * space character; comment lines are also ignored and do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * encode key-element information.  In addition to line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * terminators, this format considers the characters space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * (<code>' '</code>, <code>'&#92;u0020'</code>), tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * (<code>'\t'</code>, <code>'&#92;u0009'</code>), and form feed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * (<code>'\f'</code>, <code>'&#92;u000C'</code>) to be white
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * If a logical line is spread across several natural lines, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * backslash escaping the line terminator sequence, the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * terminator sequence, and any white space at the start of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * following line have no affect on the key or element values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * The remainder of the discussion of key and element parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * (when loading) will assume all the characters constituting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * the key and element appear on a single natural line after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * line continuation characters have been removed.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * it is <i>not</i> sufficient to only examine the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * preceding a line terminator sequence to decide if the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * terminator is escaped; there must be an odd number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * contiguous backslashes for the line terminator to be escaped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Since the input is processed from left to right, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * non-zero even number of 2<i>n</i> contiguous backslashes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * before a line terminator (or elsewhere) encodes <i>n</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * backslashes after escape processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * The key contains all of the characters in the line starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * with the first non-white space character and up to, but not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * including, the first unescaped <code>'='</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <code>':'</code>, or white space character other than a line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * terminator. All of these key termination characters may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * included in the key by escaping them with a preceding backslash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * character; for example,<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <code>\:\=</code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * would be the two-character key <code>":="</code>.  Line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * terminator characters can be included using <code>\r</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <code>\n</code> escape sequences.  Any white space after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * key is skipped; if the first non-white space character after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * the key is <code>'='</code> or <code>':'</code>, then it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * ignored and any white space characters after it are also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * skipped.  All remaining characters on the line become part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * the associated element string; if there are no remaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * characters, the element is the empty string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <code>&quot;&quot;</code>.  Once the raw character sequences
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * constituting the key and element are identified, escape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * processing is performed as described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * As an example, each of the following three lines specifies the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <code>"Truth"</code> and the associated element value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <code>"Beauty"</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Truth = Beauty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *  Truth:Beauty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Truth                    :Beauty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * As another example, the following three lines specify a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * property:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * fruits                           apple, banana, pear, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *                                  cantaloupe, watermelon, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *                                  kiwi, mango
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * The key is <code>"fruits"</code> and the associated element is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * <pre>"apple, banana, pear, cantaloupe, watermelon, kiwi, mango"</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Note that a space appears before each <code>\</code> so that a space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * will appear after each comma in the final result; the <code>\</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * line terminator, and leading white space on the continuation line are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * merely discarded and are <i>not</i> replaced by one or more other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * As a third example, the line:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <pre>cheeses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * specifies that the key is <code>"cheeses"</code> and the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * element is the empty string <code>""</code>.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <a name="unicodeescapes"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Characters in keys and elements can be represented in escape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * sequences similar to those used for character and string literals
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   277
     * (see sections 3.3 and 3.10.6 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   278
     * <cite>The Java&trade; Language Specification</cite>).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * The differences from the character escape sequences and Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * escapes used for characters and strings are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <li> Octal escapes are not recognized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * <li> The character sequence <code>\b</code> does <i>not</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * represent a backspace character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * <li> The method does not treat a backslash character,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <code>\</code>, before a non-valid escape character as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * error; the backslash is silently dropped.  For example, in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Java string the sequence <code>"\z"</code> would cause a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * compile time error.  In contrast, this method silently drops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * the backslash.  Therefore, this method treats the two character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * sequence <code>"\b"</code> as equivalent to the single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * character <code>'b'</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * <li> Escapes are not necessary for single and double quotes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * however, by the rule above, single and double quote characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * preceded by a backslash still yield single and double quote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * characters, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <li> Only a single 'u' character is allowed in a Uniocde escape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * The specified stream remains open after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @param   reader   the input character stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @throws  IOException  if an error occurred when reading from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *          input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @throws  IllegalArgumentException if a malformed Unicode escape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *          appears in the input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public synchronized void load(Reader reader) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        load0(new LineReader(reader));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Reads a property list (key and element pairs) from the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * byte stream. The input stream is in a simple line-oriented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * format as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * {@link #load(java.io.Reader) load(Reader)} and is assumed to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * the ISO 8859-1 character encoding; that is each byte is one Latin1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * character. Characters not in Latin1, and certain special characters,
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   328
     * are represented in keys and elements using Unicode escapes as defined in
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   329
     * section 3.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   330
     * <cite>The Java&trade; Language Specification</cite>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * The specified stream remains open after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param      inStream   the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @exception  IOException  if an error occurred when reading from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *             input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @throws     IllegalArgumentException if the input stream contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *             malformed Unicode escape sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public synchronized void load(InputStream inStream) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        load0(new LineReader(inStream));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private void load0 (LineReader lr) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        char[] convtBuf = new char[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        int limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        int keyLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        int valueStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        char c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        boolean hasSep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        boolean precedingBackslash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        while ((limit = lr.readLine()) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            c = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            keyLen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            valueStart = limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            hasSep = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            //System.out.println("line=<" + new String(lineBuf, 0, limit) + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            precedingBackslash = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            while (keyLen < limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                c = lr.lineBuf[keyLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                //need check if escaped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                if ((c == '=' ||  c == ':') && !precedingBackslash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    valueStart = keyLen + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    hasSep = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                } else if ((c == ' ' || c == '\t' ||  c == '\f') && !precedingBackslash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    valueStart = keyLen + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                if (c == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    precedingBackslash = !precedingBackslash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    precedingBackslash = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                keyLen++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            while (valueStart < limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                c = lr.lineBuf[valueStart];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                if (c != ' ' && c != '\t' &&  c != '\f') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    if (!hasSep && (c == '=' ||  c == ':')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                        hasSep = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                valueStart++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            String value = loadConvert(lr.lineBuf, valueStart, limit - valueStart, convtBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /* Read in a "logical line" from an InputStream/Reader, skip all comment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * and blank lines and filter out those leading whitespace characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * (\u0020, \u0009 and \u000c) from the beginning of a "natural line".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Method returns the char length of the "logical line" and stores
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * the line in "lineBuf".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    class LineReader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        public LineReader(InputStream inStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            this.inStream = inStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            inByteBuf = new byte[8192];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        public LineReader(Reader reader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            this.reader = reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            inCharBuf = new char[8192];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        byte[] inByteBuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        char[] inCharBuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        char[] lineBuf = new char[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        int inLimit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        int inOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        InputStream inStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        Reader reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        int readLine() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            int len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            char c = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            boolean skipWhiteSpace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            boolean isCommentLine = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            boolean isNewLine = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            boolean appendedLineBegin = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            boolean precedingBackslash = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            boolean skipLF = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                if (inOff >= inLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    inLimit = (inStream==null)?reader.read(inCharBuf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                              :inStream.read(inByteBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    inOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    if (inLimit <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                        if (len == 0 || isCommentLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (inStream != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    //The line below is equivalent to calling a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    //ISO8859-1 decoder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    c = (char) (0xff & inByteBuf[inOff++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    c = inCharBuf[inOff++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                if (skipLF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    skipLF = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    if (c == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                if (skipWhiteSpace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    if (c == ' ' || c == '\t' || c == '\f') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    if (!appendedLineBegin && (c == '\r' || c == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    skipWhiteSpace = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    appendedLineBegin = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                if (isNewLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    isNewLine = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    if (c == '#' || c == '!') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        isCommentLine = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                if (c != '\n' && c != '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    lineBuf[len++] = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    if (len == lineBuf.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        int newLength = lineBuf.length * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        if (newLength < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                            newLength = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                        char[] buf = new char[newLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                        System.arraycopy(lineBuf, 0, buf, 0, lineBuf.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        lineBuf = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    //flip the preceding backslash flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    if (c == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                        precedingBackslash = !precedingBackslash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                        precedingBackslash = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    // reached EOL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    if (isCommentLine || len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                        isCommentLine = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        isNewLine = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                        skipWhiteSpace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                        len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                    if (inOff >= inLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                        inLimit = (inStream==null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                  ?reader.read(inCharBuf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                  :inStream.read(inByteBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                        inOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                        if (inLimit <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                            return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    if (precedingBackslash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                        len -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                        //skip the leading whitespace characters in following line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        skipWhiteSpace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        appendedLineBegin = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                        precedingBackslash = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                        if (c == '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                            skipLF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                        return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * Converts encoded &#92;uxxxx to unicode chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * and changes special saved chars to their original forms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    private String loadConvert (char[] in, int off, int len, char[] convtBuf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        if (convtBuf.length < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            int newLen = len * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            if (newLen < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                newLen = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            convtBuf = new char[newLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        char aChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        char[] out = convtBuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        int outLen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        int end = off + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        while (off < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            aChar = in[off++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            if (aChar == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                aChar = in[off++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                if(aChar == 'u') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    // Read the xxxx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    int value=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    for (int i=0; i<4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        aChar = in[off++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        switch (aChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                          case '0': case '1': case '2': case '3': case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                          case '5': case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                             value = (value << 4) + aChar - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                          case 'a': case 'b': case 'c':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                          case 'd': case 'e': case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                             value = (value << 4) + 10 + aChar - 'a';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                          case 'A': case 'B': case 'C':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                          case 'D': case 'E': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                             value = (value << 4) + 10 + aChar - 'A';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                              throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                           "Malformed \\uxxxx encoding.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    out[outLen++] = (char)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    if (aChar == 't') aChar = '\t';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    else if (aChar == 'r') aChar = '\r';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    else if (aChar == 'n') aChar = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                    else if (aChar == 'f') aChar = '\f';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    out[outLen++] = aChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                out[outLen++] = aChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        return new String (out, 0, outLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * Converts unicodes to encoded &#92;uxxxx and escapes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * special characters with a preceding slash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    private String saveConvert(String theString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                               boolean escapeSpace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                               boolean escapeUnicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        int len = theString.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        int bufLen = len * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if (bufLen < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            bufLen = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        StringBuffer outBuffer = new StringBuffer(bufLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        for(int x=0; x<len; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            char aChar = theString.charAt(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            // Handle common case first, selecting largest block that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            // avoids the specials below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if ((aChar > 61) && (aChar < 127)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                if (aChar == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    outBuffer.append('\\'); outBuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                outBuffer.append(aChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            switch(aChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    if (x == 0 || escapeSpace)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                        outBuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    outBuffer.append(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                case '\t':outBuffer.append('\\'); outBuffer.append('t');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                case '\n':outBuffer.append('\\'); outBuffer.append('n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                case '\r':outBuffer.append('\\'); outBuffer.append('r');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                case '\f':outBuffer.append('\\'); outBuffer.append('f');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                case '=': // Fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                case ':': // Fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                case '#': // Fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                case '!':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    outBuffer.append('\\'); outBuffer.append(aChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                    if (((aChar < 0x0020) || (aChar > 0x007e)) & escapeUnicode ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                        outBuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                        outBuffer.append('u');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                        outBuffer.append(toHex((aChar >> 12) & 0xF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                        outBuffer.append(toHex((aChar >>  8) & 0xF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                        outBuffer.append(toHex((aChar >>  4) & 0xF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                        outBuffer.append(toHex( aChar        & 0xF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                        outBuffer.append(aChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        return outBuffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    private static void writeComments(BufferedWriter bw, String comments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        bw.write("#");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        int len = comments.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        int current = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        int last = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        char[] uu = new char[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        uu[0] = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        uu[1] = 'u';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        while (current < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            char c = comments.charAt(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            if (c > '\u00ff' || c == '\n' || c == '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                if (last != current)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                    bw.write(comments.substring(last, current));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                if (c > '\u00ff') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                    uu[2] = toHex((c >> 12) & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    uu[3] = toHex((c >>  8) & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    uu[4] = toHex((c >>  4) & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                    uu[5] = toHex( c        & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    bw.write(new String(uu));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    bw.newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    if (c == '\r' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                        current != len - 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                        comments.charAt(current + 1) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                        current++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    if (current == len - 1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                        (comments.charAt(current + 1) != '#' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                        comments.charAt(current + 1) != '!'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                        bw.write("#");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                last = current + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            current++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        if (last != current)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            bw.write(comments.substring(last, current));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        bw.newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * Calls the <code>store(OutputStream out, String comments)</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * and suppresses IOExceptions that were thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @deprecated This method does not throw an IOException if an I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * occurs while saving the property list.  The preferred way to save a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * properties list is via the <code>store(OutputStream out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * String comments)</code> method or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * <code>storeToXML(OutputStream os, String comment)</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @param   out      an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @param   comments   a description of the property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @exception  ClassCastException  if this <code>Properties</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *             contains any keys or values that are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     *             <code>Strings</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    @Deprecated
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6521
diff changeset
   708
    public void save(OutputStream out, String comments)  {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            store(out, comments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * Writes this property list (key and element pairs) in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * <code>Properties</code> table to the output character stream in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * format suitable for using the {@link #load(java.io.Reader) load(Reader)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Properties from the defaults table of this <code>Properties</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * table (if any) are <i>not</i> written out by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * If the comments argument is not null, then an ASCII <code>#</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * character, the comments string, and a line separator are first written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * to the output stream. Thus, the <code>comments</code> can serve as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * identifying comment. Any one of a line feed ('\n'), a carriage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * return ('\r'), or a carriage return followed immediately by a line feed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * in comments is replaced by a line separator generated by the <code>Writer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * and if the next character in comments is not character <code>#</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * character <code>!</code> then an ASCII <code>#</code> is written out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * after that line separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * Next, a comment line is always written, consisting of an ASCII
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * <code>#</code> character, the current date and time (as if produced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * by the <code>toString</code> method of <code>Date</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * current time), and a line separator as generated by the <code>Writer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * Then every entry in this <code>Properties</code> table is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * written out, one per line. For each entry the key string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * written, then an ASCII <code>=</code>, then the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * element string. For the key, all space characters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * written with a preceding <code>\</code> character.  For the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * element, leading space characters, but not embedded or trailing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * space characters, are written with a preceding <code>\</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * character. The key and element characters <code>#</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * <code>!</code>, <code>=</code>, and <code>:</code> are written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * with a preceding backslash to ensure that they are properly loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * After the entries have been written, the output stream is flushed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * The output stream remains open after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * @param   writer      an output character stream writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * @param   comments   a description of the property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * @exception  IOException if writing this property list to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     *             output stream throws an <tt>IOException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * @exception  ClassCastException  if this <code>Properties</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *             contains any keys or values that are not <code>Strings</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @exception  NullPointerException  if <code>writer</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    public void store(Writer writer, String comments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        store0((writer instanceof BufferedWriter)?(BufferedWriter)writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                                                 : new BufferedWriter(writer),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
               comments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
               false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * Writes this property list (key and element pairs) in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * <code>Properties</code> table to the output stream in a format suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * for loading into a <code>Properties</code> table using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * {@link #load(InputStream) load(InputStream)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * Properties from the defaults table of this <code>Properties</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * table (if any) are <i>not</i> written out by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * This method outputs the comments, properties keys and values in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * the same format as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * {@link #store(java.io.Writer, java.lang.String) store(Writer)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * with the following differences:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * <li>The stream is written using the ISO 8859-1 character encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * <li>Characters not in Latin-1 in the comments are written as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * <code>&#92;u</code><i>xxxx</i> for their appropriate unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * hexadecimal value <i>xxxx</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * <li>Characters less than <code>&#92;u0020</code> and characters greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * than <code>&#92;u007E</code> in property keys or values are written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * as <code>&#92;u</code><i>xxxx</i> for the appropriate hexadecimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * value <i>xxxx</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * After the entries have been written, the output stream is flushed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * The output stream remains open after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @param   out      an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @param   comments   a description of the property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @exception  IOException if writing this property list to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     *             output stream throws an <tt>IOException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * @exception  ClassCastException  if this <code>Properties</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     *             contains any keys or values that are not <code>Strings</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * @exception  NullPointerException  if <code>out</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    public void store(OutputStream out, String comments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
               comments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
               true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    private void store0(BufferedWriter bw, String comments, boolean escUnicode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        if (comments != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            writeComments(bw, comments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        bw.write("#" + new Date().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        bw.newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            for (Enumeration e = keys(); e.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                String key = (String)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                String val = (String)get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                key = saveConvert(key, true, escUnicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                /* No need to escape embedded and trailing spaces for value, hence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                 * pass false to flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                val = saveConvert(val, false, escUnicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                bw.write(key + "=" + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                bw.newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        bw.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * Loads all of the properties represented by the XML document on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * specified input stream into this properties table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * <p>The XML document must have the following DOCTYPE declaration:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * &lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * Furthermore, the document must satisfy the properties DTD described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * <p>The specified stream is closed after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @param in the input stream from which to read the XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @throws IOException if reading from the specified input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     *         results in an <tt>IOException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @throws InvalidPropertiesFormatException Data on input stream does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *         constitute a valid XML document with the mandated document type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @throws NullPointerException if <code>in</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @see    #storeToXML(OutputStream, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    public synchronized void loadFromXML(InputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        throws IOException, InvalidPropertiesFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (in == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        XMLUtils.load(this, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * Emits an XML document representing all of the properties contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * in this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * <p> An invocation of this method of the form <tt>props.storeToXML(os,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * comment)</tt> behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * <tt>props.storeToXML(os, comment, "UTF-8");</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * @param os the output stream on which to emit the XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @param comment a description of the property list, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     *        if no comment is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @throws IOException if writing to the specified output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *         results in an <tt>IOException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @throws NullPointerException if <code>os</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @throws ClassCastException  if this <code>Properties</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     *         contains any keys or values that are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     *         <code>Strings</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @see    #loadFromXML(InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     */
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6521
diff changeset
   893
    public void storeToXML(OutputStream os, String comment)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        if (os == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        storeToXML(os, comment, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * Emits an XML document representing all of the properties contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * in this table, using the specified encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * <p>The XML document will have the following DOCTYPE declaration:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * &lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *<p>If the specified comment is <code>null</code> then no comment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * will be stored in the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * <p>The specified stream remains open after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     *
6521
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
   915
     * @param os        the output stream on which to emit the XML document.
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
   916
     * @param comment   a description of the property list, or <code>null</code>
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
   917
     *                  if no comment is desired.
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
   918
     * @param  encoding the name of a supported
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
   919
     *                  <a href="../lang/package-summary.html#charenc">
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
   920
     *                  character encoding</a>
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
   921
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @throws IOException if writing to the specified output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     *         results in an <tt>IOException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @throws NullPointerException if <code>os</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     *         or if <code>encoding</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @throws ClassCastException  if this <code>Properties</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *         contains any keys or values that are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *         <code>Strings</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @see    #loadFromXML(InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     */
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6521
diff changeset
   932
    public void storeToXML(OutputStream os, String comment, String encoding)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if (os == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        XMLUtils.save(this, os, comment, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * Searches for the property with the specified key in this property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * If the key is not found in this property list, the default property list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * and its defaults, recursively, are then checked. The method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * <code>null</code> if the property is not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @param   key   the property key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * @return  the value in this property list with the specified key value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * @see     #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @see     #defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    public String getProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        Object oval = super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        String sval = (oval instanceof String) ? (String)oval : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        return ((sval == null) && (defaults != null)) ? defaults.getProperty(key) : sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * Searches for the property with the specified key in this property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * If the key is not found in this property list, the default property list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * and its defaults, recursively, are then checked. The method returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * default value argument if the property is not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @param   key            the hashtable key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @param   defaultValue   a default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * @return  the value in this property list with the specified key value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * @see     #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * @see     #defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    public String getProperty(String key, String defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        String val = getProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        return (val == null) ? defaultValue : val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * Returns an enumeration of all the keys in this property list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * including distinct keys in the default property list if a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * of the same name has not already been found from the main
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * properties list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * @return  an enumeration of all the keys in this property list, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     *          the keys in the default property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @throws  ClassCastException if any key in this property list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     *          is not a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * @see     java.util.Enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @see     java.util.Properties#defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @see     #stringPropertyNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    public Enumeration<?> propertyNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        Hashtable h = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        enumerate(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        return h.keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * Returns a set of keys in this property list where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * the key and its corresponding value are strings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * including distinct keys in the default property list if a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * of the same name has not already been found from the main
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * properties list.  Properties whose key or value is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * of type <tt>String</tt> are omitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * The returned set is not backed by the <tt>Properties</tt> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * Changes to this <tt>Properties</tt> are not reflected in the set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * or vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * @return  a set of keys in this property list where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     *          the key and its corresponding value are strings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     *          including the keys in the default property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * @see     java.util.Properties#defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    public Set<String> stringPropertyNames() {
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 6882
diff changeset
  1014
        Hashtable<String, String> h = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        enumerateStringProperties(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        return h.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * Prints this property list out to the specified output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * This method is useful for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * @param   out   an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * @throws  ClassCastException if any key in this property list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     *          is not a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    public void list(PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        out.println("-- listing properties --");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        Hashtable h = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        enumerate(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        for (Enumeration e = h.keys() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            String key = (String)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            String val = (String)h.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            if (val.length() > 40) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                val = val.substring(0, 37) + "...";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            out.println(key + "=" + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * Prints this property list out to the specified output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * This method is useful for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @param   out   an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * @throws  ClassCastException if any key in this property list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     *          is not a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * Rather than use an anonymous inner class to share common code, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * method is duplicated in order to ensure that a non-1.1 compiler can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * compile this file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    public void list(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        out.println("-- listing properties --");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        Hashtable h = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        enumerate(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        for (Enumeration e = h.keys() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            String key = (String)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            String val = (String)h.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            if (val.length() > 40) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                val = val.substring(0, 37) + "...";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            out.println(key + "=" + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * Enumerates all key/value pairs in the specified hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * @param h the hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * @throws ClassCastException if any of the property keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     *         is not of String type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    private synchronized void enumerate(Hashtable h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        if (defaults != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            defaults.enumerate(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        for (Enumeration e = keys() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            String key = (String)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            h.put(key, get(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * Enumerates all key/value pairs in the specified hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * and omits the property if the key or value is not a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * @param h the hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    private synchronized void enumerateStringProperties(Hashtable<String, String> h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        if (defaults != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            defaults.enumerateStringProperties(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        for (Enumeration e = keys() ; e.hasMoreElements() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            Object k = e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            Object v = get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            if (k instanceof String && v instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                h.put((String) k, (String) v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * Convert a nibble to a hex character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * @param   nibble  the nibble to convert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    private static char toHex(int nibble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        return hexDigit[(nibble & 0xF)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    /** A table of hex digits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    private static final char[] hexDigit = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    };
10587
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1115
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1116
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1117
    private static class XMLUtils {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1118
        private static Method load = null;
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1119
        private static Method save = null;
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1120
        static {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1121
            try {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1122
                // reference sun.util.xml.Utils reflectively
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1123
                // to allow the Properties class be compiled in
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1124
                // the absence of XML
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1125
                Class<?> c = Class.forName("sun.util.xml.XMLUtils", true, null);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1126
                load = c.getMethod("load", Properties.class, InputStream.class);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1127
                save = c.getMethod("save", Properties.class, OutputStream.class,
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1128
                                   String.class, String.class);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1129
            } catch (ClassNotFoundException cnf) {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1130
                throw new AssertionError(cnf);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1131
            } catch (NoSuchMethodException e) {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1132
                throw new AssertionError(e);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1133
            }
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1134
        }
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1135
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1136
        static void invoke(Method m, Object... args) throws IOException {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1137
            try {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1138
                m.invoke(null, args);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1139
            } catch (IllegalAccessException e) {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1140
                throw new AssertionError(e);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1141
            } catch (InvocationTargetException e) {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1142
                Throwable t = e.getCause();
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1143
                if (t instanceof RuntimeException)
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1144
                    throw (RuntimeException)t;
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1145
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1146
                if (t instanceof IOException) {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1147
                    throw (IOException)t;
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1148
                } else {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1149
                    throw new AssertionError(t);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1150
                }
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1151
            }
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1152
        }
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1153
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1154
        static void load(Properties props, InputStream in)
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1155
            throws IOException, InvalidPropertiesFormatException
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1156
        {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1157
            if (load == null)
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1158
                throw new InternalError("sun.util.xml.XMLUtils not found");
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1159
            invoke(load, props, in);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1160
        }
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1161
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1162
        static void save(Properties props, OutputStream os, String comment,
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1163
                         String encoding)
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1164
            throws IOException
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1165
        {
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1166
            if (save == null)
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1167
                throw new InternalError("sun.util.xml.XMLUtils not found");
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1168
            invoke(save, props, os, comment, encoding);
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1169
        }
654c00a794b6 6915797: Remove sun.tools.jar.JarImageSource that is not used
mchung
parents: 9266
diff changeset
  1170
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
}