Class TLcyStringPropertiesCodec
- All Implemented Interfaces:
ILcyPropertiesDecoder
,ILcyPropertiesEncoder
This class can encode and decode an ALcyProperties
instance to and from a text
file. When decoding, all values are String
s. During encoding, only
keys that have a String
as their associated value are stored, keys with
other values produce warnings. Note that all simple types (int
, double
,
...) are automatically converted to and from String
s by ALcyProperties
'
putInt
method, putDouble
method etc.
The composite property converter is used to try and transform all properties of the given
ALcyProperties
to String
values. This class can only encode
ALcyProperties
that can be completely converted to String
values.
The file format is almost identical to that of java.util.Properties
. An extra feature
is a property named "includeConfig". During decoding, this property is interpreted as the source
name of another configuration file, which is then read as well. Multiple source names can be
separated by a comma. Another small difference is that spaces at the begin and at the end of a
value are trimmed.
The interpretation of the source and destination names is up to the set
ILcdInputStreamFactory
and ILcdOutputStreamFactory
. By default, they
are interpreted as file names relative to the current working directory. For decoding, file
names relative to the class path are accepted as well.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canDecodeSource
(String aSourceName) Checks whether thisILcyPropertiesDecoder
can decode the specified data source.boolean
canEncode
(ALcyProperties aProperties, String aDestinationName) Returns whether this encoder can export the specified properties to the specified destination.decode
(InputStream aInputStream) Decodes anALcyProperties
from the specifiedInputStream
.Decodes the given source name into anALcyProperties
object.void
decodeSFCT
(InputStream aInputStream, ALcyProperties aPropertiesSFCT, boolean aOverwrite) Decodes anALcyProperties
from the specifiedInputStream
and puts the decoded properties in the specifiedALcyProperties
.void
decodeSFCT
(String aSourceName, ALcyProperties aProperties, boolean aOverwrite) Decodes the given source name into a givenALcyProperties
object.void
encode
(ALcyProperties aProperties, OutputStream aOutputStream) Encodes the givenALcyProperties
to the givenOutputStream
.void
encode
(ALcyProperties aProperties, String aDestinationName) Encodes the givenALcyProperties
into the given destination.Returns theILcdInputStreamFactory
that is used by this decoder.Returns theILcdOutputStreamFactory
that is used by this encoder.void
setInputStreamFactory
(ILcdInputStreamFactory aInputStreamFactory) Sets theILcdInputStreamFactory
to be used by this decoder.void
setOutputStreamFactory
(ILcdOutputStreamFactory aOutputStreamFactory) Sets theILcdOutputStreamFactory
to be used by this encoder.
-
Constructor Details
-
TLcyStringPropertiesCodec
public TLcyStringPropertiesCodec()
-
-
Method Details
-
getCompositePropertyConverter
-
getInputStreamFactory
Returns theILcdInputStreamFactory
that is used by this decoder.- Returns:
- the
ILcdInputStreamFactory
that is used by this decoder.
-
setInputStreamFactory
Sets theILcdInputStreamFactory
to be used by this decoder.- Parameters:
aInputStreamFactory
- theILcdInputStreamFactory
to be used by this decoder, must not benull
.
-
getOutputStreamFactory
Returns theILcdOutputStreamFactory
that is used by this encoder.- Returns:
- the
ILcdOutputStreamFactory
that is used by this encoder.
-
setOutputStreamFactory
Sets theILcdOutputStreamFactory
to be used by this encoder.- Parameters:
aOutputStreamFactory
- TheILcdOutputStreamFactory
to be used by this encoder, must not benull
.
-
canDecodeSource
Description copied from interface:ILcyPropertiesDecoder
Checks whether this
ILcyPropertiesDecoder
can decode the specified data source.Often this will only be a simple test, for example checking the file extension of a file.
- Specified by:
canDecodeSource
in interfaceILcyPropertiesDecoder
- Parameters:
aSourceName
- the data source to be verified; typically a file name or a URL.- Returns:
true
if this decoder can decode the data specified by the source name,false
otherwise.- See Also:
-
decode
Decodes the given source name into an
ALcyProperties
object.Will decode the properties found in the specified source name. As the last step in the decoding this decoder asks its property converter to convert the read
String
properties toObject
properties. It is up to the property converter to decide which properties are converted.- Specified by:
decode
in interfaceILcyPropertiesDecoder
- Parameters:
aSourceName
- The source name to decode from. Must not benull
.- Returns:
- The decoded
ALcyProperties
. Nevernull
. - Throws:
IOException
- In case of IO failure.
-
decode
Decodes an
ALcyProperties
from the specifiedInputStream
.- Parameters:
aInputStream
- TheInputStream
to decode from.- Returns:
- The decoded
ALcyProperties
. Nevernull
. - Throws:
IOException
- In case of IO failure.- See Also:
-
decodeSFCT
public void decodeSFCT(String aSourceName, ALcyProperties aProperties, boolean aOverwrite) throws IOException Decodes the given source name into a given
ALcyProperties
object.Will decode the properties found in the specified source name and put them in the specified
ALcyProperties
. As the last step in the decoding this decoder asks its property converter to convert the readString
properties toObject
properties. It is up to the property converter to decide which properties are converted.- Specified by:
decodeSFCT
in interfaceILcyPropertiesDecoder
- Parameters:
aSourceName
- The source name to decode from.aProperties
- The properties to load into. Must not benull
.aOverwrite
-true
to overwrite existing properties if they are also present in the given source.false
to leave existing properties unchanged.- Throws:
IOException
- In case of IO failure.
-
decodeSFCT
public void decodeSFCT(InputStream aInputStream, ALcyProperties aPropertiesSFCT, boolean aOverwrite) throws IOException Decodes an
ALcyProperties
from the specifiedInputStream
and puts the decoded properties in the specifiedALcyProperties
.- Parameters:
aInputStream
- TheInputStream
to decode from.aPropertiesSFCT
- TheALcyProperties
in which to put the decoded properties.aOverwrite
-true
to overwrite existing properties if they are also present in the givenInputStream
.false
to leave existing properties unchanged.- Throws:
IOException
- In case of IO failure.- See Also:
-
canEncode
Returns whether this encoder can export the specified properties to the specified destination.
This method will typically check whether the contents of the specified properties are compatible with the format this encoder is written for.
Returns true if the given
ALcyProperties
only containsString
values. Note that the property converter is applied before performing this test. After this method is called, no changes are made to the givenALcyProperties
.- Specified by:
canEncode
in interfaceILcyPropertiesEncoder
- Parameters:
aProperties
- the properties to be verified.aDestinationName
- the location where the properties should be exported to.- Returns:
true
if this encoder can encode the specified properties to the specified location,false
otherwise.- See Also:
-
encode
Encodes the given
ALcyProperties
into the given destination.Note that the property converter is applied to a copy of the given
ALcyProperties
before encoding. The givenALcyProperties
are not changed.- Specified by:
encode
in interfaceILcyPropertiesEncoder
- Parameters:
aProperties
- The properties to encode.aDestinationName
- The destination name to encode to.- Throws:
IOException
- In case of IO failure.
-
encode
Encodes the given
ALcyProperties
to the givenOutputStream
.Note that the property converter is applied to a copy of the given
ALcyProperties
before encoding. The givenALcyProperties
are not changed.- Parameters:
aProperties
- TheALcyProperties
to encode. Must not benull
.aOutputStream
- TheOutputStream
to which to encode theALcyProperties
. Must not benull
.- Throws:
IOException
- In case of IO failure
-