protected List<Event> canonicalParse(InputStream input2) throws IOException { StreamReader reader = new StreamReader(new UnicodeReader(input2)); StringBuilder buffer = new StringBuilder(); while (reader.peek() != '\0') { buffer.append(reader.peek()); reader.forward(); } CanonicalParser parser = new CanonicalParser(buffer.toString()); List<Event> result = new ArrayList<Event>(); while (parser.peekEvent() != null) { result.add(parser.getEvent()); } input2.close(); return result; }
protected List<Event> parse(InputStream input) throws IOException { StreamReader reader = new StreamReader(new UnicodeReader(input)); Parser parser = new ParserImpl(reader); List<Event> result = new ArrayList<Event>(); while (parser.peekEvent() != null) { result.add(parser.getEvent()); } input.close(); return result; }
private List<Node> compose_all(InputStream file) { Composer composer = new Composer(new ParserImpl(new StreamReader(new UnicodeReader(file))), new Resolver()); List<Node> documents = new ArrayList<Node>(); while (composer.checkNode()) { documents.add(composer.getNode()); } return documents; }
private void loadResource(Yaml yaml, InputStream yamlStream, String filename) { Node loadedYaml = yaml.compose(new UnicodeReader(yamlStream)); if (loadedYaml == null) { throw new InvalidParserConfigurationException("The file " + filename + " is empty"); } // Get and check top level config if (!(loadedYaml instanceof MappingNode)) { fail(loadedYaml, filename, "File must be a Map"); } MappingNode rootNode = (MappingNode) loadedYaml; NodeTuple configNodeTuple = null; for (NodeTuple tuple : rootNode.getValue()) { String name = getKeyAsString(tuple, filename); if ("config".equals(name)) { configNodeTuple = tuple; break; } } if (configNodeTuple == null) { fail(loadedYaml, filename, "The top level entry MUST be 'config'."); } SequenceNode configNode = getValueAsSequenceNode(configNodeTuple, filename); List<Node> configList = configNode.getValue(); for (Node configEntry : configList) { if (!(configEntry instanceof MappingNode)) { fail(loadedYaml, filename, "The entry MUST be a mapping"); } NodeTuple entry = getExactlyOneNodeTuple((MappingNode) configEntry, filename); MappingNode actualEntry = getValueAsMappingNode(entry, filename); String entryType = getKeyAsString(entry, filename); switch (entryType) { case "lookup": loadYamlLookup(actualEntry, filename); break; case "set": loadYamlLookupSets(actualEntry, filename); break; case "matcher": loadYamlMatcher(actualEntry, filename); break; case "test": if (loadTests) { loadYamlTestcase(actualEntry, filename); } break; default: throw new InvalidParserConfigurationException( "Yaml config.(" + filename + ":" + actualEntry.getStartMark().getLine() + "): " + "Found unexpected config entry: " + entryType + ", allowed are 'lookup', 'set', 'matcher' and 'test'"); } } }
/** * Get {@link Properties} for a given {@code inputStream} treating it as a YAML file. * * @param inputStream input stream representing YAML file * @return properties representing values from {@code inputStream} * @throws IllegalStateException when unable to read properties */ @Override public Properties getProperties(InputStream inputStream) { requireNonNull(inputStream); Yaml yaml = new Yaml(); Properties properties = new Properties(); try (Reader reader = new UnicodeReader(inputStream)) { Object object = yaml.load(reader); if (object != null) { Map<String, Object> yamlAsMap = convertToMap(object); properties.putAll(flatten(yamlAsMap)); } return properties; } catch (IOException | ScannerException e) { throw new IllegalStateException("Unable to load yaml configuration from provided stream", e); } }
public static <T> T read(InputStream is, Class<T> type) { return read(new UnicodeReader(is), type); }
/** * Parse the only YAML document in a stream and produce the corresponding * Java object. * * @param <T> * Class is defined by the second argument * @param input * data to load from (BOM is respected and removed) * @param type * Class of the object to be created * * @return parsed object */ @SuppressWarnings("unchecked") @Nullable public <T> T fromYaml(InputStream input, Class<T> type) { return (T) this.loadFromReader(new StreamReader(new UnicodeReader(input)), type); }
private List<Node> canonical_compose_all(InputStream file) { StreamReader reader = new StreamReader(new UnicodeReader(file)); StringBuilder buffer = new StringBuilder(); while (reader.peek() != '\0') { buffer.append(reader.peek()); reader.forward(); } CanonicalParser parser = new CanonicalParser(buffer.toString()); Composer composer = new Composer(parser, new Resolver()); List<Node> documents = new ArrayList<Node>(); while (composer.checkNode()) { documents.add(composer.getNode()); } return documents; }
private boolean process(MatchCallback callback, Yaml yaml, Resource resource) { int count = 0; try { if (logger.isDebugEnabled()) { logger.debug("Loading from YAML: " + resource); } Reader reader = new UnicodeReader(resource.getInputStream()); try { for (Object object : yaml.loadAll(reader)) { if (object != null && process(asMap(object), callback)) { count++; if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND) { break; } } } if (logger.isDebugEnabled()) { logger.debug("Loaded " + count + " document" + (count > 1 ? "s" : "") + " from YAML resource: " + resource); } } finally { reader.close(); } } catch (IOException ex) { handleProcessError(resource, ex); } return (count > 0); }
/** * Parse the only YAML document in a stream and produce the corresponding * Java object. * * @param io * data to load from (BOM is respected and removed) * @return parsed object */ public Object load(InputStream io) { return loadFromReader(new StreamReader(new UnicodeReader(io)), Object.class); }
/** * Parse the only YAML document in a stream and produce the corresponding * Java object. * * @param <T> * Class is defined by the second argument * @param input * data to load from (BOM is respected and removed) * @param type * Class of the object to be created * @return parsed object */ @SuppressWarnings("unchecked") public <T> T loadAs(InputStream input, Class<T> type) { return (T) loadFromReader(new StreamReader(new UnicodeReader(input)), type); }
/** * Parse all YAML documents in a stream and produce corresponding Java * objects. The documents are parsed only when the iterator is invoked. * * @param yaml * YAML data to load from (BOM is respected and ignored) * @return an iterator over the parsed Java objects in this stream in proper * sequence */ public Iterable<Object> loadAll(InputStream yaml) { return loadAll(new UnicodeReader(yaml)); }
/** * Parse the only YAML document in a stream and produce the corresponding * Java object. * * @param io * data to load from (BOM is respected and removed) * * @return parsed object */ public Object fromYaml(InputStream io) { return this.loadFromReader(new StreamReader(new UnicodeReader(io)), Object.class); }
/** * Parse the only YAML document in a stream and produce the corresponding * Java object. * * @param <T> * Class is defined by the second argument * @param input * data to load from (BOM is respected and removed) * @param type * Class of the object to be created * * @return parsed object */ @SuppressWarnings("unchecked") public <T> T fromYaml(InputStream input, Class<T> type) { return (T) this.loadFromReader(new StreamReader(new UnicodeReader(input)), type); }
/** * Parse all YAML documents in a stream and produce corresponding Java * objects. The documents are parsed only when the iterator is invoked. * * @param yaml * YAML data to load from (BOM is respected and ignored) * * @return an iterator over the parsed Java objects in this stream in proper sequence */ public Iterable<Object> fromAllYaml(InputStream yaml) { return this.fromAllYaml(new UnicodeReader(yaml)); }
/** * Parse the first YAML document in a stream and produce the corresponding * JavaBean. * * @param io * data to load from (BOM is respected and removed) * @return parsed JavaBean */ @SuppressWarnings("unchecked") public T load(InputStream io) { return (T) loader.load(new UnicodeReader(io)); }
/** * Parse the first YAML document in a stream and produce the corresponding JavaBean. * * @param io * data to load from (BOM is respected and removed) * @return parsed JavaBean */ @SuppressWarnings("unchecked") public T load(final InputStream io) { return (T) loader.load(new UnicodeReader(io)); }
/** * Parse the only YAML document in a stream and produce the corresponding Java object. * * @param io * data to load from (BOM is respected and removed) * @return parsed object */ public Object load(final InputStream io) { return loadFromReader(new StreamReader(new UnicodeReader(io)), Object.class); }
/** * Parse the only YAML document in a stream and produce the corresponding Java object. * * @param <T> * Class is defined by the second argument * @param input * data to load from (BOM is respected and removed) * @param type * Class of the object to be created * @return parsed object */ @SuppressWarnings("unchecked") public <T> T loadAs(final InputStream input, final Class<T> type) { return (T) loadFromReader(new StreamReader(new UnicodeReader(input)), type); }
/** * Parse all YAML documents in a stream and produce corresponding Java objects. The documents are parsed only when the iterator is * invoked. * * @param yaml * YAML data to load from (BOM is respected and ignored) * @return an iterator over the parsed Java objects in this stream in proper sequence */ public Iterable<Object> loadAll(final InputStream yaml) { return loadAll(new UnicodeReader(yaml)); }
/** * Parse the only YAML document in a stream and produce the corresponding * Java object. * * @param io * data to load from (BOM is respected and removed) * * @return parsed object */ @Nullable public Object fromYaml(InputStream io) { return this.loadFromReader(new StreamReader(new UnicodeReader(io)), Object.class); }