public class FileConfiguration
extends java.lang.Object
Constructor and Description |
---|
FileConfiguration()
Initializes a file configuration but does not load
any configuration.
|
Modifier and Type | Method and Description |
---|---|
void |
addList(java.lang.String name,
boolean required)
Adds a list to the map where the file is in the current directory
and the files name is name appended with .txt
|
void |
addProperties(java.lang.String name,
boolean required,
java.lang.String... requiredKeys)
Adds a property to the map where the file is in the current
directory and the files name is name appended with .properties
|
void |
addString(java.lang.String name,
boolean required)
Adds a string to the map where the file is in the current directory
and the files name is name appended with .txt
|
java.nio.file.Path |
getFolder()
Gets the absolute path of the folder that configuration
is being loaded from
|
java.util.List<java.lang.String> |
getList(java.lang.String name) |
java.util.Map<java.lang.String,java.util.Properties> |
getProperties()
Get the map of strings -> properties
|
java.lang.String |
getProperty(java.lang.String key)
Gets the property where the part before the
.
|
java.lang.String |
getString(java.lang.String name) |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getStringLists()
Get the map for strings -> string lists
|
java.util.Map<java.lang.String,java.lang.String> |
getStrings()
Get the map for strings -> strings
|
void |
load()
Loads all the necessary configuration.
|
protected java.util.Properties |
loadProperties(java.nio.file.Path path,
java.lang.String... requiredKeys)
Loads properties from the specified file, as if by
Properties.load(java.io.Reader) |
protected java.lang.String |
loadReplyString(java.nio.file.Path path)
Loads a reply string from a file, ignoring lines prefixed with a hash-tag
(#).
|
protected java.util.List<java.lang.String> |
loadStringList(java.nio.file.Path path)
Loads a list of strings from the file, where there is 1 string per line.
|
void |
setFolder(java.nio.file.Path path)
Sets the path to the folder that configuration is being loaded
from.
|
public FileConfiguration()
public void load() throws java.io.IOException, java.lang.NullPointerException
java.io.IOException
- if an io-exception occurs (or a file is not found)java.lang.NullPointerException
- if a required key is missingpublic java.nio.file.Path getFolder()
public void setFolder(java.nio.file.Path path)
path
- the folder to load config frompublic java.lang.String getProperty(java.lang.String key)
addProperty("user", true, "username", "password")
.
.
.
getProperty("user.username")
key
- the keypublic java.util.List<java.lang.String> getList(java.lang.String name)
public java.lang.String getString(java.lang.String name)
public void addProperties(java.lang.String name, boolean required, java.lang.String... requiredKeys) throws java.lang.NullPointerException, java.io.IOException
name
- the name of the file except for .propertiesrequired
- if an NPE should be thrown if the file doesn't existrequiredKeys
- the keys that must be in the properties filejava.lang.NullPointerException
- if the file doesn't exist and it is required, or a key is missing from the propertiesjava.io.IOException
- if an i/o exception occurspublic void addList(java.lang.String name, boolean required) throws java.io.IOException
name
- the name of the filerequired
- if an NPE should be thrown if the file doesn't existjava.io.IOException
- if an i/o exception occurspublic void addString(java.lang.String name, boolean required) throws java.io.IOException
name
- the name of the filerequired
- if an NPE should be thrown if the file doesn't existjava.io.IOException
- if an i/o exception occursprotected java.util.Properties loadProperties(java.nio.file.Path path, java.lang.String... requiredKeys) throws java.io.IOException, java.lang.NullPointerException
Properties.load(java.io.Reader)
path
- the file to load fromrequiredKeys
- the list of required keysfile
java.io.IOException
- if an i/o exception occurs (like file
not existing)java.lang.NullPointerException
- if a required key is missing or the file is nullprotected java.lang.String loadReplyString(java.nio.file.Path path) throws java.io.IOException
path
- the file to load fromjava.io.IOException
- if an i/o exception occurs, like the file not existingprotected java.util.List<java.lang.String> loadStringList(java.nio.file.Path path) throws java.io.IOException
String.substring(int)
with parameter 3. All strings
are lower-cased.path
- the file to load fromjava.io.IOException
- if an i/o exception occurs, like the file not existingpublic java.util.Map<java.lang.String,java.lang.String> getStrings()
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getStringLists()
public java.util.Map<java.lang.String,java.util.Properties> getProperties()