From 9a60a80d2bc3493c2115fe0ce575fd5b84f89128 Mon Sep 17 00:00:00 2001 From: amihaiemil Date: Wed, 24 Apr 2024 16:23:00 +0300 Subject: [PATCH] YamlInput.readYamlNode --- .../java/com/amihaiemil/eoyaml/YamlInput.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/amihaiemil/eoyaml/YamlInput.java b/src/main/java/com/amihaiemil/eoyaml/YamlInput.java index b0e07e30..297888b3 100644 --- a/src/main/java/com/amihaiemil/eoyaml/YamlInput.java +++ b/src/main/java/com/amihaiemil/eoyaml/YamlInput.java @@ -99,4 +99,20 @@ public interface YamlInput { * @throws IOException if the input cannot be read for some reason */ Scalar readLiteralBlockScalar() throws IOException; + + /** + * Read the given input as a generic YamlNode. + * @return YamlNode. + * @throws IOException If something goes wrong. + */ + default YamlNode readYamlNode() throws IOException { + final YamlNode document; + final YamlStream stream = this.readYamlStream(); + if(stream.values().size() == 1) { + document = stream.iterator().next(); + } else { + document = stream; + } + return document; + } }