Package com.avrix.utils
Class YamlFile
java.lang.Object
com.avrix.utils.YamlFile
This class represents a YAML file and provides methods to read, write, and manipulate its contents.
-
Constructor Summary
ConstructorDescriptionConstructor to load a YAML file from aFile
.YamlFile
(InputStream inputStream, Path filePath, String fileName) Constructor to load a YAML file from anInputStream
.Constructor to load a YAML file from a file path.Constructor to load a YAML file from a JAR file.Constructor to load a YAML file from aURI
.Constructor to load a YAML file from aURL
.Constructor to load a YAML file from aPath
. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
clear()
Clears all the data in the YAML file.final boolean
Checks if a key exists in the YAML file.static YamlFile
Creates a new YAML file.static YamlFile
Creates a new YAML file from a file path.static YamlFile
Creates a new YAML file from aPath
.getAll()
Returns all the data in the YAML file.final boolean
getBoolean
(String key) Gets a boolean value from the YAML file.getBooleanList
(String key) Gets a list of booleans from the YAML file.getBooleanMap
(String key) Gets a map of boolean values from the YAML file stored under the specified key.final byte
Gets a byte value from the YAML file.getByteList
(String key) Gets a list of bytes from the YAML file.final char
Gets a char value from the YAML file.getCharacterList
(String key) Gets a list of characters from the YAML file.final double
Gets a double value from the YAML file.getDoubleList
(String key) Gets a list of doubles from the YAML file.getDoubleMap
(String key) Gets a map of double values from the YAML file stored under the specified key.Returns the file name of the YAML file.Returns the file path of the YAML file.final int
Gets an integer value from the YAML file.getIntegerList
(String key) Gets a list of integers from the YAML file.Gets a map of integer values from the YAML file stored under the specified key.Gets a list of values from the YAML file.final long
Gets a long value from the YAML file.getLongList
(String key) Gets a list of longs from the YAML file.Gets a map from the YAML file stored under the specified key.getMapKeys
(String key) Retrieves the keys of the map stored under the specified key in the YAML file.final Collection<Object>
getMapValues
(String key) Retrieves the values of the map stored under the specified key in the YAML file.final short
Gets a short value from the YAML file.getShortList
(String key) Gets a list of shorts from the YAML file.final String
Gets a string value from the YAML file.getStringList
(String key) Gets a list of strings from the YAML file.getStringMap
(String key) Gets a map of string values from the YAML file stored under the specified key.Gets a value from the YAML file.final boolean
isEmpty()
Checks if the YAML file is empty.static YamlFile
Loads a YAML file from a File.static YamlFile
Loads a YAML file from a file path.static YamlFile
Loads a YAML file from aPath
.final void
Merges anotherYamlFile
into this YAML file.final void
Merges a map of data into the YAML file.final void
Removes a key from the YAML file.void
save()
Saves the YAML file to its original file path.void
Saves the YAML file to a specified file path.final void
setBoolean
(String key, boolean value) Sets a boolean value in the YAML file.final void
setBooleanList
(String key, List<Boolean> value) Sets a list of booleans in the YAML file.void
setBooleanMap
(String key, Map<String, Boolean> map) Sets a map of boolean values in the YAML file under the specified key.final void
Sets a byte value in the YAML file.final void
setByteList
(String key, List<Byte> value) Sets a list of bytes in the YAML file.final void
Sets a char value in the YAML file.final void
setCharacterList
(String key, List<Character> value) Sets a list of characters in the YAML file.final void
Sets a double value in the YAML file.final void
setDoubleList
(String key, List<Double> value) Sets a list of doubles in the YAML file.void
setDoubleMap
(String key, Map<String, Double> map) Sets a map of double values in the YAML file under the specified key.final void
Sets an integer value in the YAML file.final void
setIntegerList
(String key, List<Integer> value) Sets a list of integers in the YAML file.void
Sets a map of integer values in the YAML file under the specified key.final void
Sets a list of values in the YAML file.final void
Sets a long value in the YAML file.final void
setLongList
(String key, List<Long> value) Sets a list of longs in the YAML file.void
Sets a map in the YAML file under the specified key.final void
Sets a short value in the YAML file.final void
setShortList
(String key, List<Short> value) Sets a list of shorts in the YAML file.final void
Sets a string value in the YAML file.final void
setStringList
(String key, List<String> value) Sets a list of strings in the YAML file.void
setStringMap
(String key, Map<String, String> map) Sets a map of string values in the YAML file under the specified key.void
Sets a value in the YAML file.
-
Constructor Details
-
YamlFile
Constructor to load a YAML file from a JAR file.- Parameters:
jarFilePath
- the path to the JAR fileinternalFilePath
- the internal path to the YAML file within the JAR
-
YamlFile
Constructor to load a YAML file from anInputStream
.- Parameters:
inputStream
- theInputStream
to load the YAML file fromfilePath
- the path to the YAML filefileName
- the name of the YAML file
-
YamlFile
Constructor to load a YAML file from aPath
.- Parameters:
path
- thePath
to the YAML file- Throws:
IOException
- if an I/O error occurs
-
YamlFile
Constructor to load a YAML file from aURL
.- Parameters:
filePath
- theURL
to the YAML file- Throws:
IOException
- if an I/O error occursURISyntaxException
- if theURL
is malformed
-
YamlFile
Constructor to load a YAML file from aURI
.- Parameters:
fileUri
- theURI
to the YAML file- Throws:
IOException
- if an I/O error occurs
-
YamlFile
Constructor to load a YAML file from aFile
.- Parameters:
file
- the YAML file- Throws:
IOException
- if an I/O error occurs
-
YamlFile
Constructor to load a YAML file from a file path.- Parameters:
filePath
- the path to the YAML file- Throws:
IOException
- if an I/O error occurs
-
-
Method Details
-
getFilePath
Returns the file path of the YAML file.- Returns:
- the file path
-
getFileName
Returns the file name of the YAML file.- Returns:
- the file name
-
save
Saves the YAML file to a specified file path.- Parameters:
path
- the path to save the YAML file to
-
save
public void save()Saves the YAML file to its original file path. -
load
Loads a YAML file from a File.- Parameters:
filePath
- the YAML file- Returns:
- the loaded YamlFile object, or null if the file does not exist
-
load
Loads a YAML file from aPath
.- Parameters:
filePath
- the path to the YAML file- Returns:
- the loaded YamlFile object
-
load
Loads a YAML file from a file path.- Parameters:
filePath
- the path to the YAML file- Returns:
- the loaded YamlFile object
-
create
Creates a new YAML file.- Parameters:
filePath
- the YAML file to create- Returns:
- the created YamlFile object, or null if the file already exists or an error occurs
-
create
Creates a new YAML file from aPath
.- Parameters:
filePath
- the path to the YAML file to create- Returns:
- the created YamlFile object
-
create
Creates a new YAML file from a file path.- Parameters:
filePath
- the path to the YAML file to create- Returns:
- the created YamlFile object
-
remove
Removes a key from the YAML file.- Parameters:
key
- the key to remove
-
setValue
Sets a value in the YAML file.- Parameters:
key
- the key to setvalue
- the value to set
-
getValue
Gets a value from the YAML file.- Parameters:
key
- the key to get- Returns:
- the value associated with the key, or null if the key does not exist
-
getAll
Returns all the data in the YAML file.- Returns:
- a map containing all the data in the YAML file
-
contains
Checks if a key exists in the YAML file.- Parameters:
key
- the key to check- Returns:
- true if the key exists, false otherwise
-
clear
public final void clear()Clears all the data in the YAML file. -
isEmpty
public final boolean isEmpty()Checks if the YAML file is empty.- Returns:
- true if the YAML file is empty, false otherwise
-
merge
Merges a map of data into the YAML file.- Parameters:
data
- the data to merge
-
merge
Merges anotherYamlFile
into this YAML file.- Parameters:
yamlFile
- theYamlFile
to merge
-
getInt
Gets an integer value from the YAML file.- Parameters:
key
- the key to get the integer value from- Returns:
- the integer value associated with the key, or 0 if the key does not exist or is not a number
-
setInt
Sets an integer value in the YAML file.- Parameters:
key
- the key to set the integer value forvalue
- the integer value to set
-
getLong
Gets a long value from the YAML file.- Parameters:
key
- the key to get the long value from- Returns:
- the long value associated with the key, or 0L if the key does not exist or is not a number
-
setLong
Sets a long value in the YAML file.- Parameters:
key
- the key to set the long value forvalue
- the long value to set
-
getShort
Gets a short value from the YAML file.- Parameters:
key
- the key to get the short value from- Returns:
- the short value associated with the key, or 0 if the key does not exist or is not a number
-
setShort
Sets a short value in the YAML file.- Parameters:
key
- the key to set the short value forvalue
- the short value to set
-
getByte
Gets a byte value from the YAML file.- Parameters:
key
- the key to get the byte value from- Returns:
- the byte value associated with the key, or 0 if the key does not exist or is not a number
-
setByte
Sets a byte value in the YAML file.- Parameters:
key
- the key to set the byte value forvalue
- the byte value to set
-
getBoolean
Gets a boolean value from the YAML file.- Parameters:
key
- the key to get the boolean value from- Returns:
- the boolean value associated with the key, or false if the key does not exist or is not a boolean
-
setBoolean
Sets a boolean value in the YAML file.- Parameters:
key
- the key to set the boolean value forvalue
- the boolean value to set
-
getDouble
Gets a double value from the YAML file.- Parameters:
key
- the key to get the double value from- Returns:
- the double value associated with the key, or 0.0 if the key does not exist or is not a number
-
setDouble
Sets a double value in the YAML file.- Parameters:
key
- the key to set the double value forvalue
- the double value to set
-
getString
Gets a string value from the YAML file.- Parameters:
key
- the key to get the string value from- Returns:
- the string value associated with the key, or null if the key does not exist or is not a string
-
setString
Sets a string value in the YAML file.- Parameters:
key
- the key to set the string value forvalue
- the string value to set
-
getChar
Gets a char value from the YAML file.- Parameters:
key
- the key to get the char value from- Returns:
- the char value associated with the key, or ' ' if the key does not exist or is not a string
-
setChar
Sets a char value in the YAML file.- Parameters:
key
- the key to set the char value forvalue
- the char value to set
-
getMapKeys
Retrieves the keys of the map stored under the specified key in the YAML file.- Parameters:
key
- the key of the map in the YAML file- Returns:
- a set containing the keys of the map, or null if the key does not exist or does not contain a map
-
getMapValues
Retrieves the values of the map stored under the specified key in the YAML file.- Parameters:
key
- the key of the map in the YAML file- Returns:
- a collection containing the values of the map, or null if the key does not exist or does not contain a map
-
setMap
Sets a map in the YAML file under the specified key.- Parameters:
key
- the key where the map should be setmap
- the map to set
-
getMap
Gets a map from the YAML file stored under the specified key.- Parameters:
key
- the key of the map to retrieve- Returns:
- the map stored under the specified key, or null if the key does not exist or does not contain a map
-
setStringMap
Sets a map of string values in the YAML file under the specified key.- Parameters:
key
- the key where the map should be setmap
- the map of string values to set
-
getStringMap
Gets a map of string values from the YAML file stored under the specified key.- Parameters:
key
- the key of the map to retrieve- Returns:
- the map of string values stored under the specified key, or null if the key does not exist or does not contain a map
-
setDoubleMap
Sets a map of double values in the YAML file under the specified key.- Parameters:
key
- the key where the map should be setmap
- the map of double values to set
-
getDoubleMap
Gets a map of double values from the YAML file stored under the specified key.- Parameters:
key
- the key of the map to retrieve- Returns:
- the map of double values stored under the specified key, or null if the key does not exist or does not contain a map
-
setIntMap
Sets a map of integer values in the YAML file under the specified key.- Parameters:
key
- the key where the map should be setmap
- the map of integer values to set
-
getIntMap
Gets a map of integer values from the YAML file stored under the specified key.- Parameters:
key
- the key of the map to retrieve- Returns:
- the map of integer values stored under the specified key, or null if the key does not exist or does not contain a map
-
setBooleanMap
Sets a map of boolean values in the YAML file under the specified key.- Parameters:
key
- the key where the map should be setmap
- the map of boolean values to set
-
getBooleanMap
Gets a map of boolean values from the YAML file stored under the specified key.- Parameters:
key
- the key of the map to retrieve- Returns:
- the map of boolean values stored under the specified key, or null if the key does not exist or does not contain a map
-
getList
Gets a list of values from the YAML file.- Parameters:
key
- the key to get the list of values from- Returns:
- the list of values associated with the key, or an empty list if the key does not exist or is not a list
-
setList
Sets a list of values in the YAML file.- Parameters:
key
- the key to set the list of values forvalue
- the list of values to set
-
getStringList
Gets a list of strings from the YAML file.- Parameters:
key
- the key to get the list of strings from- Returns:
- the list of strings associated with the key, or an empty list if the key does not exist or is not a list
-
setStringList
Sets a list of strings in the YAML file.- Parameters:
key
- the key to set the list of strings forvalue
- the list of strings to set
-
getDoubleList
Gets a list of doubles from the YAML file.- Parameters:
key
- the key to get the list of doubles from- Returns:
- the list of doubles associated with the key, or an empty list if the key does not exist or is not a list
-
setDoubleList
Sets a list of doubles in the YAML file.- Parameters:
key
- the key to set the list of doubles forvalue
- the list of doubles to set
-
getLongList
Gets a list of longs from the YAML file.- Parameters:
key
- the key to get the list of longs from- Returns:
- the list of longs associated with the key, or an empty list if the key does not exist or is not a list
-
setLongList
Sets a list of longs in the YAML file.- Parameters:
key
- the key to set the list of longs forvalue
- the list of longs to set
-
getIntegerList
Gets a list of integers from the YAML file.- Parameters:
key
- the key to get the list of integers from- Returns:
- the list of integers associated with the key, or an empty list if the key does not exist or is not a list
-
setIntegerList
Sets a list of integers in the YAML file.- Parameters:
key
- the key to set the list of integers forvalue
- the list of integers to set
-
getCharacterList
Gets a list of characters from the YAML file.- Parameters:
key
- the key to get the list of characters from- Returns:
- the list of characters associated with the key, or an empty list if the key does not exist or is not a list
-
setCharacterList
Sets a list of characters in the YAML file.- Parameters:
key
- the key to set the list of characters forvalue
- the list of characters to set
-
getBooleanList
Gets a list of booleans from the YAML file.- Parameters:
key
- the key to get the list of booleans from- Returns:
- the list of booleans associated with the key, or an empty list if the key does not exist or is not a list
-
setBooleanList
Sets a list of booleans in the YAML file.- Parameters:
key
- the key to set the list of booleans forvalue
- the list of booleans to set
-
getShortList
Gets a list of shorts from the YAML file.- Parameters:
key
- the key to get the list of shorts from- Returns:
- the list of shorts associated with the key, or an empty list if the key does not exist or is not a list
-
setShortList
Sets a list of shorts in the YAML file.- Parameters:
key
- the key to set the list of shorts forvalue
- the list of shorts to set
-
getByteList
Gets a list of bytes from the YAML file.- Parameters:
key
- the key to get the list of bytes from- Returns:
- the list of bytes associated with the key, or an empty list if the key does not exist or is not a list
-
setByteList
Sets a list of bytes in the YAML file.- Parameters:
key
- the key to set the list of bytes forvalue
- the list of bytes to set
-