public class KeyValue extends Object
| Modifier and Type | Field and Description |
|---|---|
private List<KeyValue> |
children
Gets the children of this instance.
|
static KeyValue |
Invalid
Represents an invalid
KeyValue given when a searched for child does not exist. |
String |
name
Gets or sets the name of this instance.
|
String |
value
Gets or sets the value of this instance.
|
| Constructor and Description |
|---|
KeyValue() |
KeyValue(String name) |
KeyValue(String name,
String value)
Initializes a new instance of the
KeyValue class. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
asBoolean()
Attempts to convert and return the value of this instance as a boolean.
|
float |
asFloat() |
float |
asFloat(float defaultValue)
Attempts to convert and return the value of this instance as a float.
|
int |
asInteger() |
int |
asInteger(int defaultValue)
Attempts to convert and return the value of this instance as an integer.
|
long |
asLong() |
long |
asLong(long defaultValue)
Attempts to convert and return the value of this instance as a long.
|
String |
asString()
Returns the value of this instance as a string.
|
KeyValue |
get(String key)
Gets the child
KeyValue with the specified key. |
static KeyValue |
loadAsBinary(String path)
Attempts to load the given filename as a binary
KeyValue. |
static KeyValue |
loadAsText(String path)
Attempts to load the given filename as a text
KeyValue. |
(package private) static KeyValue |
loadFromFile(String path,
boolean asBinary) |
static KeyValue |
loadFromString(String input)
Attempts to create an instance of
KeyValue from the given input text. |
boolean |
readAsBinary(BinaryReader input)
Populate this instance from the given
BinaryReader as a binary KeyValue. |
boolean |
readAsText(InputStream input)
Populate this instance from the given
InputStream as a text KeyValue. |
boolean |
readFileAsText(String filename)
Opens and reads the given filename as text.
|
static String |
readNullTermString(InputStream in) |
void |
recursiveLoadFromBuffer(KVTextReader kvr) |
private void |
recursiveSaveToFile(FileOutputStream f) |
private void |
recursiveSaveToFile(FileOutputStream f,
int indentLevel) |
void |
saveToFile(String path,
boolean asBinary)
Saves this instance to file.
|
String |
toString()
Returns a
String that represents this instance. |
private void |
writeIndents(FileOutputStream f,
int indentLevel) |
private static void |
writeString(FileOutputStream f,
String str) |
private static void |
writeString(FileOutputStream f,
String str,
boolean quote) |
public static final KeyValue Invalid
KeyValue given when a searched for child does not exist.public String name
public String value
public KeyValue(String name, String value)
KeyValue class.name - The optional name of the root key.value - The optional value assigned to the root key.public KeyValue(String name)
public KeyValue()
public String asString()
public int asInteger(int defaultValue)
defaultValue - The default value to return if the conversion is invalid.public int asInteger()
public long asLong(long defaultValue)
defaultValue - The default value to return if the conversion is invalid.public long asLong()
public float asFloat(float defaultValue)
defaultValue - The default value to return if the conversion is invalid.public float asFloat()
public boolean asBoolean()
public static KeyValue loadAsText(String path)
KeyValue.
This method will swallow any exceptions that occur when reading, use readFileAsText(String) if you wish to handle exceptions.path - The path to the file to load.KeyValue instance if the load was successful, or null on failure.public static KeyValue loadAsBinary(String path)
KeyValue.
This method will swallow any exceptions that occur when reading, use readAsBinary(BinaryReader) if you wish to handle exceptions.path - The path to the file to load.KeyValue instance if the load was successful, or null on failure.public static KeyValue loadFromString(String input)
KeyValue from the given input text.
This method will swallow any exceptions that occur when reading, use readAsText(InputStream) if you wish to handle exceptions.input - The input text to load.KeyValue instance if the load was successful, or null on failure.public boolean readAsText(InputStream input) throws IOException
InputStream as a text KeyValue.input - The input InputStream to read from.IOExceptionpublic boolean readFileAsText(String filename) throws FileNotFoundException, IOException
filename - The file to open and read.{@link - FileNotFoundException} , IOExceptionFileNotFoundExceptionIOExceptionpublic void recursiveLoadFromBuffer(KVTextReader kvr) throws IOException
IOExceptionpublic void saveToFile(String path, boolean asBinary)
path - The file path to save to.asBinary - If set to true, saves this instance as binary.private void recursiveSaveToFile(FileOutputStream f) throws IOException
IOExceptionprivate void recursiveSaveToFile(FileOutputStream f, int indentLevel) throws IOException
IOExceptionprivate void writeIndents(FileOutputStream f, int indentLevel) throws IOException
IOExceptionprivate static void writeString(FileOutputStream f, String str, boolean quote) throws IOException
IOExceptionprivate static void writeString(FileOutputStream f, String str) throws IOException
IOExceptionpublic static String readNullTermString(InputStream in) throws IOException
IOExceptionpublic boolean readAsBinary(BinaryReader input) throws IOException
BinaryReader as a binary KeyValue.input - The input BinaryReader to read from.IOExceptionCopyright © 2012. All Rights Reserved.