public final class PropertyReaderUtils extends Object
PropertyReader
objects.PropertyReader
Modifier and Type | Field and Description |
---|---|
static PropertyReader |
EMPTY_PROPERTY_READER
Deprecated.
An empty and unmodifiable
PropertyReader instance. |
Modifier and Type | Method and Description |
---|---|
static PropertyReader |
createPropertyReader(InputStream in)
Deprecated.
Constructs a
PropertyReader from the specified input
stream. |
static boolean |
equals(PropertyReader pr,
Object toCompare)
Deprecated.
Compares a
PropertyReader instance with another object for
equality. |
static boolean |
getBooleanProperty(PropertyReader properties,
String propertyName,
boolean fallbackDefault)
Deprecated.
Gets the property with the specified name and converts it to a
boolean . |
static int |
getIntProperty(PropertyReader properties,
String propertyName)
Deprecated.
Gets the property with the specified name and converts it to an
int . |
static String |
getRequiredProperty(PropertyReader properties,
String name)
Deprecated.
Retrieves the specified property and throws a
MissingRequiredPropertyException if it is not set. |
String |
getWithDefault(PropertyReader properties,
String key,
String fallbackValue)
Deprecated.
Retrieves a property with the specified name, falling back to a default
value if the property is not set.
|
static int |
hashCode(PropertyReader pr)
Deprecated.
Computes a hash code value for the specified
PropertyReader
object. |
static void |
serialize(PropertyReader properties,
FastStringBuffer buffer,
String valueIfEmpty)
Deprecated.
since XINS 2.0, use
toString(PropertyReader, String) |
static String |
toString(PropertyReader properties)
Deprecated.
Returns the String representation of the specified
PropertyReader . |
static String |
toString(PropertyReader properties,
String valueIfEmpty)
Deprecated.
Serializes the specified
PropertyReader to a
String . |
static String |
toString(PropertyReader properties,
String valueIfEmpty,
String prefixIfNotEmpty,
String suffix)
Deprecated.
Returns the
String representation for the specified
PropertyReader . |
static String |
toString(PropertyReader properties,
String valueIfEmpty,
String prefixIfNotEmpty,
String suffix,
int maxValueLength)
Deprecated.
Returns the
String representation for the specified
PropertyReader . |
public static final PropertyReader EMPTY_PROPERTY_READER
PropertyReader
instance. This
field is not null
.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 String getWithDefault(PropertyReader properties, String key, String fallbackValue) throws IllegalArgumentException
properties
- the set of properties to retrieve a property from,
cannot be null
.key
- the property key,
cannot be null
.fallbackValue
- the fallback default value, returned in case the property is not set
in properties
, cannot be null
.IllegalArgumentException
- if properties == null || key == null || fallbackValue == null
.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, FastStringBuffer buffer, String valueIfEmpty) throws IllegalArgumentException
toString(PropertyReader, String)
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 String toString(PropertyReader properties)
PropertyReader
.
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 String for that
entry.
properties
- the PropertyReader
to serialize, cannot be null
.PropertyReader
.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 String 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
.null
.
If all parameters are null
then an empty String is returned.public static String toString(PropertyReader properties, String valueIfEmpty, String prefixIfNotEmpty, String suffix)
String
representation for the specified
PropertyReader
.properties
- the PropertyReader
to construct a String 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.null
.
If all parameters are null
then an empty String is returned.public static String toString(PropertyReader properties, String valueIfEmpty, String prefixIfNotEmpty, String suffix, int maxValueLength)
String
representation for the specified
PropertyReader
.properties
- the PropertyReader
to construct a String 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.maxValueLength
- the maximum of characters to set for the value, if the value is longer
than this limit '...' will be added after the limit.
If the value is -1, no limit will be set.null
.
If all parameters are null
then an empty String is returned.public static final boolean equals(PropertyReader pr, Object toCompare)
PropertyReader
instance with another object for
equality.pr
- the PropertyReader
, can be null
.toCompare
- the object to compare the PropertyReader
with,
can be null
.true
if the objects are considered to be equal,
false
if they are considered different.public static final int hashCode(PropertyReader pr) throws NullPointerException
PropertyReader
object.pr
- the PropertyReader
instance to compute a hash code value
for, cannot be null
.NullPointerException
- if pr == null
.See http://www.xins.org/.