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 Strings. 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 Strings 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanDecodeSource(String aSourceName) Checks whether thisILcyPropertiesDecodercan decode the specified data source.booleancanEncode(ALcyProperties aProperties, String aDestinationName) Returns whether this encoder can export the specified properties to the specified destination.decode(InputStream aInputStream) Decodes anALcyPropertiesfrom the specifiedInputStream.Decodes the given source name into anALcyPropertiesobject.voiddecodeSFCT(InputStream aInputStream, ALcyProperties aPropertiesSFCT, boolean aOverwrite) Decodes anALcyPropertiesfrom the specifiedInputStreamand puts the decoded properties in the specifiedALcyProperties.voiddecodeSFCT(String aSourceName, ALcyProperties aProperties, boolean aOverwrite) Decodes the given source name into a givenALcyPropertiesobject.voidencode(ALcyProperties aProperties, OutputStream aOutputStream) Encodes the givenALcyPropertiesto the givenOutputStream.voidencode(ALcyProperties aProperties, String aDestinationName) Encodes the givenALcyPropertiesinto the given destination.Returns theILcdInputStreamFactorythat is used by this decoder.Returns theILcdOutputStreamFactorythat is used by this encoder.voidsetInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory) Sets theILcdInputStreamFactoryto be used by this decoder.voidsetOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory) Sets theILcdOutputStreamFactoryto be used by this encoder.
-
Constructor Details
-
TLcyStringPropertiesCodec
public TLcyStringPropertiesCodec()
-
-
Method Details
-
getCompositePropertyConverter
-
getInputStreamFactory
Returns theILcdInputStreamFactorythat is used by this decoder.- Returns:
- the
ILcdInputStreamFactorythat is used by this decoder.
-
setInputStreamFactory
Sets theILcdInputStreamFactoryto be used by this decoder.- Parameters:
aInputStreamFactory- theILcdInputStreamFactoryto be used by this decoder, must not benull.
-
getOutputStreamFactory
Returns theILcdOutputStreamFactorythat is used by this encoder.- Returns:
- the
ILcdOutputStreamFactorythat is used by this encoder.
-
setOutputStreamFactory
Sets theILcdOutputStreamFactoryto be used by this encoder.- Parameters:
aOutputStreamFactory- TheILcdOutputStreamFactoryto be used by this encoder, must not benull.
-
canDecodeSource
Description copied from interface:ILcyPropertiesDecoderChecks whether this
ILcyPropertiesDecodercan decode the specified data source.Often this will only be a simple test, for example checking the file extension of a file.
- Specified by:
canDecodeSourcein interfaceILcyPropertiesDecoder- Parameters:
aSourceName- the data source to be verified; typically a file name or a URL.- Returns:
trueif this decoder can decode the data specified by the source name,falseotherwise.- See Also:
-
decode
Decodes the given source name into an
ALcyPropertiesobject.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
Stringproperties toObjectproperties. It is up to the property converter to decide which properties are converted.- Specified by:
decodein 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
ALcyPropertiesfrom the specifiedInputStream.- Parameters:
aInputStream- TheInputStreamto 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
ALcyPropertiesobject.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 readStringproperties toObjectproperties. It is up to the property converter to decide which properties are converted.- Specified by:
decodeSFCTin interfaceILcyPropertiesDecoder- Parameters:
aSourceName- The source name to decode from.aProperties- The properties to load into. Must not benull.aOverwrite-trueto overwrite existing properties if they are also present in the given source.falseto 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
ALcyPropertiesfrom the specifiedInputStreamand puts the decoded properties in the specifiedALcyProperties.- Parameters:
aInputStream- TheInputStreamto decode from.aPropertiesSFCT- TheALcyPropertiesin which to put the decoded properties.aOverwrite-trueto overwrite existing properties if they are also present in the givenInputStream.falseto 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
ALcyPropertiesonly containsStringvalues. 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:
canEncodein interfaceILcyPropertiesEncoder- Parameters:
aProperties- the properties to be verified.aDestinationName- the location where the properties should be exported to.- Returns:
trueif this encoder can encode the specified properties to the specified location,falseotherwise.- See Also:
-
encode
Encodes the given
ALcyPropertiesinto the given destination.Note that the property converter is applied to a copy of the given
ALcyPropertiesbefore encoding. The givenALcyPropertiesare not changed.- Specified by:
encodein 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
ALcyPropertiesto the givenOutputStream.Note that the property converter is applied to a copy of the given
ALcyPropertiesbefore encoding. The givenALcyPropertiesare not changed.- Parameters:
aProperties- TheALcyPropertiesto encode. Must not benull.aOutputStream- TheOutputStreamto which to encode theALcyProperties. Must not benull.- Throws:
IOException- In case of IO failure
-