List of usage examples for java.lang System setOut
public static void setOut(PrintStream out)
From source file:org.apache.jk.apr.AprImpl.java
/** Sets the System.out stream */ public static void setOut(String filename) { try {//from w w w . jav a 2 s .co m if (filename != null) { System.setOut(new PrintStream(new FileOutputStream(filename))); } } catch (Throwable th) { } }
From source file:org.apache.spark.simr.Simr.java
public void redirectOutput(String filePrefix) throws IOException { FSDataOutputStream stdout = fs.create(new Path(conf.get("simr_out_dir") + "/" + filePrefix + ".stdout")); FSDataOutputStream stderr = fs.create(new Path(conf.get("simr_out_dir") + "/" + filePrefix + ".stderr")); System.setOut(new PrintStream(stdout)); System.setErr(new PrintStream(stderr)); }
From source file:org.apache.oozie.cli.TestCLIParser.java
private String readCommandOutput(CLIParser parser, CLIParser.Command c) throws IOException { ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); PipedOutputStream pipeOut = new PipedOutputStream(); PipedInputStream pipeIn = new PipedInputStream(pipeOut, 1024 * 10); System.setOut(new PrintStream(pipeOut)); parser.showHelp(c.getCommandLine()); pipeOut.close();//w w w .j a v a 2 s .c o m ByteStreams.copy(pipeIn, outBytes); pipeIn.close(); return new String(outBytes.toByteArray()); }
From source file:be.makercafe.apps.makerbench.Main.java
@Override public void start(Stage primaryStage) { setupWorkspace();/*from w w w .j a v a2 s . co m*/ rootContextMenu = createViewerContextMenu(); viewer = createViewer(); this.stage = primaryStage; BorderPane p = new BorderPane(); p.setTop(createMenuBar()); // p.setLeft(viewer); tabFolder = new TabPane(); BorderPane bodyPane = new BorderPane(); TextArea taConsole = new TextArea(); taConsole.setPrefSize(Double.MAX_VALUE, 200.0); taConsole.setEditable(false); Console console = new Console(taConsole); PrintStream ps = new PrintStream(console, true); System.setOut(ps); System.setErr(ps); bodyPane.setBottom(taConsole); bodyPane.setCenter(tabFolder); SplitPane splitpane = new SplitPane(); splitpane.getItems().addAll(viewer, bodyPane); splitpane.setDividerPositions(0.0f, 1.0f); p.setCenter(splitpane); Scene scene = new Scene(p, 1024, 800); //scene.getStylesheets().add(this.getClass().getResource("/styles/java-keywords.css").toExternalForm()); primaryStage.setResizable(true); primaryStage.setTitle("Makerbench"); primaryStage.setScene(scene); //primaryStage.getIcons().add(new Image("/path/to/stackoverflow.jpg")); primaryStage.show(); }
From source file:com.ibm.bi.dml.debug.DMLDebugger.java
/** * Sets STDERR stream of a DML program running in debug mode *//*ww w . j a v a2s. c o m*/ @SuppressWarnings("unused") private void setStdErr() { originalErr = System.err; System.setOut(originalErr); }
From source file:org.kepler.gui.KeplerInitializer.java
public static void initializeSystem() throws Exception { System.out.println("Kepler Initializing..."); // Only run initialization once. if (hasBeenInitialized) { return;//from w w w. j a v a2 s . c om } hasBeenInitialized = true; ConfigurationProperty commonProperty = ConfigurationManager.getInstance() .getProperty(ConfigurationManager.getModule("common")); autoUpdate = Boolean.parseBoolean(commonProperty.getProperty("autoDataSourcesUpdate.value").getValue()); autoUpdateDelay = Integer.parseInt(commonProperty.getProperty("autoDataSourcesUpdate.delay").getValue()); // Add the dbconnection type. Constants.add("dbconnection", new DBConnectionToken()); DotKeplerManager dkm = DotKeplerManager.getInstance(); // String log_file_setting = c.getValue("//log_file"); String log_file_setting = commonProperty.getProperty("log_file").getValue(); if (log_file_setting != null) { if (log_file_setting.equalsIgnoreCase("true")) { log_file = true; } else { log_file = false; } } if (log_file) { try { FileOutputStream err = new FileOutputStream("kepler_stderr.log"); PrintStream errPrintStream = new PrintStream(err); System.setErr(errPrintStream); System.setOut(errPrintStream); } catch (FileNotFoundException fnfe) { System.out.println("Warning: Failure to redirect log to a file."); } } // First get the entries named mkdir. We will make // directories for each of these entries under the UserDir. List mkdirList = commonProperty.getProperties("startup"); List mkdirs = ConfigurationProperty.getValueList(mkdirList, "mkdir", true); for (Iterator i = mkdirs.iterator(); i.hasNext();) { String dir = (String) i.next(); if (dir == null || dir.length() == 0) { continue; } dir = dkm.getCacheDir(dir); File f = new File(dir); if (!f.exists()) { boolean created = f.mkdirs(); if (created) { log.debug("Making directory " + dir); } } } Connection conn = DatabaseFactory.getDBConnection(); // // Get the tabletestsql entry. This is the sql used to test if a // table already exists in the database. // String tabletestsql = commonProperty.getProperty("startup.tabletestsql").getValue(); PreparedStatement tabletest = null; if (tabletestsql != null) { tabletest = conn.prepareStatement(tabletestsql); } // We use pattern matching to extract the tablename from the // ddl statement. This is a Java 1.4 regex regular expression // which extracts the word after the string "table". The // match is case insensitive so "table" will also match // "TABLE". The "(" ")" characters denote a grouping. This // will be returned as group 1. Pattern extractTable = Pattern.compile("table\\s+(\\w*)", Pattern.CASE_INSENSITIVE); // Get the list of ddl statements defining the tables to create. List createTableList = commonProperty.getProperties("startup"); List createtables = ConfigurationProperty.getValueList(createTableList, "createtable", true); final String schemaName = CacheManager.getDatabaseSchemaName(); for (Iterator i = createtables.iterator(); i.hasNext();) { String ddl = (String) i.next(); // Create our Matcher object for the ddl string. Matcher m = extractTable.matcher(ddl); // Matcher.find() looks for any match of the pattern in the string. m.find(); String tablename = m.group(1); if (tabletest == null) { log.error("unable to test for table: " + tablename); continue; } tabletest.setString(1, tablename); tabletest.setString(2, schemaName); ResultSet rs = tabletest.executeQuery(); if (rs.next()) { log.debug("Table " + tablename + " already exists"); continue; } Statement statement = conn.createStatement(); statement.execute(ddl); statement.close(); log.debug("Table " + tablename + " created"); } tabletest.close(); // Get the Authorized Namespace after the tables are set up. AuthNamespace an = AuthNamespace.getInstance(); an.initialize(); // Hook to execute arbitrary sql statements on the internal database. // List sqls = c.getList("//startup/sql"); List sqlList = commonProperty.getProperties("startup"); List sqls = ConfigurationProperty.getValueList(sqlList, "sql", true); Statement statement = null; for (Iterator i = sqls.iterator(); i.hasNext();) { String statementStr = (String) i.next(); log.info("Executing sql command " + statementStr); statement = conn.createStatement(); statement.execute(statementStr); } if (statement != null) statement.close(); conn.close(); // Set the icon loader to load Kepler files MoMLParser.setIconLoader(new KeplerIconLoader()); // set the initial directory for file dialogs setDefaultFileDialogDir(); // refresh the datasources from the registry updateDataSources(); }
From source file:ConsoleWindowTest.java
public static void init() { JFrame frame = new JFrame(); frame.setTitle("ConsoleWindow"); final JTextArea output = new JTextArea(); output.setEditable(false);//from w w w . j ava2 s .co m frame.add(new JScrollPane(output)); frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); frame.setLocation(DEFAULT_LEFT, DEFAULT_TOP); frame.setFocusableWindowState(false); frame.setVisible(true); // define a PrintStream that sends its bytes to the output text area PrintStream consoleStream = new PrintStream(new OutputStream() { public void write(int b) { } // never called public void write(byte[] b, int off, int len) { output.append(new String(b, off, len)); } }); // set both System.out and System.err to that stream System.setOut(consoleStream); System.setErr(consoleStream); }
From source file:eu.cassandra.training.entities.ActivityTemp.java
/** * This function is giving the capability of creating an event file out of the * list of consumption events imported from the user to this temporary * activity./* w ww . j a v a 2 s.co m*/ * */ public void createEventFile() throws IOException { PrintStream realSystemOut = System.out; eventsFile = Constants.tempFolder + name + " events.csv"; OutputStream output = new FileOutputStream(eventsFile); PrintStream printOut = new PrintStream(output); System.setOut(printOut); System.out.println("Start Time, End Time"); for (Integer[] temp : events) { System.out.println(temp[0] + "-" + temp[1]); } System.setOut(realSystemOut); output.close(); }
From source file:org.apache.hadoop.hive.metastore.tools.TestSchemaToolForMetastore.java
@After public void tearDown() throws IOException, SQLException { File metaStoreDir = new File(testMetastoreDB); if (metaStoreDir.exists()) { FileUtils.forceDeleteOnExit(metaStoreDir); }// ww w . j a v a 2 s.c o m System.setOut(outStream); System.setErr(errStream); if (conn != null) { conn.close(); } }
From source file:org.pentaho.di.kitchen.KitchenIT.java
@Test public void testFileJobsExecution() throws Exception { String file = this.getClass().getResource("Job.kjb").getFile(); String[] args = new String[] { "/file:" + file }; oldOut = System.out;//from ww w. j a v a 2s .c o m oldErr = System.err; System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); try { Kitchen.main(args); } catch (SecurityException e) { System.setOut(oldOut); System.setErr(oldErr); System.out.println(outContent); assertFalse(outContent.toString().contains("result=[false]")); assertFalse(outContent.toString().contains("ERROR")); } }