Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----java.util.Dictionary | +----java.util.Hashtable | +----java.util.Properties
Properties
class represents a persistent set of
properties. The Properties
can be saved to a stream
or loaded from a stream. Each key and its corresponding value in
the property list is a string.
A property list can contain another property list as its "defaults"; this second property list is searched if the property key is not found in the original property list.
Field Summary | |
Properties | defaults
|
Constructor Summary | |
Properties()
|
|
Properties(Properties defaults)
|
Method Summary | |
String | getProperty(String key)
|
String | getProperty(String key,
String defaultValue)
|
void | list(PrintStream out)
|
void | list(PrintWriter out)
|
void | load(InputStream inStream)
|
Enumeration | propertyNames()
|
Object | put(Object key,
Object value)
key to the specified
value in this Properties set.
|
void | save(OutputStream out,
String header)
Properties table to the output stream in a format suitable
for loading into a Properties table using the
load method.
|
Object | setProperty(String key,
String value)
put .
|
Methods inherited from class java.util.Hashtable |
clear, clone, contains, containsKey, containsValue, elements, entries, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values |
Methods inherited from class java.util.Dictionary |
elements, get, isEmpty, keys, put, remove, size |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Properties defaults
Constructor Detail |
public Properties()
public Properties(Properties defaults)
defaults
- the defaults.
Method Detail |
public Object setProperty(String key, String value)
put
. Provided for
parallelism with the getProperties method. Enforces use of
strings for property keys and values.public Object put(Object key, Object value)
key
to the specified
value
in this Properties set. Neither the key nor the
value can be null
.
key
- the Properties key.
value
- the value.
null
if it did not have one.null
public void load(InputStream inStream) throws IOException
Every property occupies one line of the input stream. Each line
is terminated by a line terminator (\n
or \r
or \r\n
). Lines from the input stream are processed until
end of file is reached on the input stream.
A line that contains only whitespace or whose first non-whitespace
character is an ASCII #
or !
is ignored
(thus, #
or !
indicate comment lines).
Every line other than a blank line or a comment line describes one
property to be added to the table (except that if a line ends with \,
then the following line, if it exists, is treated as a continuation
line, as described
below). The key consists of all the characters in the line starting
with the first non-whitespace character and up to, but not including,
the first ASCII =
, :
, or whitespace
character. All of the key termination characters may be included in
the key by preceding them with a \.
Any whitespace after the key is skipped; if the first non-whitespace
character after the key is =
or :
, then it
is ignored and any whitespace characters after it are also skipped.
All remaining characters on the line become part of the associated
element string. Within the element string, the ASCII
escape sequences \t
, \n
,
\r
, \\
, \"
, \'
,
\
(a backslash and a space), and
\\u
xxxx are recognized and converted to single
characters. Moreover, if the last character on the line is
\
, then the next line is treated as a continuation of the
current line; the \
and line terminator are simply
discarded, and any leading whitespace characters on the continuation
line are also discarded and are not part of the element string.
As an example, each of the following four lines specifies the key
"Truth"
and the associated element value
"Beauty"
:
Truth = Beauty Truth:Beauty Truth :BeautyAs another example, the following three lines specify a single property:
fruits apple, banana, pear, \ cantaloupe, watermelon, \ kiwi, mangoThe key is
"fruits"
and the associated element is:
"apple, banana, pear, cantaloupe, watermelon,kiwi, mango"Note that a space appears before each
\
so that a space
will appear after each comma in the final result; the \
,
line terminator, and leading whitespace on the continuation line are
merely discarded and are not replaced by one or more other
characters.
As a third example, the line:
cheesesspecifies that the key is
"cheeses"
and the associated
element is the empty string.
in
- the input stream.
public void save(OutputStream out, String header)
Properties
table to the output stream in a format suitable
for loading into a Properties
table using the
load
method.
Properties from the defaults table of this Properties
table (if any) are not written out by this method.
If the header argument is not null, then an ASCII #
character, the header string, and a newline are first written to the
output stream. Thus, the header
can serve as an
identifying comment.
Next, a comment line is always written, consisting of an ASCII
#
character, the current date and time (as if produced
by the toString
method of Date
for the
current time), and a newline.
Then every entry in this Properties
table is written out,
one per line. For each entry the key string is written, then an ASCII
=
, then the associated element string. Each character of
the element string is examined to see whether it should be rendered as
an escape sequence. The ASCII characters \
, tab, newline,
and carriage return are written as \\
, \t
,
\n
, and \r
, respectively. Characters less
than
and characters greater than
~
are written as \\u
xxxx for
the appropriate hexadecimal value xxxx. Space characters, but
not embedded or trailing space characters, are written with a preceding
\
. The key and value characters #
,
!
, =
, and :
are written with a
preceding slash to ensure that they are properly loaded.
After the entries have been written, the output stream is flushed. The output stream remains open after this method returns.
out
- an output stream.
header
- a description of the property list.
public String getProperty(String key)
null
if the property is not found.
key
- the property key.
public String getProperty(String key, String defaultValue)
key
- the hashtable key.
defaultValue
- a default value.
public Enumeration propertyNames()
public void list(PrintStream out)
out
- an output stream.
public void list(PrintWriter out)
out
- an output stream.
Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |