Package net.fortytwo.ripple.query

Examples of net.fortytwo.ripple.query.PipedIOStream


            throw new RippleException(t);
        }
        jline.Terminal term = reader.getTerminal();
//System.out.println( "reader.getTerminal() = " + term );

        writeIn = new PipedIOStream();
        //writeIn.write(32);
        //writeIn = new PipedInputStream();
        //readOut = new PipedOutputStream( writeIn );

        // Initialize completors.
View Full Code Here


            throw new RippleException(t);
        }
        jline.Terminal term = reader.getTerminal();
//System.out.println( "reader.getTerminal() = " + term );

        writeIn = new PipedIOStream();
        //writeIn.write(32);
        //writeIn = new PipedInputStream();
        //readOut = new PipedOutputStream( writeIn );

        // Initialize completors.
View Full Code Here

    private void parse(final InputStream is, final boolean expectSuccess)
            throws Exception {
        lineNumber = 0;

        final PipedIOStream pio = new PipedIOStream();

        Collector<Exception> exceptions = new Collector<Exception>();
        RecognizerAdapter ra = new RecognizerAdapter(System.err) {
            @Override
            protected void handleQuery(ListAST query) throws RippleException {
                // Do nothing.
            }

            @Override
            protected void handleCommand(Command command) throws RippleException {
                // Do nothing.
            }

            @Override
            protected void handleEvent(RecognizerEvent event) throws RippleException {
                // Do nothing.
            }

            @Override
            protected void handleAssignment(KeywordAST name) throws RippleException {
                // Do nothing.
            }
        };
        final Interpreter interpreter = new Interpreter(ra, pio, exceptions);

        Thread interpreterThread = new Thread(new Runnable() {
            public void run() {
                try {
                    interpreter.parse();
                } catch (Exception e) {
                    // Throw out the error, for now.
                    e.printStackTrace();
                }
            }
        }, "InterpreterTest thread");

        interpreterThread.start();

        final BufferedReader reader = new BufferedReader(
                new InputStreamReader(is));

        String line;

        do {
            exceptions.clear();

            lineNumber++;
            System.out.println("line #" + lineNumber);
            line = reader.readLine();

            if (null == line) {
                break;
            }

            pio.write((line.trim() + '\n').getBytes());

            do {
                //System.out.println( "waiting " + WAIT_INTERVAL + " milliseconds" );
                synchronized (this) {
                    // FIXME: the first wait depends on a race condition
                    try {
                        wait(WAIT_INTERVAL);
                    } catch (InterruptedException e) {
                        throw new RippleException(e);
                    }
                }
            } while (Thread.State.RUNNABLE == interpreterThread.getState());

            if (expectSuccess) {
                if (exceptions.size() > 0) {
                    fail("Success case failed on line "
                            + lineNumber + ": " + line
                            + ", with exception = " + exceptions.iterator().next());
                }
            } else {
                if (exceptions.size() < 1) {
                    fail("Failure case succeeded on line "
                            + lineNumber + ": " + line);
                }
            }
        } while (true);


        pio.close();
    }
View Full Code Here

TOP

Related Classes of net.fortytwo.ripple.query.PipedIOStream

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.