|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xins.common.collections.PropertyReaderUtils
Utility functions for dealing with PropertyReader
objects.
PropertyReader
Field Summary | |
static PropertyReader |
EMPTY_PROPERTY_READER
An empty and unmodifiable PropertyReader instance. |
Method Summary | |
static PropertyReader |
createPropertyReader(InputStream in)
Constructs a PropertyReader from the specified input
stream. |
static boolean |
getBooleanProperty(PropertyReader properties,
String propertyName,
boolean fallbackDefault)
Gets the property with the specified name and converts it to a boolean . |
static int |
getIntProperty(PropertyReader properties,
String propertyName)
Gets the property with the specified name and converts it to an int . |
static String |
getRequiredProperty(PropertyReader properties,
String name)
Retrieves the specified property and throws a MissingRequiredPropertyException if it is not set. |
static void |
serialize(PropertyReader properties,
FastStringBuffer buffer,
String valueIfEmpty)
Serializes the specified PropertyReader to a
FastStringBuffer . |
static void |
serialize(PropertyReader properties,
LogdocStringBuffer buffer)
Serializes the specified PropertyReader for Logdoc. |
static LogdocSerializable |
serialize(PropertyReader p,
String valueIfEmpty)
Constructs a LogdocSerializable for the specified
PropertyReader . |
static LogdocSerializable |
serialize(PropertyReader p,
String valueIfEmpty,
String prefixIfNotEmpty,
String suffix)
Constructs a LogdocSerializable for the specified
PropertyReader . |
static String |
toString(PropertyReader properties,
String valueIfEmpty)
Serializes the specified PropertyReader to a
String . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final PropertyReader EMPTY_PROPERTY_READER
PropertyReader
instance. This
field is not null
.
Method Detail |
public static boolean getBooleanProperty(PropertyReader properties, String propertyName, boolean fallbackDefault) throws IllegalArgumentException, InvalidPropertyValueException
boolean
.
properties
- the set of properties to read from, cannot be null
.propertyName
- the name of the property to read, cannot be null
.fallbackDefault
- the fallback default value, returned if the value of the property is
either null
or ""
(an empty string).
IllegalArgumentException
- if properties == null || propertyName == null
.
InvalidPropertyValueException
- if the value of the property is neither null
nor
""
(an empty string), nor "true"
nor
"false"
.public static int getIntProperty(PropertyReader properties, String propertyName) throws IllegalArgumentException, MissingRequiredPropertyException, InvalidPropertyValueException
int
.
properties
- the set of properties to read from, cannot be null
.propertyName
- the name of the property to read, cannot be null
.
int
.
IllegalArgumentException
- if properties == null || propertyName == null
.
MissingRequiredPropertyException
- if the specified property is not set, or if it is set to an empty
string.
InvalidPropertyValueException
- if the conversion to an int
failed.public static String getRequiredProperty(PropertyReader properties, String name) throws IllegalArgumentException, MissingRequiredPropertyException
MissingRequiredPropertyException
if it is not set.
properties
- the set of properties to retrieve a specific proeprty from, cannot be
null
.name
- the name of the property, cannot be null
.
null
and
guaranteed to contain at least one character.
IllegalArgumentException
- if properties == null || name == null
.
MissingRequiredPropertyException
- if the value of the property is either null
or an empty
string.public static PropertyReader createPropertyReader(InputStream in) throws IllegalArgumentException, IOException
PropertyReader
from the specified input
stream.
The parsing done is similar to the parsing done by the
Properties.load(InputStream)
method. Empty values will be
ignored.
in
- the input stream to read from, cannot be null
.
PropertyReader
instance that contains all the properties
defined in the specified input stream.
IllegalArgumentException
- if in == null
.
IOException
- if there was an I/O error while reading from the stream.public static void serialize(PropertyReader properties, LogdocStringBuffer buffer) throws IllegalArgumentException
PropertyReader
for Logdoc. For
each entry, both the key and the value are encoded using the URL
encoding (see URLEncoding
).
The key and value are separated by a literal equals sign
('='
). The entries are separated using an ampersand
('&'
).
If the value for an entry is either null
or an empty
string (""
), then nothing is added to the buffer for that
entry.
properties
- the PropertyReader
to serialize, cannot be null
.buffer
- the buffer to write the serialized data to, cannot be
null
.
IllegalArgumentException
- if properties == null || buffer == null
.public static void serialize(PropertyReader properties, FastStringBuffer buffer, String valueIfEmpty) throws IllegalArgumentException
PropertyReader
to a
FastStringBuffer
. For each entry, both the key and the
value are encoded using the URL encoding (see URLEncoding
).
The key and value are separated by a literal equals sign
('='
). The entries are separated using
an ampersand ('&'
).
If the value for an entry is either null
or an empty
string (""
), then nothing is added to the buffer for that
entry.
properties
- the PropertyReader
to serialize, can be null
.buffer
- the buffer to write the serialized data to, cannot be
null
.valueIfEmpty
- the string to append to the buffer in case
properties == null || properties.size() == 0
; if this
argument is null
, however, then nothing will be appended
in the mentioned case.
IllegalArgumentException
- if properties == null || buffer == null
.public static LogdocSerializable serialize(PropertyReader p, String valueIfEmpty)
LogdocSerializable
for the specified
PropertyReader
.
p
- the PropertyReader
to construct a LogdocSerializable
for, or null
.valueIfEmpty
- the value to return if the specified set of properties is either
null
or empty, can be null
.
LogdocSerializable
, never null
.public static LogdocSerializable serialize(PropertyReader p, String valueIfEmpty, String prefixIfNotEmpty, String suffix)
LogdocSerializable
for the specified
PropertyReader
.
p
- the PropertyReader
to construct a LogdocSerializable
for, or null
.valueIfEmpty
- the value to return if the specified set of properties is either
null
or empty, can be null
.prefixIfNotEmpty
- the prefix to add to the value if the PropertyReader
is not empty, can be null
.suffix
- the suffix to add to the value, can be null
. The suffix
will be added even if the PropertyReaderis empty.
LogdocSerializable
, never null
.public static String toString(PropertyReader properties, String valueIfEmpty)
PropertyReader
to a
String
. For each entry, both the key and the
value are encoded using the URL encoding (see URLEncoding
).
The key and value are separated by a literal equals sign
('='
). The entries are separated using
an ampersand ('&'
).
If the value for an entry is either null
or an empty
string (""
), then nothing is added to the buffer for that
entry.
properties
- the PropertyReader
to serialize, can be null
.valueIfEmpty
- the string to append to the buffer in case
properties == null || properties.size() == 0
; if this
argument is null
, however, then nothing will be appended
in the mentioned case..
null
.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |