public class YAMLProcessor extends YAMLNode
For example, given the following configuration file:
members: - Hollie - Jason - Bobo - Aya - Tetsu worldguard: fire: spread: false blocks: [cloth, rock, glass] sturmeh: cool: false eats: babies: true
Calling code could access sturmeh's baby eating state by using
getBoolean("sturmeh.eats.babies", false)
. For lists, there are
methods such as getStringList
that will return a type safe list.
Modifier and Type | Field and Description |
---|---|
static char |
COMMENT_CHAR |
protected java.io.File |
file |
protected YAMLFormat |
format |
protected java.lang.String |
header |
static java.lang.String |
LINE_BREAK |
protected org.yaml.snakeyaml.Yaml |
yaml |
Constructor and Description |
---|
YAMLProcessor(java.io.File file,
boolean writeDefaults) |
YAMLProcessor(java.io.File file,
boolean writeDefaults,
YAMLFormat format) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getComment(java.lang.String key)
Returns a root-level comment.
|
java.util.Map<java.lang.String,java.lang.String> |
getComments()
Returns root-level comments.
|
static YAMLNode |
getEmptyNode(boolean writeDefaults)
Get an empty ConfigurationNode for using as a default in methods that
select a node from a node list.
|
java.lang.String |
getHeader()
Return the set header.
|
java.io.InputStream |
getInputStream() |
java.io.OutputStream |
getOutputStream() |
void |
load()
Loads the configuration file.
|
boolean |
save()
Saves the configuration to disk.
|
void |
setComment(java.lang.String key,
java.lang.String... comment)
Set a root-level comment.
|
void |
setComment(java.lang.String key,
java.lang.String comment) |
void |
setComments(java.util.Map<java.lang.String,java.lang.String> comments)
Set root-level comments from a map.
|
void |
setHeader(java.lang.String... headerLines)
Set the header for the file as a series of lines that are terminated
by a new line sequence.
|
void |
setHeader(java.lang.String header)
Set the header for the file.
|
addNode, clear, getBlockVector2List, getBoolean, getBoolean, getBooleanList, getDouble, getDouble, getDoubleList, getInt, getInt, getIntList, getKeys, getList, getMap, getNode, getNodeList, getNodes, getProperty, getString, getString, getStringList, getVector, getVector, getVector2, getVector2List, getVectorList, removeProperty, setProperty, setWriteDefaults, writeDefaults
public static final java.lang.String LINE_BREAK
public static final char COMMENT_CHAR
protected final org.yaml.snakeyaml.Yaml yaml
protected final java.io.File file
protected java.lang.String header
protected YAMLFormat format
public YAMLProcessor(java.io.File file, boolean writeDefaults, YAMLFormat format)
public YAMLProcessor(java.io.File file, boolean writeDefaults)
public void load() throws java.io.IOException
java.io.IOException
- on load errorpublic void setHeader(java.lang.String... headerLines)
headerLines
- header lines to prependpublic void setHeader(java.lang.String header)
header
- header to prependpublic java.lang.String getHeader()
public boolean save()
public java.io.InputStream getInputStream() throws java.io.IOException
java.io.IOException
public java.io.OutputStream getOutputStream() throws java.io.IOException
java.io.IOException
public java.lang.String getComment(java.lang.String key)
key
- the property keynull
public void setComment(java.lang.String key, java.lang.String comment)
public void setComment(java.lang.String key, java.lang.String... comment)
key
- the property keycomment
- the comment. May be null
, in which case the comment
is removed.public java.util.Map<java.lang.String,java.lang.String> getComments()
public void setComments(java.util.Map<java.lang.String,java.lang.String> comments)
comments
- comment mappublic static YAMLNode getEmptyNode(boolean writeDefaults)
writeDefaults
- true to write default values when a property is
requested that doesn't exist