public class TLcyStringPropertiesCodec extends Object implements 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 and Description |
---|
TLcyStringPropertiesCodec() |
Modifier and Type | Method and Description |
---|---|
boolean |
canDecodeSource(String aSourceName)
Checks whether this
ILcyPropertiesDecoder 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.
|
ALcyProperties |
decode(InputStream aInputStream)
Decodes an
ALcyProperties from the specified InputStream . |
ALcyProperties |
decode(String aSourceName)
Decodes the given source name into an
ALcyProperties object. |
void |
decodeSFCT(InputStream aInputStream,
ALcyProperties aPropertiesSFCT,
boolean aOverwrite)
Decodes an
ALcyProperties from the specified InputStream and puts
the decoded properties in the specified ALcyProperties . |
void |
decodeSFCT(String aSourceName,
ALcyProperties aProperties,
boolean aOverwrite)
Decodes the given source name into a given
ALcyProperties object. |
void |
encode(ALcyProperties aProperties,
OutputStream aOutputStream)
Encodes the given
ALcyProperties to the given OutputStream . |
void |
encode(ALcyProperties aProperties,
String aDestinationName)
Encodes the given
ALcyProperties into the given destination. |
TLcyCompositePropertyConverter |
getCompositePropertyConverter() |
ILcdInputStreamFactory |
getInputStreamFactory()
Returns the
ILcdInputStreamFactory that is used by this decoder. |
ILcdOutputStreamFactory |
getOutputStreamFactory()
Returns the
ILcdOutputStreamFactory that is used by this encoder. |
void |
setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
Sets the
ILcdInputStreamFactory to be used by this decoder. |
void |
setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
Sets the
ILcdOutputStreamFactory to be used by this encoder. |
public TLcyCompositePropertyConverter getCompositePropertyConverter()
public ILcdInputStreamFactory getInputStreamFactory()
ILcdInputStreamFactory
that is used by this decoder.ILcdInputStreamFactory
that is used by this decoder.public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
ILcdInputStreamFactory
to be used by this decoder.aInputStreamFactory
- the ILcdInputStreamFactory
to be used by this decoder,
must not be null
.public ILcdOutputStreamFactory getOutputStreamFactory()
ILcdOutputStreamFactory
that is used by this encoder.ILcdOutputStreamFactory
that is used by this encoder.public void setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
ILcdOutputStreamFactory
to be used by this encoder.aOutputStreamFactory
- The ILcdOutputStreamFactory
to be used by this
encoder, must not be null
.public boolean canDecodeSource(String aSourceName)
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.
canDecodeSource
in interface ILcyPropertiesDecoder
aSourceName
- the data source to be verified; typically a file name or a URL.true
if this decoder can decode the data specified by the source name, false
otherwise.ILcyPropertiesDecoder.decode(java.lang.String)
public ALcyProperties decode(String aSourceName) throws IOException
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 to Object
properties. It is up to the property converter to decide
which properties are converted.
decode
in interface ILcyPropertiesDecoder
aSourceName
- The source name to decode from. Must not be null
.ALcyProperties
. Never null
.IOException
- In case of IO failure.public ALcyProperties decode(InputStream aInputStream) throws IOException
Decodes an ALcyProperties
from the specified InputStream
.
aInputStream
- The InputStream
to decode from.ALcyProperties
. Never null
.IOException
- In case of IO failure.decode(String)
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 read String
properties to Object
properties.
It is up to the property converter to decide which properties are converted.
decodeSFCT
in interface ILcyPropertiesDecoder
aSourceName
- The source name to decode from.aProperties
- The properties to load into. Must not be null
.aOverwrite
- true
to overwrite existing properties if they are also present
in the given source. false
to leave existing properties
unchanged.IOException
- In case of IO failure.public void decodeSFCT(InputStream aInputStream, ALcyProperties aPropertiesSFCT, boolean aOverwrite) throws IOException
Decodes an ALcyProperties
from the specified InputStream
and puts
the decoded properties in the specified ALcyProperties
.
aInputStream
- The InputStream
to decode from.aPropertiesSFCT
- The ALcyProperties
in which to put the decoded properties.aOverwrite
- true
to overwrite existing properties if they are also
present in the given InputStream
. false
to
leave existing properties unchanged.IOException
- In case of IO failure.decodeSFCT(String, com.luciad.lucy.util.properties.ALcyProperties, boolean)
public boolean canEncode(ALcyProperties aProperties, String aDestinationName)
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 contains String
values. Note that the property converter is
applied before performing this test. After this method is called, no changes are made to the
given ALcyProperties
.
canEncode
in interface ILcyPropertiesEncoder
aProperties
- the properties to be verified.aDestinationName
- the location where the properties should be exported to.true
if this encoder can encode the specified properties to the specified
location, false
otherwise.ILcyPropertiesEncoder.encode(com.luciad.lucy.util.properties.ALcyProperties, java.lang.String)
public void encode(ALcyProperties aProperties, String aDestinationName) throws IOException
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 given
ALcyProperties
are not changed.
encode
in interface ILcyPropertiesEncoder
aProperties
- The properties to encode.aDestinationName
- The destination name to encode to.IOException
- In case of IO failure.public void encode(ALcyProperties aProperties, OutputStream aOutputStream) throws IOException
Encodes the given ALcyProperties
to the given OutputStream
.
Note that the property converter is applied to
a copy of the given ALcyProperties
before encoding. The given
ALcyProperties
are not changed.
aProperties
- The ALcyProperties
to encode. Must not be null
.aOutputStream
- The OutputStream
to which to encode the
ALcyProperties
. Must not be null
.IOException
- In case of IO failure