[Q] JvYAML and non-ASCII characters
"Makoto Kuwata" <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I have questions about JvYAML 0.2.1.
Q1.
YAML.load(Reader) throws Exception when non-ASCII characters found,
but YAML.load(String) doesn't.
Why the former throws exception? I hope that YAML.load(Reader) to be
able to handle non-ASCII characters.
/* YAML.load(Reader) throws exception */
InputStream inputStream = new FileInputStream("example.yaml");
Reader reader = new InputStreamReader(inputStream, "UTF-8");
Object ydoc = YAML.load(reader);
// Exception in thread "main" org.jvyaml.YAMLException: At 8 we
found: ### Special characters are not allowed
// at org.jvyaml.ScannerImpl.checkPrintable(ScannerImpl.java:282)
// ....
/* YAML.load(String) doesn't throw exception */
InputStream inputStream = new FileInputStream("example.yaml");
Reader reader = new InputStreamReader(inputStream, "UTF-8");
StringBuffer buf = new StringBuffer();
int ch;
while ((ch = reader.read()) >= 0)
buf.append((char)ch);
Object ydoc = YAML.load(buf.toString());
Q2.
YAML.dump(Object) throws exception when non-ASCII characters.
Is there any solution to handle non-ASCII characters, such as
allow_unicode=True in PyYAML?
/* YAML.dump(String) throws exception */
String s = "\u65e5\u672c\u8a9e";
System.out.println(YAML.dump(s));
// Exception in thread "main" org.jvyaml.EmitterException:
expected NodeEvent, but got #<org.jvyaml.events.StreamEndEvent>
// at
org.jvyaml.EmitterImpl$EmitterEnvironment.expectNode(EmitterImpl.java:580)
// at
org.jvyaml.EmitterImpl$EmitterEnvironment.expectDocumentRoot(EmitterImpl.java:394)
// ....
--
regards,
makoto kuwata
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/