|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectxv.text.PropertiesReader
public class PropertiesReader
A class designed to allow reading Properties
files using
the format as specified in Properties.load(java.io.Reader)
.
There is one notable difference between the format as implemented by this
class and the one read by the Properties
class. The Properties
class will throw an IllegalArgumentException
if the file
contains an invalid Unicode escape sequence (e.g., "\uxxxx"), while this
class will treat the escape as an escaped 'u'
character and treat the
characters that follow as normal characters.
This means that there are no invalid inputs: all inputs will produce results, although they may not be the intended results.
Generally this class can be used by the following loop:
PropertiesReader propertiesReader = new PropertiesReader(stream); String key; while ((key = propertiesReader.readKey()) != null) { String value = propertiesReader.readValue(); // Use the properties as required }
Constructor Summary | |
---|---|
PropertiesReader(InputStream stream)
Loads the given property stream using the ISO 8859-1 character encoding, which is the official property stream encoding. |
|
PropertiesReader(Reader reader)
Loads the given property stream as characters from the given reader. |
|
PropertiesReader(URL url)
Creates a new properties reader using the given URL. |
Method Summary | |
---|---|
static boolean |
isWhitespace(int c)
Determines if the given character is a whitespace character according to the .properties spec and not according to Character.isWhitespace(int) . |
static HashMap<String,String> |
loadProperties(InputStream stream)
Utility method for reading properties into a new HashMap . |
static HashMap<String,String> |
loadProperties(PropertiesReader reader)
Utility method for reading properties into a new HashMap . |
static void |
loadProperties(PropertiesReader reader,
Map<? super String,? super String> properties)
Utility method for reading properties into a pre-existing Map . |
static HashMap<String,String> |
loadProperties(Reader reader)
Utility method for reading properties into a new HashMap . |
static HashMap<String,String> |
loadProperties(URL url)
Utility method for reading properties into a new HashMap . |
String |
readKey()
Reads through the stream, finding the next actual key and reading through to the next separator character. |
String |
readValue()
Reads through the stream, finding the next value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PropertiesReader(InputStream stream)
stream
- the stream to read the properties from
NullPointerException
- if stream
is null
public PropertiesReader(URL url) throws IOException
If you always want to use the standard encoding, use new
PropertiesReader(url.openStream())
instead.
url
- the URL to use
IOException
- if an I/O error occurs while connecting to the URL
NullPointerException
- if url
is null
public PropertiesReader(Reader reader)
reader
- the reader to read properties from
NullPointerException
- if reader
is null
Method Detail |
---|
public String readKey() throws IOException
Examples:
Upcoming Characters | Return value | Remaining String |
---|---|---|
" foo=bar" |
"foo" |
"bar" |
" foo:=bar" |
"foo" |
"=bar" |
" foo = bar" |
"foo" |
" bar" |
null
if the end-of-stream is reached
IOException
public String readValue() throws IOException
IOException
public static HashMap<String,String> loadProperties(InputStream stream) throws IOException
HashMap
.
The characters are read in ISO 8859-1 encoding.
stream
- the stream to read the properties from
IOException
- if an I/O exception occurs while reading the propertiespublic static HashMap<String,String> loadProperties(Reader reader) throws IOException
HashMap
.
reader
- the reader to read the properties from
IOException
- if an I/O exception occurs while reading the propertiespublic static HashMap<String,String> loadProperties(URL url) throws IOException
HashMap
.
url
- the URL to load properties from
IOException
- if an I/O exception occurs while reading the propertiespublic static HashMap<String,String> loadProperties(PropertiesReader reader) throws IOException
HashMap
.
reader
- the properties reader to read the properties from
IOException
- if an I/O exception occurs while reading the propertiespublic static void loadProperties(PropertiesReader reader, Map<? super String,? super String> properties) throws IOException
Map
.
reader
- the properties reader to read the properties fromproperties
- the map to place properties into
IOException
- if an I/O exception occurs while reading the propertiespublic static boolean isWhitespace(int c)
Character.isWhitespace(int)
.
c
- the character to check
true
if the character is a whitespace character according
to the .properties spec
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |