Package org.jets3t.service
Class Jets3tProperties
- java.lang.Object
-
- org.jets3t.service.Jets3tProperties
-
- All Implemented Interfaces:
Serializable
public class Jets3tProperties extends Object implements Serializable
Utility class to load and store JetS3t-specific properties.Properties are initially loaded via getInstance methods from a named properties file, which must be available at the root of the classpath, or from an input stream. In either case the properties are cached according to a name, such that subsequent calls to get a properties instance with the same name will return the same properties object.
For more information about JetS3t properties please see: JetS3t Configuration
- Author:
- James Murty
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Jets3tProperties()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearAllProperties()
Clears (removes) all the property names and values used internally by this object.void
clearProperty(String propertyName)
Removes a property name and value.boolean
containsKey(String propertyName)
boolean
getBoolProperty(String propertyName, boolean defaultValue)
static Jets3tProperties
getInstance(InputStream inputStream, String propertiesIdentifer)
Return a properties instance based on properties read from an input stream, and stores the properties object in a cache referenced by the propertiesIdentifier.static Jets3tProperties
getInstance(String propertiesFileName)
Return a properties instance based on properties read from a properties file, and stores the properties object in a cache referenced by the properties file name.int
getIntProperty(String propertyName, int defaultValue)
long
getLongProperty(String propertyName, long defaultValue)
Properties
getProperties()
String
getStringProperty(String propertyName, String defaultValue)
boolean
isLoaded()
void
loadAndReplaceProperties(InputStream inputStream, String propertiesSource)
Reads properties from an InputStream and stores them in this class's properties object.void
loadAndReplaceProperties(Properties newProperties, String propertiesSource)
Merges properties from another Properties object into this instance.void
loadAndReplaceProperties(Jets3tProperties properties, String propertiesSource)
Merges properties from another JetS3tProperties object into this instance.void
setProperty(String propertyName, String propertyValue)
Sets or removes a property value.
-
-
-
Method Detail
-
getInstance
public static Jets3tProperties getInstance(InputStream inputStream, String propertiesIdentifer) throws IOException
Return a properties instance based on properties read from an input stream, and stores the properties object in a cache referenced by the propertiesIdentifier.- Parameters:
inputStream
- an input stream containing property name/value pairs in a format that can be read byProperties.load(InputStream)
.propertiesIdentifer
- the name under which the properties are cached- Returns:
- a properties object initialised with property values from the input stream
- Throws:
IOException
-
getInstance
public static Jets3tProperties getInstance(String propertiesFileName)
Return a properties instance based on properties read from a properties file, and stores the properties object in a cache referenced by the properties file name.- Parameters:
propertiesFileName
- the name of a properties file that exists in the root of the classpath, such that it can be loaded with the code getClass().getResourceAsStream("/" + propertiesFileName);.- Returns:
- a properties object initialised with property values from the properties file
-
setProperty
public void setProperty(String propertyName, String propertyValue)
Sets or removes a property value.- Parameters:
propertyName
- the name of the property to set or remove.propertyValue
- a new value for the property. If this value is null, the named property will be removed.
-
clearProperty
public void clearProperty(String propertyName)
Removes a property name and value.- Parameters:
propertyName
- the name of the property to remove.
-
clearAllProperties
public void clearAllProperties()
Clears (removes) all the property names and values used internally by this object. Use this method in combination withloadAndReplaceProperties(Properties, String)
to directly manage the properties encapsulated in this class.
-
loadAndReplaceProperties
public void loadAndReplaceProperties(InputStream inputStream, String propertiesSource) throws IOException
Reads properties from an InputStream and stores them in this class's properties object. If a new property already exists, the property value is replaced.- Parameters:
inputStream
- an input stream containing property name/value pairs in a format that can be read byProperties.load(InputStream)
.propertiesSource
- a name for the source of the properties, such as a properties file name or identifier. This is only used to generate meaningful debug messages when properties are updated, so it is possible to tell where the updated property value came from.- Throws:
IOException
-
loadAndReplaceProperties
public void loadAndReplaceProperties(Jets3tProperties properties, String propertiesSource)
Merges properties from another JetS3tProperties object into this instance. If a new property already exists, the property value is replaced.- Parameters:
properties
- the object containing properties that will be merged into this set of properties.propertiesSource
- a name for the source of the properties, such as a properties file name or identifier. This is only used to generate meaningful debug messages when properties are updated, so it is possible to tell where the updated property value came from.
-
loadAndReplaceProperties
public void loadAndReplaceProperties(Properties newProperties, String propertiesSource)
Merges properties from another Properties object into this instance. If a new property already exists, the property value is replaced.- Parameters:
newProperties
- the object containing properties that will be merged into this set of properties.propertiesSource
- a name for the source of the properties, such as a properties file name or identifier. This is only used to generate meaningful debug messages when properties are updated, so it is possible to tell where the updated property value came from.
-
getProperties
public Properties getProperties()
- Returns:
- a properties object containing all this object's properties, but cloned so changes to the returned properties object are not reflected in this object.
-
getStringProperty
public String getStringProperty(String propertyName, String defaultValue)
- Parameters:
propertyName
-defaultValue
-- Returns:
- the named Property value as a string if the property is set, otherwise returns the default value.
-
getLongProperty
public long getLongProperty(String propertyName, long defaultValue) throws NumberFormatException
- Parameters:
propertyName
-defaultValue
-- Returns:
- the named Property value as a long if the property is set, otherwise returns the default value.
- Throws:
NumberFormatException
-
getIntProperty
public int getIntProperty(String propertyName, int defaultValue) throws NumberFormatException
- Parameters:
propertyName
-defaultValue
-- Returns:
- the named Property value as an int if the property is set, otherwise returns the default value.
- Throws:
NumberFormatException
-
getBoolProperty
public boolean getBoolProperty(String propertyName, boolean defaultValue) throws IllegalArgumentException
- Parameters:
propertyName
-defaultValue
-- Returns:
- the named Property value as a boolean if the property is set, otherwise returns the default value.
- Throws:
IllegalArgumentException
-
containsKey
public boolean containsKey(String propertyName)
- Parameters:
propertyName
- the property name to check for.- Returns:
- true if the property exists, false otherwise.
-
isLoaded
public boolean isLoaded()
- Returns:
- true if this properties object was successfully loaded from an input stream or a named properties file, false otherwise.
-
-