List of usage examples for java.lang System setOut
public static void setOut(PrintStream out)
From source file:Log.java
/** * Initializes the log.//from w w w . j a va 2s. c o m * @param stdio If true, standard output and error will be * sent to the log * @param level Messages with this log level or higher will * be printed to the system console * @since jEdit 3.2pre4 */ public static void init(boolean stdio, int level) { if (stdio) { if (System.out == realOut && System.err == realErr) { System.setOut(createPrintStream(NOTICE, null)); System.setErr(createPrintStream(ERROR, null)); } } Log.level = level; // Log some stuff log(MESSAGE, Log.class, "When reporting bugs, please" + " include the following information:"); String[] props = { "java.version", "java.vm.version", "java.runtime.version", "java.vendor", "java.compiler", "os.name", "os.version", "os.arch", "user.home", "java.home", "java.class.path", }; for (int i = 0; i < props.length; i++) { log(MESSAGE, Log.class, props[i] + '=' + System.getProperty(props[i])); } }
From source file:org.apache.hadoop.hdfs.TestFsShellPermission.java
static String execCmd(FsShell shell, final String[] args) throws Exception { ByteArrayOutputStream baout = new ByteArrayOutputStream(); PrintStream out = new PrintStream(baout, true); PrintStream old = System.out; System.setOut(out); int ret = shell.run(args); out.close();// www. j ava 2 s . c om System.setOut(old); return String.valueOf(ret); }
From source file:org.apache.hadoop.hive.ql.processors.DfsProcessor.java
@Override public CommandProcessorResponse run(String command) { try {/*from www . j av a 2 s. co m*/ SessionState ss = SessionState.get(); command = new VariableSubstitution().substitute(ss.getConf(), command); String[] tokens = command.split("\\s+"); CommandProcessorResponse authErrResp = CommandUtil.authorizeCommand(ss, HiveOperationType.DFS, Arrays.asList(tokens)); if (authErrResp != null) { // there was an authorization issue return authErrResp; } PrintStream oldOut = System.out; if (ss != null && ss.out != null) { System.setOut(ss.out); } int ret = dfs.run(tokens); if (ret != 0) { console.printError("Command failed with exit code = " + ret); } System.setOut(oldOut); return new CommandProcessorResponse(ret, null, null, dfsSchema); } catch (Exception e) { console.printError("Exception raised from DFSShell.run " + e.getLocalizedMessage(), org.apache.hadoop.util.StringUtils.stringifyException(e)); return new CommandProcessorResponse(1); } }
From source file:org.apache.flink.yarn.CliFrontendYarnAddressConfigurationTest.java
@AfterClass public static void restoreAfterwards() { System.setOut(OUT); System.setErr(ERR); }
From source file:ee.ioc.cs.vsle.util.Console.java
private Console() { // create all components and add them frame = new JFrame("Java Console"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = new Dimension((screenSize.width / 2), (screenSize.height / 2)); int x = (frameSize.width / 2); int y = (frameSize.height / 2); frame.setBounds(x, y, frameSize.width, frameSize.height); textArea = new JTextArea(); textArea.setEditable(false);//w w w .j ava 2 s . c o m JButton button = new JButton("clear"); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); frame.getContentPane().add(button, BorderLayout.SOUTH); frame.setVisible(true); frame.addWindowListener(this); button.addActionListener(this); final PipedInputStream pin = new PipedInputStream(); try { PipedOutputStream pout = new PipedOutputStream(pin); System.setOut(new PrintStream(new TeeOutputStream(systemOut, pout), true)); } catch (java.io.IOException io) { textArea.append("Couldn't redirect STDOUT to this console\n" + io.getMessage()); } catch (SecurityException se) { textArea.append("Couldn't redirect STDOUT to this console\n" + se.getMessage()); } final PipedInputStream pin2 = new PipedInputStream(); try { PipedOutputStream pout2 = new PipedOutputStream(pin2); System.setErr(new PrintStream(new TeeOutputStream(systemErr, pout2), true)); } catch (java.io.IOException io) { textArea.append("Couldn't redirect STDERR to this console\n" + io.getMessage()); } catch (SecurityException se) { textArea.append("Couldn't redirect STDERR to this console\n" + se.getMessage()); } quit = false; // signals the Threads that they should exit sysOutFollower = new StreamFollower(pin, StreamRestorer.SYS_OUT, "Console_out"); sysOutFollower.start(); // sysErrFollower = new StreamFollower(pin2, StreamRestorer.SYS_ERR, "Console_err"); sysErrFollower.start(); }
From source file:org.apache.apex.malhar.sql.FileEndpointTest.java
@Test public void testApplication() throws Exception { File modelFile = new File("src/test/resources/model/model_file_csv.json"); String model = FileUtils.readFileToString(modelFile); PrintStream originalSysout = System.out; ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); try {//from w w w .j av a 2 s .c o m LocalMode lma = LocalMode.newInstance(); Configuration conf = new Configuration(false); lma.prepareDAG(new Application(model), conf); LocalMode.Controller lc = lma.getController(); lc.runAsync(); waitTillStdoutIsPopulated(baos, 30000); lc.shutdown(); } catch (ConstraintViolationException e) { Assert.fail("constraint violations: " + e.getConstraintViolations()); } catch (Exception e) { Assert.fail("Exception: " + e); } System.setOut(originalSysout); String[] sout = baos.toString().split(System.lineSeparator()); Collection<String> filter = Collections2.filter(Arrays.asList(sout), Predicates.containsPattern("Delta Record:")); String[] actualLines = filter.toArray(new String[filter.size()]); Assert.assertEquals(6, actualLines.length); Assert.assertTrue(actualLines[0].contains("RowTime=Mon Feb 15 10:15:00 GMT 2016, Product=paint1")); Assert.assertTrue(actualLines[1].contains("RowTime=Mon Feb 15 10:16:00 GMT 2016, Product=paint2")); Assert.assertTrue(actualLines[2].contains("RowTime=Mon Feb 15 10:17:00 GMT 2016, Product=paint3")); Assert.assertTrue(actualLines[3].contains("RowTime=Mon Feb 15 10:18:00 GMT 2016, Product=paint4")); Assert.assertTrue(actualLines[4].contains("RowTime=Mon Feb 15 10:19:00 GMT 2016, Product=paint5")); Assert.assertTrue(actualLines[5].contains("RowTime=Mon Feb 15 10:10:00 GMT 2016, Product=abcde6")); }
From source file:net.dv8tion.jda.core.utils.SimpleLog.java
/** * Will duplicate the output-streams to the specified Files. * This will catch everything that is sent to sout and serr (even stuff not logged via SimpleLog). * * @param std/* w ww . j a va 2 s . c o m*/ * The file to use for System.out logging, or null to not LOG System.out to a file * @param err * The file to use for System.err logging, or null to not LOG System.err to a file * @throws java.io.IOException * If an IO error is encountered while dealing with the file. Most likely * to be caused by a lack of permissions when creating the log folders or files. */ @SuppressWarnings("ResultOfMethodCallIgnored") public static void addFileLogs(File std, File err) throws IOException { if (std != null) { if (origStd == null) origStd = System.out; if (!std.getAbsoluteFile().getParentFile().exists()) { std.getAbsoluteFile().getParentFile().mkdirs(); } if (!std.exists()) { std.createNewFile(); } FileOutputStream fOut = new FileOutputStream(std, true); System.setOut(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { origStd.write(b); fOut.write(b); } })); if (stdOut != null) stdOut.close(); stdOut = fOut; } else if (origStd != null) { System.setOut(origStd); stdOut.close(); origStd = null; } if (err != null) { if (origErr == null) origErr = System.err; if (!err.getAbsoluteFile().getParentFile().exists()) { err.getAbsoluteFile().getParentFile().mkdirs(); } if (!err.exists()) { err.createNewFile(); } FileOutputStream fOut = new FileOutputStream(err, true); System.setErr(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { origErr.write(b); fOut.write(b); } })); if (errOut != null) errOut.close(); errOut = fOut; } else if (origErr != null) { System.setErr(origErr); errOut.close(); origErr = null; } }
From source file:org.nuxeo.automation.scripting.test.TestCompileAndContext.java
@Before public void setUpStreams() { outStream = System.out; System.setOut(new PrintStream(outContent)); }
From source file:org.apache.hadoop.mapred.TestJobClient.java
private int runTool(Configuration conf, Tool tool, String[] args, OutputStream out) throws Exception { PrintStream oldOut = System.out; PrintStream newOut = new PrintStream(out, true); try {// w ww . j av a 2 s. com System.setOut(newOut); return ToolRunner.run(conf, tool, args); } finally { System.setOut(oldOut); } }
From source file:org.meresco.triplestore.TransactionLogTest.java
@After public void tearDown() throws Exception { System.setOut(orig_stdout); deleteDirectory(tempdir); }