Class PropertiesExtensions
- java.lang.Object
-
- de.alpharogroup.collections.properties.PropertiesExtensions
-
public final class PropertiesExtensions extends java.lang.ObjectThe ClassPropertiesExtensionsprovides methods loading properties and other related operations for properties like find redundant values or getting all available languages from a bundle.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROPERTIES_COMMENT_PATTERNThe constant PROPERTIES_COMMENT_PATTERN is the regex pattern for find comments in properties filestatic java.lang.String[]PROPERTIES_DELIMITERSThe constant PROPERTIES_DELIMITERS contains all valid delimiters for properties filesstatic java.lang.StringSEARCH_FILE_PATTERNThe constant SEARCH_FILE_PATTERN is a regex for searching java and html files
-
Constructor Summary
Constructors Constructor Description PropertiesExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidexport(java.util.Properties properties, java.io.OutputStream outputStream)Exports the givenInputStreamthat represents a properties file to the given propertiesOutputStreamthat represents the output file.static voidexport(java.util.Properties properties, java.io.OutputStream outputStream, java.io.InputStream inputStream, java.lang.String comment, boolean loadFromXML, boolean storeToXML)Exports the givenInputStreamthat represents a properties file to the given propertiesOutputStreamthat represents the output file.static voidexport(java.util.Properties properties, java.io.OutputStream outputStream, java.lang.String comment)Exports the givenInputStreamthat represents a properties file to the given propertiesOutputStreamthat represents the output file.static java.util.Map<java.lang.String,java.util.List<java.lang.String>>findRedundantValues(java.util.Properties properties)Finds redundant values from the given Properties object and saves it to a Map.static java.util.Optional<java.lang.Integer>getInteger(java.util.Properties properties, java.lang.String propertiesKey)Try to get a number from the given properties key from the given properties.static java.util.Map<java.lang.String,java.util.List<java.lang.String>>getMatchedPrefixLists(java.util.Properties properties)Finds all keys with the same key prefixes from the given Properties and saves them to a Map with the prefix as a key and holds a List with the whole keys the starts with the same key prefix.static java.util.List<java.lang.String>getPropertyParameters(java.lang.String propertyValue)Finds the property parameters from the given propertyValue.static java.util.PropertiesloadProperties(java.io.File propertiesFile)Load a Properties-object from the given File-object.static java.util.PropertiesloadProperties(java.io.File propertiesFile, boolean loadFromXML)Load a Properties-object from the given File-object.static voidtoProperties(java.io.File properties, java.io.File xml, java.lang.String comment)Converts the given xml file to the given properties file.static voidtoProperties(java.io.OutputStream properties, java.io.InputStream xml, java.lang.String comment)Converts the given xml InputStream to the given properties OutputStream.static voidtoProperties(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.lang.String comment, boolean xmlFile)Exports the givenInputStreamthat represents a properties file to the given propertiesOutputStreamthat represents the output file.static voidtoPropertiesFile(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.lang.String comment)Converts the given properties InputStream to the given propertiesOutputStreamthat represents the output file.static voidtoXml(java.io.File properties, java.io.File xml, java.lang.String comment, java.lang.String encoding)Converts the given properties file to the given xml file.static voidtoXml(java.io.InputStream properties, java.io.OutputStream xml, java.lang.String comment, java.lang.String encoding)Converts the given properties InputStream to the given xml OutputStream.
-
-
-
Field Detail
-
PROPERTIES_COMMENT_PATTERN
public static final java.lang.String PROPERTIES_COMMENT_PATTERN
The constant PROPERTIES_COMMENT_PATTERN is the regex pattern for find comments in properties file- See Also:
- Constant Field Values
-
SEARCH_FILE_PATTERN
public static final java.lang.String SEARCH_FILE_PATTERN
The constant SEARCH_FILE_PATTERN is a regex for searching java and html files- See Also:
- Constant Field Values
-
PROPERTIES_DELIMITERS
public static final java.lang.String[] PROPERTIES_DELIMITERS
The constant PROPERTIES_DELIMITERS contains all valid delimiters for properties files
-
-
Method Detail
-
findRedundantValues
public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> findRedundantValues(java.util.Properties properties)
Finds redundant values from the given Properties object and saves it to a Map.- Parameters:
properties- The Properties to check.- Returns:
- A map that contains the redundant value as the key of the map and a List(as value of the map) of keys that have the redundant value.
-
getMatchedPrefixLists
public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> getMatchedPrefixLists(java.util.Properties properties)
Finds all keys with the same key prefixes from the given Properties and saves them to a Map with the prefix as a key and holds a List with the whole keys the starts with the same key prefix.- Parameters:
properties- the en properties- Returns:
- the matched prefix lists
-
getPropertyParameters
public static java.util.List<java.lang.String> getPropertyParameters(java.lang.String propertyValue)
Finds the property parameters from the given propertyValue.- Parameters:
propertyValue- the property value- Returns:
- the property parameters as a list.
-
loadProperties
public static java.util.Properties loadProperties(java.io.File propertiesFile) throws java.io.IOExceptionLoad a Properties-object from the given File-object.- Parameters:
propertiesFile- the properties file- Returns:
- the properties or null if the file is not found.
- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
loadProperties
public static java.util.Properties loadProperties(java.io.File propertiesFile, boolean loadFromXML) throws java.io.IOExceptionLoad a Properties-object from the given File-object.- Parameters:
propertiesFile- the properties fileloadFromXML- the load from XML- Returns:
- the properties or null if the file is not found.
- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
toProperties
public static void toProperties(java.io.File properties, java.io.File xml, java.lang.String comment) throws java.io.IOExceptionConverts the given xml file to the given properties file.- Parameters:
properties- the properties file. The xml file does not have to exist.xml- the xml file with the properties to convert.comment- the comment- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
toProperties
public static void toProperties(java.io.OutputStream properties, java.io.InputStream xml, java.lang.String comment) throws java.io.IOExceptionConverts the given xml InputStream to the given properties OutputStream.- Parameters:
properties- the properties file. The xml file does not have to exist.xml- the xml file with the properties to convert.comment- the comment- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
toPropertiesFile
public static void toPropertiesFile(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.lang.String comment) throws java.io.IOExceptionConverts the given properties InputStream to the given propertiesOutputStreamthat represents the output file.- Parameters:
outputStream- the properties file. The xml file does not have to exist.inputStream- the xml file with the properties to convert.comment- the comment- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
toProperties
public static void toProperties(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.lang.String comment, boolean xmlFile) throws java.io.IOExceptionExports the givenInputStreamthat represents a properties file to the given propertiesOutputStreamthat represents the output file. The flag xmlFile tells if the output shell be an xml file or a properties file.- Parameters:
outputStream- the stream from the output properties file. If the file does not exists a new file will be created.inputStream- the stream from input file with the properties to convertcomment- the commentxmlFile- the flag that tells if the output shell be an xml file if true otherwise it will be an properties file- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
export
public static void export(java.util.Properties properties, java.io.OutputStream outputStream, java.io.InputStream inputStream, java.lang.String comment, boolean loadFromXML, boolean storeToXML) throws java.io.IOExceptionExports the givenInputStreamthat represents a properties file to the given propertiesOutputStreamthat represents the output file.- Parameters:
properties- the properties to storeoutputStream- the stream from the output properties file. If the file does not exists a new file will be created.inputStream- the input streamcomment- the commentloadFromXML- the flag that tells if the input shell be loaded from a XML file if true otherwise it will be loaded from a properties filestoreToXML- the flag that tells if the output shell be stored to a XML file if true otherwise it will be stored to a properties file- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
export
public static void export(java.util.Properties properties, java.io.OutputStream outputStream) throws java.io.IOExceptionExports the givenInputStreamthat represents a properties file to the given propertiesOutputStreamthat represents the output file. The flag xmlFile tells if the output shell be an xml file or a properties file.- Parameters:
properties- the properties to storeoutputStream- the stream from the output properties file. If the file does not exists a new file will be created.- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
export
public static void export(java.util.Properties properties, java.io.OutputStream outputStream, java.lang.String comment) throws java.io.IOExceptionExports the givenInputStreamthat represents a properties file to the given propertiesOutputStreamthat represents the output file. The flag xmlFile tells if the output shell be an xml file or a properties file.- Parameters:
properties- the properties to storeoutputStream- the stream from the output properties file. If the file does not exists a new file will be created.comment- the comment- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
toXml
public static void toXml(java.io.File properties, java.io.File xml, java.lang.String comment, java.lang.String encoding) throws java.io.IOExceptionConverts the given properties file to the given xml file.- Parameters:
properties- the properties file.xml- the xml file to write in. The xml file does not have to exist.comment- the commentencoding- the encoding for the xml file.- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
toXml
public static void toXml(java.io.InputStream properties, java.io.OutputStream xml, java.lang.String comment, java.lang.String encoding) throws java.io.IOExceptionConverts the given properties InputStream to the given xml OutputStream.- Parameters:
properties- the properties InputStream.xml- the xml OutputStream to write in.comment- the commentencoding- the encoding for the xml file.- Throws:
java.io.IOException- Signals that an I/O exception has occurred.
-
getInteger
public static java.util.Optional<java.lang.Integer> getInteger(java.util.Properties properties, java.lang.String propertiesKey)Try to get a number from the given properties key from the given properties. If it does not exists an emptyOptionalwill be returned and a log message will be logged.- Parameters:
properties- the propertiespropertiesKey- the properties key- Returns:
- the Optional with the number or an empty Optional if the properties key has no number value or no value at all
-
-