org.yaml.snakeyaml.parser.ParserImpl Java Examples

The following examples show how to use org.yaml.snakeyaml.parser.ParserImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Yaml.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parse a YAML stream and produce parsing events.
 *
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
 * @param yaml
 *            YAML document(s)
 * @return parsed events
 */
public Iterable<Event> parse(Reader yaml) {
    final Parser parser = new ParserImpl(new StreamReader(yaml));
    Iterator<Event> result = new Iterator<Event>() {
        public boolean hasNext() {
            return parser.peekEvent() != null;
        }

        public Event next() {
            return parser.getEvent();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new EventIterable(result);
}
 
Example #2
Source File: Yaml.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parse all YAML documents in a String and produce corresponding Java
 * objects. The documents are parsed only when the iterator is invoked.
 * 
 * @param yaml
 *            YAML data to load from (BOM must not be present)
 * @return an iterator over the parsed Java objects in this String in proper
 *         sequence
 */
public Iterable<Object> loadAll(Reader yaml) {
    Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
    constructor.setComposer(composer);
    Iterator<Object> result = new Iterator<Object>() {
        public boolean hasNext() {
            return constructor.checkData();
        }

        public Object next() {
            return constructor.getData();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new YamlIterable(result);
}
 
Example #3
Source File: Yaml.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parse all YAML documents in a stream and produce corresponding
 * representation trees.
 *
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
 * @param yaml
 *            stream of YAML documents
 * @return parsed root Nodes for all the specified YAML documents
 */
public Iterable<Node> composeAll(Reader yaml) {
    final Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
    constructor.setComposer(composer);
    Iterator<Node> result = new Iterator<Node>() {
        public boolean hasNext() {
            return composer.checkNode();
        }

        public Node next() {
            return composer.getNode();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new NodeIterable(result);
}
 
Example #4
Source File: Yaml.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parse all YAML documents in a stream and produce corresponding
 * representation trees.
 * 
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
 * @param yaml
 *            stream of YAML documents
 * @return parsed root Nodes for all the specified YAML documents
 */
public Iterable<Node> composeAll(Reader yaml) {
    final Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
    constructor.setComposer(composer);
    Iterator<Node> result = new Iterator<Node>() {
        public boolean hasNext() {
            return composer.checkNode();
        }

        public Node next() {
            return composer.getNode();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new NodeIterable(result);
}
 
Example #5
Source File: Yaml.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parse a YAML stream and produce parsing events.
 * 
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
 * @param yaml
 *            YAML document(s)
 * @return parsed events
 */
public Iterable<Event> parse(Reader yaml) {
    final Parser parser = new ParserImpl(new StreamReader(yaml));
    Iterator<Event> result = new Iterator<Event>() {
        public boolean hasNext() {
            return parser.peekEvent() != null;
        }

        public Event next() {
            return parser.getEvent();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new EventIterable(result);
}
 
Example #6
Source File: Yaml.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parse all YAML documents in a String and produce corresponding Java
 * objects. The documents are parsed only when the iterator is invoked.
 *
 * @param yaml
 *            YAML data to load from (BOM must not be present)
 * @return an iterator over the parsed Java objects in this String in proper
 *         sequence
 */
public Iterable<Object> loadAll(Reader yaml) {
    Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
    constructor.setComposer(composer);
    Iterator<Object> result = new Iterator<Object>() {
        public boolean hasNext() {
            return constructor.checkData();
        }

        public Object next() {
            return constructor.getData();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new YamlIterable(result);
}
 
Example #7
Source File: Yaml.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
/**
 * Parse all YAML documents in a String and produce corresponding Java
 * objects. The documents are parsed only when the iterator is invoked.
 * 
 * @param yaml
 *            YAML data to load from (BOM must not be present)
 * @return an iterator over the parsed Java objects in this String in proper
 *         sequence
 */
public Iterable<Object> loadAll(Reader yaml) {
    Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
    constructor.setComposer(composer);
    Iterator<Object> result = new Iterator<Object>() {
        public boolean hasNext() {
            return constructor.checkData();
        }

        public Object next() {
            return constructor.getData();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new YamlIterable(result);
}
 
Example #8
Source File: Yaml.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
/**
 * Parse all YAML documents in a stream and produce corresponding
 * representation trees.
 * 
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
 * @param yaml
 *            stream of YAML documents
 * @return parsed root Nodes for all the specified YAML documents
 */
public Iterable<Node> composeAll(Reader yaml) {
    final Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
    constructor.setComposer(composer);
    Iterator<Node> result = new Iterator<Node>() {
        public boolean hasNext() {
            return composer.checkNode();
        }

        public Node next() {
            return composer.getNode();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new NodeIterable(result);
}
 
Example #9
Source File: Yaml.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
/**
 * Parse a YAML stream and produce parsing events.
 * 
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
 * @param yaml
 *            YAML document(s)
 * @return parsed events
 */
public Iterable<Event> parse(Reader yaml) {
    final Parser parser = new ParserImpl(new StreamReader(yaml));
    Iterator<Event> result = new Iterator<Event>() {
        public boolean hasNext() {
            return parser.peekEvent() != null;
        }

        public Event next() {
            return parser.getEvent();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new EventIterable(result);
}
 
Example #10
Source File: YamlUtils.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
public static Node read(YamlSource source, Reader reader, ConfigurationContext context) throws IOException {
    LoaderOptions loaderOptions = new LoaderOptions();
    loaderOptions.setMaxAliasesForCollections(context.getYamlMaxAliasesForCollections());
    Composer composer = new Composer(
        new ParserImpl(new StreamReaderWithSource(source, reader)),
        new Resolver(),
        loaderOptions);
    try {
        return composer.getSingleNode();
    } catch (YAMLException e) {
        if (e.getMessage().startsWith("Number of aliases for non-scalar nodes exceeds the specified max")) {
            throw new ConfiguratorException(String.format(
                "%s%nYou can increase the maximum by setting an environment variable or property%n  ENV: %s=\"100\"%n  PROPERTY: -D%s=\"100\"",
                e.getMessage(), ConfigurationContext.CASC_YAML_MAX_ALIASES_ENV,
                ConfigurationContext.CASC_YAML_MAX_ALIASES_PROPERTY));
        }
        throw e;
    }
}
 
Example #11
Source File: PyImportTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: PyEmitterTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
private List<Event> parse(String data) {
    ParserImpl parser = new ParserImpl(new StreamReader(data));
    List<Event> newEvents = new ArrayList<Event>();
    while (parser.peekEvent() != null) {
        newEvents.add(parser.getEvent());
    }
    return newEvents;
}
 
Example #13
Source File: PyStructureTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: ConstructorSequenceTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private List<Object> construct(Constructor constructor, String data) {
    StreamReader reader = new StreamReader(data);
    Parser parser = new ParserImpl(reader);
    Resolver resolver = new Resolver();
    Composer composer = new Composer(parser, resolver);
    constructor.setComposer(composer);
    List<Object> result = (List<Object>) constructor.getSingleData(Object.class);
    return result;
}
 
Example #15
Source File: ConstructorMappingTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
private Object construct(Constructor constructor, String data) {
    StreamReader reader = new StreamReader(data);
    Parser parser = new ParserImpl(reader);
    Resolver resolver = new Resolver();
    Composer composer = new Composer(parser, resolver);
    constructor.setComposer(composer);
    return constructor.getSingleData(Object.class);
}
 
Example #16
Source File: FragmentComposerTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testFragment() {
    String document = "foo:  blargle\n"
            + "developer:  { name: \"Bjarne Stroustrup\", language: \"C++\"}\n"
            + "gee:  [ \"whiz\", \"bang\"]\n";//

    StreamReader reader = new StreamReader(document);
    Composer composer = new FragmentComposer(new ParserImpl(reader), new Resolver(),
            "developer");
    Constructor constructor = new Constructor();
    constructor.setComposer(composer);
    DeveloperBean developer = (DeveloperBean) constructor.getSingleData(DeveloperBean.class);
    assertEquals("Bjarne Stroustrup", developer.name);
    assertEquals("C++", developer.language);
}
 
Example #17
Source File: Yaml.java    From Diorite with MIT License 4 votes vote down vote up
private Object loadFromReader(StreamReader sreader, Class<?> type)
{
    Composer composer = new Composer(new ParserImpl(sreader), this.resolver);
    this.constructor.setComposer(composer);
    return this.constructor.getSingleData(type);
}
 
Example #18
Source File: Yaml.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
private Object loadFromReader(StreamReader sreader, Class<?> type) {
    Composer composer = new Composer(new ParserImpl(sreader), resolver);
    constructor.setComposer(composer);
    return constructor.getSingleData(type);
}
 
Example #19
Source File: Yaml.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
private Object loadFromReader(StreamReader sreader, Class<?> type) {
    Composer composer = new Composer(new ParserImpl(sreader), resolver);
    constructor.setComposer(composer);
    return constructor.getSingleData(type);
}
 
Example #20
Source File: Yaml.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
private Object loadFromReader(StreamReader sreader, Class<?> type) {
    Composer composer = new Composer(new ParserImpl(sreader), resolver);
    constructor.setComposer(composer);
    return constructor.getSingleData(type);
}
 
Example #21
Source File: Yaml.java    From Diorite with MIT License 3 votes vote down vote up
/**
 * Parse the only YAML document in a stream as configuration object.
 *
 * @param template
 *         template of config object.
 * @param io
 *         data to load from (BOM must not be present)
 * @param <T>
 *         type of config object.
 *
 * @return parsed object
 */
@SuppressWarnings("unchecked")
public <T extends Config> T fromYaml(ConfigTemplate<T> template, Reader io)
{
    Composer composer = new Composer(new ParserImpl(new StreamReader(io)), new ConfigTemplateResolver(template));
    this.constructor.setComposer(composer);
    return (T) this.constructor.getSingleData(template.getConfigType());
}
 
Example #22
Source File: Yaml.java    From Diorite with MIT License 3 votes vote down vote up
/**
 * Parse all YAML documents in a String and produce corresponding Java
 * objects. The documents are parsed only when the iterator is invoked.
 *
 * @param yaml
 *         YAML data to load from (BOM must not be present)
 *
 * @return an iterator over the parsed Java objects in this String in proper sequence
 */
public Iterable<Object> fromAllYaml(Reader yaml)
{
    Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), this.resolver);
    this.constructor.setComposer(composer);
    Iterator<Object> result = new YamlLoaderIterator(this);
    return new YamlIterable(result);
}
 
Example #23
Source File: Yaml.java    From Diorite with MIT License 3 votes vote down vote up
/**
 * Parse the first YAML document in a stream and produce the corresponding
 * representation tree. (This is the opposite of the represent() method)
 *
 * @param yaml
 *         YAML document
 *
 * @return parsed root Node for the specified YAML document
 *
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Figure 3.1. Processing Overview</a>
 */
public Node compose(Reader yaml)
{
    Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), this.resolver);
    this.constructor.setComposer(composer);
    return composer.getSingleNode();
}
 
Example #24
Source File: Yaml.java    From Diorite with MIT License 3 votes vote down vote up
/**
 * Parse all YAML documents in a stream and produce corresponding
 * representation trees.
 *
 * @param yaml
 *         stream of YAML documents
 *
 * @return parsed root Nodes for all the specified YAML documents
 *
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
 */
public Iterable<Node> composeAll(Reader yaml)
{
    Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), this.resolver);
    this.constructor.setComposer(composer);
    Iterator<Node> result = new YamlComposerNodeIterator(composer);
    return new YamlNodeIterable(result);
}
 
Example #25
Source File: Yaml.java    From Diorite with MIT License 3 votes vote down vote up
/**
 * Parse a YAML stream and produce parsing events.
 *
 * @param yaml
 *         YAML document(s)
 *
 * @return parsed events
 *
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Processing Overview</a>
 */
public Iterable<Event> parse(Reader yaml)
{
    Parser parser = new ParserImpl(new StreamReader(yaml));
    Iterator<Event> result = new YamlParserEventIterator(parser);
    return new YamlEventIterable(result);
}
 
Example #26
Source File: Yaml.java    From snake-yaml with Apache License 2.0 2 votes vote down vote up
/**
 * Parse the first YAML document in a stream and produce the corresponding
 * representation tree. (This is the opposite of the represent() method)
 * 
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Figure 3.1. Processing
 *      Overview</a>
 * @param yaml
 *            YAML document
 * @return parsed root Node for the specified YAML document
 */
public Node compose(Reader yaml) {
    Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
    constructor.setComposer(composer);
    return composer.getSingleNode();
}
 
Example #27
Source File: Yaml.java    From FastAsyncWorldedit with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Parse the first YAML document in a stream and produce the corresponding
 * representation tree. (This is the opposite of the represent() method)
 *
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Figure 3.1. Processing
 *      Overview</a>
 * @param yaml
 *            YAML document
 * @return parsed root Node for the specified YAML document
 */
public Node compose(Reader yaml) {
    Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
    constructor.setComposer(composer);
    return composer.getSingleNode();
}
 
Example #28
Source File: Yaml.java    From orion.server with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Parse the first YAML document in a stream and produce the corresponding
 * representation tree. (This is the opposite of the represent() method)
 * 
 * @see <a href="http://yaml.org/spec/1.1/#id859333">Figure 3.1. Processing
 *      Overview</a>
 * @param yaml
 *            YAML document
 * @return parsed root Node for the specified YAML document
 */
public Node compose(Reader yaml) {
    Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
    constructor.setComposer(composer);
    return composer.getSingleNode();
}