gpt4 book ai didi

org.yaml.snakeyaml.Yaml.compose()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 03:54:40 27 4
gpt4 key购买 nike

本文整理了Java中org.yaml.snakeyaml.Yaml.compose()方法的一些代码示例,展示了Yaml.compose()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Yaml.compose()方法的具体详情如下:
包路径:org.yaml.snakeyaml.Yaml
类名称:Yaml
方法名:compose

Yaml.compose介绍

[英]Parse the first YAML document in a stream and produce the corresponding representation tree. (This is the opposite of the represent() method)
[中]解析流中的第一个YAML文档并生成相应的表示树。(这与represente()方法相反)

代码示例

代码示例来源:origin: org.onehippo.cms/hippo-configuration-management-model

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);
  }
}

代码示例来源:origin: RepreZen/KaiZen-OpenAPI-Editor

private Result<Node> parseYaml(String content) {
  try {
    return new Success<>(yaml.compose(new StringReader(content)));
  } catch (Exception e) {
    return new Failure<>(e);
  }
}

代码示例来源:origin: com.plausiblelabs.warwizard/warwizard-core

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();
  }
}

代码示例来源:origin: raml-org/raml-java-parser

@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);
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

/** 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;
    }
  }
}

代码示例来源:origin: com.sap.cloud.yaas.raml-parser/raml-parser

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);
  }
}

代码示例来源:origin: com.sap.cloud.yaas.raml-parser/raml-parser

Node root = yamlParser.compose(content);
if (root != null && root.getNodeId() == mapping)

代码示例来源:origin: google/cdep

@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;
 }
}

代码示例来源:origin: org.raml/raml-parser

Node root = yamlParser.compose(content);
if (root != null && root.getNodeId() == mapping)

代码示例来源:origin: org.raml/raml-parser

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);
  }
}

代码示例来源:origin: googleapis/gapic-generator

tree = new Yaml().compose(new StringReader(input));
} catch (ComposerException e) {
 helper.error(e.getProblemMark(), "Parsing error: %s", e.getMessage());

代码示例来源:origin: com.sap.cloud.yaas.raml-parser/raml-parser

NodeVisitor nodeVisitor = new NodeVisitor(this, new DefaultResourceLoader());
MappingNode rootNode = null;
Node compose = yamlParser.compose(new StringReader(suggestRaml));
if (compose != null && compose.getNodeId() == NodeId.mapping)

代码示例来源:origin: org.raml/raml-parser

NodeVisitor nodeVisitor = new NodeVisitor(this, new DefaultResourceLoader());
MappingNode rootNode = null;
Node compose = yamlParser.compose(new StringReader(suggestRaml));
if (compose != null && compose.getNodeId() == NodeId.mapping)

代码示例来源:origin: google/cdep

@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;
}

代码示例来源:origin: org.raml/raml-parser

includeNode = yamlParser.compose(reader);

代码示例来源:origin: com.google.api/api-compiler

Node tree;
try {
 tree = YAML.compose(new StringReader(input));
} catch (ComposerException e) {
 helper.error(e.getProblemMark(), "Parsing error: %s", e.getMessage());

代码示例来源:origin: googleapis/api-compiler

Node tree;
try {
 tree = YAML.compose(new StringReader(input));
} catch (ComposerException e) {
 helper.error(e.getProblemMark(), "Parsing error: %s", e.getMessage());

代码示例来源:origin: com.sap.cloud.yaas.raml-parser/raml-parser

includeNode = yamlParser.compose(new InputStreamReader(inputStream));

代码示例来源:origin: nielsbasjes/yauaa

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);

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com