- java.lang.Object
-
- com.pervasive.datarush.commons.util.PropertiesFileUtil
-
public class PropertiesFileUtil extends Object
Utility methods to consume properties files.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPropertiesFileUtil.PropertyFileType
-
Constructor Summary
Constructors Constructor Description PropertiesFileUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PropertiesloadFromJSON(InputStream in)Loads a JSON formatted string from a stream into aPropertiesobject.static PropertiesloadFromJSON(String filePath)Loads a JSON file from disk into aPropertiesobject.static PropertiesloadFromXML(InputStream in)Loads a XML string from a stream into aPropertiesobject.static PropertiesloadFromXML(String filePath)Loads a XML file from disk into aPropertiesobject.static Propertiesread(File propertiesFile)Loads a.properties-formatted file from disk into aPropertiesobject.static Propertiesread(InputStream in)Loads a.properties-formatted string from a stream into aPropertiesobject.static Propertiesread(String propertiesPath)Loads a.properties-formatted file from disk into aPropertiesobject.static voidwrite(File propertiesFile, Properties data, String comment)Writes aPropertiesobject to disk.static voidwrite(String propertiesPath, Properties data, String comment)Writes aPropertiesobject to disk.
-
-
-
Method Detail
-
read
public static Properties read(String propertiesPath)
Loads a.properties-formatted file from disk into aPropertiesobject. On error, the input stream is properly closed and a user-friendly exception is thrown.- Parameters:
propertiesPath- the path to the file to load- Returns:
- a
Propertiesobject populated with the specified file's data
-
read
public static Properties read(File propertiesFile)
Loads a.properties-formatted file from disk into aPropertiesobject. On error, the input stream is properly closed and a user-friendly exception is thrown.- Parameters:
propertiesFile- the file to load- Returns:
- a
Propertiesobject populated with the specified file's data
-
read
public static Properties read(InputStream in) throws IOException
Loads a.properties-formatted string from a stream into aPropertiesobject. However this method will not close the stream or handle exceptions directly.- Parameters:
in- inputstream containing properties- Returns:
- a
Propertiesobject populated with the specified file's data - Throws:
IOException
-
write
public static void write(String propertiesPath, Properties data, String comment)
Writes aPropertiesobject to disk. On error, the output stream is properly closed and a user-friendly exception is thrown.- Parameters:
propertiesPath- the path to the file to writedata- thePropertiesobject to storecomment- an optional comment to include at the top of the written file
-
write
public static void write(File propertiesFile, Properties data, String comment)
Writes aPropertiesobject to disk. On error, the output stream is properly closed and a user-friendly exception is thrown.- Parameters:
propertiesFile- the file to writedata- thePropertiesobject to storecomment- an optional comment to include at the top of the written file
-
loadFromJSON
public static Properties loadFromJSON(String filePath)
Loads a JSON file from disk into aPropertiesobject. On error, the input stream is properly closed and a user-friendly exception is thrown.- Parameters:
filePath- the path to the file to load- Returns:
- a
Propertiesobject populated with the specified file's data
-
loadFromJSON
public static Properties loadFromJSON(InputStream in) throws IOException
Loads a JSON formatted string from a stream into aPropertiesobject. However this method will not close the stream or handle exceptions directly.- Parameters:
in- inputstream containing properties in JSON format- Returns:
- a
Propertiesobject populated with the specified file's data - Throws:
IOException
-
loadFromXML
public static Properties loadFromXML(String filePath)
Loads a XML file from disk into aPropertiesobject. On error, the input stream is properly closed and a user-friendly exception is thrown.- Parameters:
filePath- the path to the file to load- Returns:
- a
Propertiesobject populated with the specified file's data
-
loadFromXML
public static Properties loadFromXML(InputStream in) throws IOException
Loads a XML string from a stream into aPropertiesobject. However this method will not close the stream or handle exceptions directly.- Parameters:
in- inputstream containing properties in XML format- Returns:
- a
Propertiesobject populated with the specified file's data - Throws:
IOException
-
-