Class Config
- java.lang.Object
-
- io.gitlab.rychly.gphotos_uploader.config.Config
-
public class Config extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Config(java.lang.String applicationDirectoryName)
Create configuration file loader/saver for configuration files in a given application directory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.File
getConfigFile(java.lang.String fileName)
Get an existing config file of a particular name (or create a new one if the file is missing).java.io.File
getConfigFile(java.lang.String fileName, boolean createInWorkingAndNotInHomeConfigDir)
Get an existing config file of a particular name (or create a new one if the file is missing).static java.util.Properties
loadPropertiesFromClassPathOrEmpty(java.lang.String fileName)
Load properties from a config file given by its filename in class-path or, in the case of error, get an empty properties.java.util.Properties
loadPropertiesFromConfigFileOrEmpty(java.lang.String fileName)
Load properties from a config file given by its basename or, in the case of error, get an empty properties.java.util.Properties
loadPropertiesFromConfigFileOrEmpty(java.lang.String fileName, boolean createInWorkingAndNotInHomeConfigDir)
Load properties from a config file given by its basename or, in the case of error, get an empty properties.static java.util.Properties
loadPropertiesFromInputStreamOrGetEmpty(java.io.InputStream inputStream)
Load properties from a givenInputStream
object or, in the case of error, get an empty properties.void
storePropertiesIntoConfigFile(java.lang.String fileName, @NotNull java.util.Properties properties)
Store properties into a config file given by its basename.void
storePropertiesIntoConfigFile(java.lang.String fileName, @NotNull java.util.Properties properties, boolean appendNotOverwrite, boolean createInWorkingAndNotInHomeConfigDir)
Store properties into a config file given by its basename.
-
-
-
Method Detail
-
loadPropertiesFromInputStreamOrGetEmpty
public static java.util.Properties loadPropertiesFromInputStreamOrGetEmpty(java.io.InputStream inputStream)
Load properties from a givenInputStream
object or, in the case of error, get an empty properties.- Parameters:
inputStream
- theInputStream
object to load properties from- Returns:
- the
Properties
object which was loaded or which is empty
-
loadPropertiesFromClassPathOrEmpty
public static java.util.Properties loadPropertiesFromClassPathOrEmpty(java.lang.String fileName)
Load properties from a config file given by its filename in class-path or, in the case of error, get an empty properties.- Parameters:
fileName
- the config file name- Returns:
- the
Properties
object which was loaded or which is empty
-
getConfigFile
public java.io.File getConfigFile(java.lang.String fileName) throws java.io.IOException
Get an existing config file of a particular name (or create a new one if the file is missing). The new file, if needed, will be create in a home configuration directory, not in the working directory.- Parameters:
fileName
- the config file name (absolute, relative, or base/without path)- Returns:
- the File object
- Throws:
java.io.IOException
- cannot create the file
-
getConfigFile
public java.io.File getConfigFile(java.lang.String fileName, boolean createInWorkingAndNotInHomeConfigDir) throws java.io.IOException
Get an existing config file of a particular name (or create a new one if the file is missing). Create a configuration directory (not a file) if the file name ends with directory separator (e.g. "/").- Parameters:
fileName
- the config file name (absolute, relative, or base/without path)createInWorkingAndNotInHomeConfigDir
- whether create the new config file in a working directory- Returns:
- the File object
- Throws:
java.io.IOException
- cannot create the file
-
loadPropertiesFromConfigFileOrEmpty
public java.util.Properties loadPropertiesFromConfigFileOrEmpty(java.lang.String fileName)
Load properties from a config file given by its basename or, in the case of error, get an empty properties. The new file, if needed, will be create in a home configuration directory, not in the working directory.- Parameters:
fileName
- the config file name (absolute, relative, or base/without path)- Returns:
- the
Properties
object which was loaded or which is empty
-
loadPropertiesFromConfigFileOrEmpty
public java.util.Properties loadPropertiesFromConfigFileOrEmpty(java.lang.String fileName, boolean createInWorkingAndNotInHomeConfigDir)
Load properties from a config file given by its basename or, in the case of error, get an empty properties.- Parameters:
fileName
- the config file name (absolute, relative, or base/without path)createInWorkingAndNotInHomeConfigDir
- whether create the new config file in a working directory- Returns:
- the
Properties
object which was loaded or which is empty
-
storePropertiesIntoConfigFile
public void storePropertiesIntoConfigFile(java.lang.String fileName, @NotNull @NotNull java.util.Properties properties) throws java.io.IOException
Store properties into a config file given by its basename. The new file, if needed, will be create in a home configuration directory, not in the working directory. Moreover, an existing file will be overwritten (the original properties in the file will be lost).- Parameters:
fileName
- the config file name (absolute, relative, or base/without path)properties
- the properties to store- Throws:
java.io.IOException
- cannot create or write the file
-
storePropertiesIntoConfigFile
public void storePropertiesIntoConfigFile(java.lang.String fileName, @NotNull @NotNull java.util.Properties properties, boolean appendNotOverwrite, boolean createInWorkingAndNotInHomeConfigDir) throws java.io.IOException
Store properties into a config file given by its basename.- Parameters:
fileName
- the config file name (absolute, relative, or base/without path)properties
- the properties to storeappendNotOverwrite
- whether append to the config file (not checking if the properties are unique)createInWorkingAndNotInHomeConfigDir
- whether create the new config file in a working directory- Throws:
java.io.IOException
- cannot create or write the file
-
-