Example usage for java.lang System setIn

List of usage examples for java.lang System setIn

Introduction

In this page you can find the example usage for java.lang System setIn.

Prototype

public static void setIn(InputStream in) 

Source Link

Document

Reassigns the "standard" input stream.

Usage

From source file:grakn.core.console.test.GraknConsoleIT.java

@AfterClass
public static void resetIO() {
    System.setIn(trueIn);
}

From source file:ai.grakn.test.graql.shell.GraqlShellIT.java

@AfterClass
public static void resetIO() {
    System.setIn(trueIn);
    System.setOut(trueOut);
    System.setErr(trueErr);
}

From source file:Alias2.java

public TestStream(String className) {
    super(System.out, true); // Autoflush
    System.setOut(this);
    System.setErr(this);
    stdin = System.in; // Save to restore in dispose()
    // Replace the default version with one that
    // automatically produces input on demand:
    System.setIn(new BufferedInputStream(new InputStream() {
        char[] input = ("test\n").toCharArray();

        int index = 0;

        public int read() {
            return (int) input[index = (index + 1) % input.length];
        }/*from   www.  ja  v a2  s. com*/
    }));
    this.className = className;
    openOutputFile();
}

From source file:Alias2.java

public void dispose() {
    System.setOut(console);
    System.setErr(err);
    System.setIn(stdin);
}

From source file:com.cic.datacrawl.ui.Main.java

private static void startupGUI(String[] args) {
    // ??/* w  w w  .  j  a v a  2  s .c  om*/
    boolean isShowChooseWorkspace = true;

    Main main = new Main(SwingGui.FRAME_TITLE);

    if (isShowChooseWorkspace) {
        ChooseWorkspaceDialog dialog = new ChooseWorkspaceDialog(main.debugGui);
        dialog.setStartupArgs(args);
        dialog.setVisible(true);
    }
    Global global = Global.getInstance();

    main.setExitAction(new IProxy(IProxy.EXIT_ACTION));

    main.attachTo(com.cic.datacrawl.ui.shell.Shell.shellContextFactory);

    main.setScope(global);
    main.setGlobal(global);
    main.pack();

    main.startupBrowser();
    main.maxSize();
    if (!isShowChooseWorkspace) {
        main.setVisible(true);
    }

    if (args.length == 2) {
        args = new String[0];
    }

    global.setIn(main.getIn());
    global.setOut(main.getOut());
    global.setErr(main.getErr());

    System.setIn(main.getIn());
    System.setOut(main.getOut());
    System.setErr(main.getErr());

    com.cic.datacrawl.ui.shell.Shell.setDebugGui(main.debugGui);

    final RhinoDim finalDim = main.dim;
    new Thread(new Runnable() {

        @Override
        public void run() {
            while (InitializerRegister.getInstance().isNotFinished())
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            ((RunOnStartup) ApplicationContext.getInstance().getBean("runOnStartup")).execute(finalDim);
        }
    }).start();
    new Thread(new Runnable() {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(60000);
                } catch (InterruptedException e) {
                }
                System.gc();
            }
        }
    }).start();
    // ?
    AutoSaveConfiguration autoSaveRunner = new AutoSaveConfiguration();
    autoSaveRunner.registerSaveRunner(main.debugGui);
    autoSaveRunner.setSleepSecond(3600);
    new Thread(autoSaveRunner).start();

    com.cic.datacrawl.ui.shell.Shell.exec(args, global);
}

From source file:grakn.core.console.test.GraknConsoleIT.java

private Response runConsoleSession(String input, String... args) {
    args = addKeyspaceAndUriParams(args);

    OutputStream bufferOut = new ByteArrayOutputStream();
    OutputStream bufferErr = new ByteArrayOutputStream();

    PrintStream printOut = new PrintStream(new TeeOutputStream(bufferOut, System.out));
    PrintStream printErr = new PrintStream(new TeeOutputStream(bufferErr, System.err));

    try {/*w  ww  .ja  va  2s .  co m*/
        System.setIn(new ByteArrayInputStream(input.getBytes()));
        GraknConsole console = new GraknConsole(args, printOut, printErr);
        console.run();
    } catch (Exception e) {
        printErr.println(e.getMessage());
        printErr.flush();
    } finally {
        resetIO();
    }

    printOut.flush();
    printErr.flush();

    return Response.of(bufferOut.toString(), bufferErr.toString());
}

From source file:ai.grakn.test.graql.shell.GraqlShellIT.java

private String testShell(String input, ByteArrayOutputStream berr, String... args) throws Exception {
    args = specifyUniqueKeyspace(args);//from  w ww. ja v  a2s  .  c  om

    InputStream in = new ByteArrayInputStream(input.getBytes());

    ByteArrayOutputStream bout = new ByteArrayOutputStream();

    PrintStream out = new PrintStream(new TeeOutputStream(bout, trueOut));

    // Intercept stderr, but make sure it is still printed using the TeeOutputStream
    PrintStream err = new PrintStream(new TeeOutputStream(berr, trueErr));

    try {
        System.out.flush();
        System.err.flush();
        System.setIn(in);
        System.setOut(out);
        System.setErr(err);

        GraqlShell.runShell(args, expectedVersion, historyFile);
    } catch (Exception e) {
        System.setErr(trueErr);
        e.printStackTrace();
        err.flush();
        fail(berr.toString());
    } finally {
        resetIO();
    }

    out.flush();
    err.flush();

    return bout.toString();
}

From source file:org.anyframe.oden.admin.common.HsqlDB.java

private Connection getInitData(Connection con) throws IOException {

    InputStream resourceAsStream = getClass().getResourceAsStream("/sql/initialdb.sql");
    if (resourceAsStream != null) {
        System.setIn(resourceAsStream);
        try {/*  w  w w  .j  av  a2s . c o  m*/
            SqlFile file = new SqlFile(null, true, null);
            file.execute(con, true);
        } catch (Exception e) {
            logger.error(e.getMessage());
        } finally {
            resourceAsStream.close();
        }
    }
    return con;
}

From source file:org.anyframe.oden.admin.database.HsqlDB.java

private Connection getInitData(Connection con) throws IOException {

    InputStream resourceAsStream = getClass().getResourceAsStream("/sql/initialdb.sql");
    if (resourceAsStream != null) {
        System.setIn(resourceAsStream);
        try {//from   w  ww.  jav a  2s  .  c o  m
            SqlFile file = new SqlFile(null, null, true);
            file.execute();
        } catch (Exception e) {
            logger.error(e.getMessage());
        } finally {
            resourceAsStream.close();
        }
    }
    return con;
}

From source file:org.apache.hadoop.hdfs.server.namenode.TestClusterId.java

/**
 * Test namenode format with -format option when a non empty name directory
 * exists. Enter Y when prompted and the format should succeed.
 *
 * @throws IOException//from  w ww.j av  a 2s .  c  om
 * @throws InterruptedException
 */
@Test(timeout = 300000)
public void testFormatWithoutForceEnterYes() throws IOException, InterruptedException {

    // we check for a non empty dir, so create a child path
    File data = new File(hdfsDir, "file");
    if (!data.mkdirs()) {
        fail("Failed to create dir " + data.getPath());
    }

    // capture the input stream
    InputStream origIn = System.in;
    ByteArrayInputStream bins = new ByteArrayInputStream("Y\n".getBytes());
    System.setIn(bins);

    String[] argv = { "-format" };

    try {
        NameNode.createNameNode(argv, config);
        fail("createNameNode() did not call System.exit()");
    } catch (ExitException e) {
        assertEquals("Format should have succeeded", 0, e.status);
    }

    System.setIn(origIn);

    String cid = getClusterId(config);
    assertTrue("Didn't get new ClusterId", (cid != null && !cid.equals("")));
}