Package org.yaml.snakeyaml.reader

Examples of org.yaml.snakeyaml.reader.StreamReader


    @JRubyMethod
    public IRubyObject parse(ThreadContext context, IRubyObject target) {
        Ruby runtime = context.runtime;
       
        // FIXME? only supports Unicode, since we have to produces strings...
        StreamReader reader;
        if (target.respondsTo("read")) {
            reader = new StreamReader(new InputStreamReader(new IOInputStream(target)));
        } else {
            reader = new StreamReader(new StringReader(target.convertToString().asJavaString()));
        }
        Parser parser = new ParserImpl(reader);
        IRubyObject handler = getInstanceVariable("@handler");
        Event event;
View Full Code Here


            Charset charset = byteList.getEncoding().getCharset();
            if (charset == null) charset = Charset.defaultCharset();

            InputStreamReader isr = new InputStreamReader(bais, charset);

            return new StreamReader(isr);
        }

        // fall back on IOInputStream, using default charset
        if (yaml.respondsTo("read")) {
            return new StreamReader(new InputStreamReader(new IOInputStream(yaml), Charset.defaultCharset()));
        } else {
            throw runtime.newTypeError(yaml, runtime.getIO());
        }
    }
View Full Code Here

    private Object construct(String data) {
        return construct(new Constructor(), data);
    }

    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);
View Full Code Here

        return construct(new Constructor(), data);
    }

    @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);
View Full Code Here

            }
        }
    }

    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());
        }
View Full Code Here

        }
        return documents;
    }

    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()) {
View Full Code Here

            super(new MyConstructor());
        }

        @Override
        public Iterable<Object> loadAll(Reader yaml) {
            StreamReader reader = new StreamReader(yaml);
            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, resolver);
            this.constructor.setComposer(composer);
            Iterator<Object> result = new Iterator<Object>() {
View Full Code Here

public class ScannerImplTest extends TestCase {

    public void testGetToken() {
        String data = "string: abcd";
        StreamReader reader = new StreamReader(data);
        Scanner scanner = new ScannerImpl(reader);
        Mark dummy = new Mark("dummy", 0, 0, 0, "", 0);
        LinkedList<Token> etalonTokens = new LinkedList<Token>();
        etalonTokens.add(new StreamStartToken(dummy, dummy));
        etalonTokens.add(new BlockMappingStartToken(dummy, dummy));
View Full Code Here

    public void testReaderUnicodeErrors() throws IOException {
        File[] inputs = getStreamsByExtension(".stream-error");
        for (int i = 0; i < inputs.length; i++) {
            InputStream input = new FileInputStream(inputs[i]);
            StreamReader stream = new StreamReader(new UnicodeReader(input));
            try {
                while (stream.peek() != '\u0000') {
                    stream.forward();
                }
                fail("Invalid stream must not be accepted: " + inputs[i].getAbsolutePath()
                        + "; encoding=" + stream.getEncoding());
            } catch (ReaderException e) {
                assertTrue(e.toString(),
                        e.toString().contains(" special characters are not allowed"));
            } catch (YAMLException e) {
                assertTrue(e.toString(), e.toString().contains("MalformedInputException"));
View Full Code Here

            for (int j = 0; j < split.length; j++) {
                tokens2.add(split[j]);
            }
            //
            List<String> tokens1 = new ArrayList<String>();
            StreamReader reader = new StreamReader(new UnicodeReader(new FileInputStream(
                    getFileByName(dataName))));
            Scanner scanner = new ScannerImpl(reader);
            try {
                while (scanner.checkToken(new Token.ID[0])) {
                    Token token = scanner.getToken();
View Full Code Here

TOP

Related Classes of org.yaml.snakeyaml.reader.StreamReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.