protected Node composeYamlNode(final InputStream inputStream, final String location) throws ParserException { log.debug("Parsing YAML source '{}'", location); final Yaml yamlParser = new Yaml(); try { return yamlParser.compose(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); } catch (RuntimeException e) { final String message = String.format("Failed to parse YAML source '%s'", location); throw new ParserException(message, e); } }
private Result<Node> parseYaml(String content) { try { return new Success<>(yaml.compose(new StringReader(content))); } catch (Exception e) { return new Failure<>(e); } }
JsonNode convert(Reader reader, String location) throws IOException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); final JsonGenerator generator = factory.createJsonGenerator(output).useDefaultPrettyPrinter(); try { final Node yaml = new org.yaml.snakeyaml.Yaml().compose(reader); build(yaml, generator); generator.close(); LOG.debug("Parsed {} as:\n {}", location, output.toString()); return json.readValue(output.toByteArray(), JsonNode.class); } finally { reader.close(); } }
@Nullable public static Node parse(ResourceLoader resourceLoader, String resourcePath, Reader reader) { try { Yaml yamlParser = new Yaml(); org.yaml.snakeyaml.nodes.Node composedNode = yamlParser.compose(reader); if (composedNode == null) { return null; } else { return new SYModelWrapper(resourceLoader, resourcePath).wrap(composedNode); } } catch (final MarkedYAMLException e) { return buildYamlErrorNode(e, resourcePath); } }
/** Given a path, where each segment consists of a string (key) or number (element in list), * this will find the YAML text for that element * <p> * If not found this will return a {@link YamlExtract} * where {@link YamlExtract#isMatch()} is false and {@link YamlExtract#getError()} is set. */ public static YamlExtract getTextOfYamlAtPath(String yaml, Object ...path) { YamlExtract result = new YamlExtract(); if (yaml==null) return result; try { int pathIndex = 0; result.yaml = yaml; result.focus = newYaml().compose(new StringReader(yaml)); findTextOfYamlAtPath(result, pathIndex, path); return result; } catch (NoSuchMethodError e) { throw new IllegalStateException("Class version error. This can happen if using a TestNG plugin in your IDE " + "which is an older version, dragging in an older version of SnakeYAML which does not support Mark.getIndex.", e); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.debug("Unable to find element in yaml (setting in result): "+e); result.error = e; return result; } } }
public T build(Reader content, String resourceLocation) { try { Yaml yamlParser = new Yaml(); NodeVisitor nodeVisitor = new NodeVisitor(this, resourceLoader, tagResolvers); rootNode = (MappingNode) yamlParser.compose(content); contextPath.pushRoot(resourceLocation); preBuildProcess(); nodeVisitor.visitDocument(rootNode); postBuildProcess(); return documentObject; } finally { IOUtils.closeQuietly(content); } }
Node root = yamlParser.compose(content); if (root != null && root.getNodeId() == mapping)
@NotNull public static CDepYml fromString(@NotNull String url, @NotNull String content) { if (Invariant.errorsInScope() > 0) { return new CDepYml(); } Invariant.registerYamlFile(url); Yaml yaml = new Yaml(new Constructor(CDepYml.class)); byte[] bytes = content.getBytes(StandardCharsets.UTF_8); CDepYml cdepYml = (CDepYml) yaml.load(new ByteArrayInputStream(bytes)); require(cdepYml != null, "cdep.yml was empty"); if (Invariant.errorsInScope() > 0) { return new CDepYml(); } assert cdepYml != null; Node node = yaml.compose(new InputStreamReader(new ByteArrayInputStream(bytes))); SnakeYmlUtils.mapAndRegisterNodes(url, cdepYml, node); return cdepYml; } }
Node root = yamlParser.compose(content); if (root != null && root.getNodeId() == mapping)
public T build(Reader content, String resourceLocation) { if (content == null) { throw new ResourceNotFoundException(resourceLocation); } try { Yaml yamlParser = new Yaml(); NodeVisitor nodeVisitor = new NodeVisitor(this, resourceLoader, tagResolvers); rootNode = (MappingNode) yamlParser.compose(content); contextPath.pushRoot(resourceLocation); preBuildProcess(); nodeVisitor.visitDocument(rootNode); postBuildProcess(); return documentObject; } finally { IOUtils.closeQuietly(content); } }
tree = new Yaml().compose(new StringReader(input)); } catch (ComposerException e) { helper.error(e.getProblemMark(), "Parsing error: %s", e.getMessage());
NodeVisitor nodeVisitor = new NodeVisitor(this, new DefaultResourceLoader()); MappingNode rootNode = null; Node compose = yamlParser.compose(new StringReader(suggestRaml)); if (compose != null && compose.getNodeId() == NodeId.mapping)
NodeVisitor nodeVisitor = new NodeVisitor(this, new DefaultResourceLoader()); MappingNode rootNode = null; Node compose = yamlParser.compose(new StringReader(suggestRaml)); if (compose != null && compose.getNodeId() == NodeId.mapping)
@NotNull public static CDepManifestYml convertStringToManifest(@NotNull String url, @NotNull String content) { Invariant.registerYamlFile(url); Yaml yaml = new Yaml(new Constructor(CDepManifestYml.class)); CDepManifestYml manifest; byte[] bytes = content.getBytes(StandardCharsets.UTF_8); try { manifest = (CDepManifestYml) yaml.load(new ByteArrayInputStream(bytes)); // Try to read current version if (manifest != null) { manifest.sourceVersion = CDepManifestYmlVersion.vlatest; } } catch (YAMLException e) { try { manifest = V3Reader.convertStringToManifest(content); } catch (YAMLException e2) { if (!tryCreateSensibleParseError(e, 0)) { // If older readers also couldn't read it then report the original exception. require(false, e.toString()); } return new CDepManifestYml(EMPTY_COORDINATE); } } require(manifest != null, "Manifest was empty"); assert manifest != null; manifest = new ConvertNullToDefaultRewriter().visitCDepManifestYml(manifest); Node nodes = yaml.compose(new InputStreamReader(new ByteArrayInputStream(bytes))); SnakeYmlUtils.mapAndRegisterNodes(url, manifest, nodes); return manifest; }
includeNode = yamlParser.compose(reader);
Node tree; try { tree = YAML.compose(new StringReader(input)); } catch (ComposerException e) { helper.error(e.getProblemMark(), "Parsing error: %s", e.getMessage());
Node tree; try { tree = YAML.compose(new StringReader(input)); } catch (ComposerException e) { helper.error(e.getProblemMark(), "Parsing error: %s", e.getMessage());
includeNode = yamlParser.compose(new InputStreamReader(inputStream));
private void loadResource(Yaml yaml, InputStream yamlStream, String filename) { Node loadedYaml; try { loadedYaml = yaml.compose(new UnicodeReader(yamlStream)); } catch (Exception e) { throw new InvalidParserConfigurationException("Parse error in the file " + filename + ": " + e.getMessage(), e);