Class TLcyStringPropertiesCodec

java.lang.Object
com.luciad.lucy.util.properties.codec.TLcyStringPropertiesCodec
All Implemented Interfaces:
ILcyPropertiesDecoder, ILcyPropertiesEncoder

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 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 Details

    • TLcyStringPropertiesCodec

      public TLcyStringPropertiesCodec()
  • Method Details

    • getCompositePropertyConverter

      public TLcyCompositePropertyConverter getCompositePropertyConverter()
    • getInputStreamFactory

      public ILcdInputStreamFactory getInputStreamFactory()
      Returns the ILcdInputStreamFactory that is used by this decoder.
      Returns:
      the ILcdInputStreamFactory that is used by this decoder.
    • setInputStreamFactory

      public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
      Sets the ILcdInputStreamFactory to be used by this decoder.
      Parameters:
      aInputStreamFactory - the ILcdInputStreamFactory to be used by this decoder, must not be null.
    • getOutputStreamFactory

      public ILcdOutputStreamFactory getOutputStreamFactory()
      Returns the ILcdOutputStreamFactory that is used by this encoder.
      Returns:
      the ILcdOutputStreamFactory that is used by this encoder.
    • setOutputStreamFactory

      public void setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
      Sets the ILcdOutputStreamFactory to be used by this encoder.
      Parameters:
      aOutputStreamFactory - The ILcdOutputStreamFactory to be used by this encoder, must not be null.
    • canDecodeSource

      public boolean canDecodeSource(String aSourceName)
      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 interface ILcyPropertiesDecoder
      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

      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.

      Specified by:
      decode in interface ILcyPropertiesDecoder
      Parameters:
      aSourceName - The source name to decode from. Must not be null.
      Returns:
      The decoded ALcyProperties. Never null.
      Throws:
      IOException - In case of IO failure.
    • decode

      public ALcyProperties decode(InputStream aInputStream) throws IOException

      Decodes an ALcyProperties from the specified InputStream.

      Parameters:
      aInputStream - The InputStream to decode from.
      Returns:
      The decoded ALcyProperties. Never null.
      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 read String properties to Object properties. It is up to the property converter to decide which properties are converted.

      Specified by:
      decodeSFCT in interface ILcyPropertiesDecoder
      Parameters:
      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.
      Throws:
      IOException - In case of IO failure.
    • decodeSFCT

      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.

      Parameters:
      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.
      Throws:
      IOException - In case of IO failure.
      See Also:
    • canEncode

      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.

      Specified by:
      canEncode in interface ILcyPropertiesEncoder
      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

      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.

      Specified by:
      encode in interface ILcyPropertiesEncoder
      Parameters:
      aProperties - The properties to encode.
      aDestinationName - The destination name to encode to.
      Throws:
      IOException - In case of IO failure.
    • encode

      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.

      Parameters:
      aProperties - The ALcyProperties to encode. Must not be null.
      aOutputStream - The OutputStream to which to encode the ALcyProperties. Must not be null.
      Throws:
      IOException - In case of IO failure