- Enclosing class:
- JSUtilities
Unlike JSON, YAML allows a sequence of objects to be read from a
single stream, with objects' YAML representation separated by
a line starting with "---" (such streams must start with the
line "%YAML VERSION" followed by some optional tag definitions,
and the sequence "---" at the start of a line). This class does
not support this particular case: instead use
JSUtilities.YAML.Parser
to handle multiple independent
objects
It is possible to automatically convert strings to various
data types. A few standard conversions are build in. These
can be extended by creating instances of
JSUtilities.YAML.TagSpec
, and using that in a suitable
constructor as described below.
The YAML parser will throw an exception if the input stream
contains tabs (the YAML specification does not allow tabs).
If one needs to handle files with tabs, the class
DetabReader
can be used to turn those
tabs into the appropriate number of spaces.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Parser support class for YAML.static class
YAML tag for additional data types. -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
parse
(char[] buffer) YAML parser that reads YAML-formated text from a character array.static Object
parse
(InputStream is, String charsetName) YAML parser that reads YAML-formatted text from anInputStream
given aString
providing the name of a character set.static Object
parse
(InputStream is, Charset cs) YAML parser that reads YAML-formatted text from anInputStream
given aCharset
.static Object
parse
(InputStream is, CharsetDecoder dec) YAML parser that reads YAML-formatted text from anInputStream
given aCharsetDecoder
.static Object
YAML parser that reads YAML-formated text from aReader
.static Object
YAML parser that reads YAML-formated text from aString
.
-
Method Details
-
parse
public static Object parse(InputStream is, String charsetName) throws IOException, UnsupportedEncodingException YAML parser that reads YAML-formatted text from anInputStream
given aString
providing the name of a character set. The result's type, if the result is not null, is eitherJSObject
,JSArray
,String
,Number
, orBoolean
.- Parameters:
is
- the input stream (containing a YAML value)charsetName
- the name of the charset used by the input stream- Returns:
- the object created
- Throws:
IOException
- an error occurred while reading from the input streamUnsupportedEncodingException
- the charsetName does not match a known charset
-
parse
YAML parser that reads YAML-formatted text from anInputStream
given aCharsetDecoder
. The result's type, if the result is not null, is eitherJSObject
,JSArray
,String
,Number
, orBoolean
.- Parameters:
is
- the input stream (containing a YAML value)dec
- the charset decoder used to turn the input stream into a sequence of characters- Returns:
- the object created
- Throws:
IOException
- an error occurred while reading from the input stream
-
parse
YAML parser that reads YAML-formatted text from anInputStream
given aCharset
. The result's type, if the result is not null, is eitherJSObject
,JSArray
,String
,Number
, orBoolean
.- Parameters:
is
- the input stream (containing a YAML value)cs
- the charset for the input stream- Returns:
- the object created
- Throws:
IOException
- an error occurred while reading from the input stream
-
parse
YAML parser that reads YAML-formated text from a character array. The result's type, if the result is not null, is eitherJSObject
,JSArray
,String
,Number
, orBoolean
.- Parameters:
buffer
- the input character sequence (containing a YAML value)- Returns:
- the object created
- Throws:
IOException
- an error occurred while reading from the input stream
-
parse
YAML parser that reads YAML-formated text from aString
. The result's type, if the result is not null, is eitherJSObject
,JSArray
,String
,Number
, orBoolean
.- Parameters:
s
- the input string (containing a YAML value)- Returns:
- the object created
- Throws:
IOException
- an error occurred while reading from the input stream
-
parse
YAML parser that reads YAML-formated text from aReader
. The result's type, if the result is not null, is eitherJSObject
,JSArray
,String
,Number
, orBoolean
.- Parameters:
r
- the reader- Returns:
- the object created
- Throws:
IOException
- an error occurred while reading from the input stream
-