List of usage examples for java.lang System setOut
public static void setOut(PrintStream out)
From source file:org.apache.nifi.toolkit.s2s.SiteToSiteCliMain.java
public static void main(String[] args) { // Make IO redirection useful PrintStream output = System.out; System.setOut(System.err); Options options = new Options(); try {//from ww w.j a v a 2 s . co m CliParse cliParse = parseCli(options, args); try (SiteToSiteClient siteToSiteClient = cliParse.getBuilder().build()) { if (cliParse.getTransferDirection() == TransferDirection.SEND) { new SiteToSiteSender(siteToSiteClient, System.in).sendFiles(); } else { new SiteToSiteReceiver(siteToSiteClient, output).receiveFiles(); } } } catch (Exception e) { printUsage(e.getMessage(), options); e.printStackTrace(); } }
From source file:com.twitter.heron.common.utils.logging.LoggingHelper.java
/** * Init java util logging// www . j a v a2 s .co m * * @param level the Level of message to log * @param isRedirectStdOutErr whether we redirect std out&err * @param format the format to log */ public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException { // Set the java util logging format setLoggingFormat(format); // Configure the root logger and its handlers so that all the // derived loggers will inherit the properties Logger rootLogger = Logger.getLogger(""); for (Handler handler : rootLogger.getHandlers()) { handler.setLevel(level); } rootLogger.setLevel(level); if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) { // zookeeper logging scares me. if people want this, we can patch to config-drive this Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING); } // setting logging for http client to be error level System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "ERROR"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "ERROR"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "ERROR"); if (isRedirectStdOutErr) { // Remove ConsoleHandler if present, to avoid StackOverflowError. // ConsoleHandler writes to System.err and since we are redirecting // System.err to Logger, it results in an infinite loop. for (Handler handler : rootLogger.getHandlers()) { if (handler instanceof ConsoleHandler) { rootLogger.removeHandler(handler); } } // now rebind stdout/stderr to logger Logger logger; LoggingOutputStream los; logger = Logger.getLogger("stdout"); los = new LoggingOutputStream(logger, StdOutErrLevel.STDOUT); System.setOut(new PrintStream(los, true)); logger = Logger.getLogger("stderr"); los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR); System.setErr(new PrintStream(los, true)); } }
From source file:org.apache.tools.ant.listener.CommonsLoggingListener.java
private Log getLog(String cat, String suffix) { if (suffix != null) { suffix = suffix.replace('.', '-'); suffix = suffix.replace(' ', '-'); cat = cat + "." + suffix; }//from w ww . j a va 2 s . com final PrintStream tmpOut = System.out; final PrintStream tmpErr = System.err; System.setOut(out); System.setErr(err); if (!initialized) { try { logFactory = LogFactory.getFactory(); } catch (final LogConfigurationException e) { e.printStackTrace(System.err); return null; } } initialized = true; final Log log = logFactory.getInstance(cat); System.setOut(tmpOut); System.setErr(tmpErr); return log; }
From source file:ape_test.CLITest.java
public void testMainWithNullArg() { PrintStream originalOut = System.out; OutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps); String[] arg = null;/*from ww w . ja v a 2 s . c o m*/ Main.main(arg); System.setOut(originalOut); assertNotSame("", os.toString()); }
From source file:TestOpenMailRelay.java
/** Try the given mail server, writing output to the given PrintStream */ public static void process(String suspect_relay, PrintStream pw) { pw.println("processs: trying: " + suspect_relay); try {/*from w w w .j a v a 2 s .c o m*/ // Redirect all output from mail API to the given stream. System.setOut(pw); System.setErr(pw); Sender2 sm = new Sender2(suspect_relay); sm.addRecipient("nobody@erewhon.moc"); sm.setFrom(MY_TARGET); sm.setSubject("Testing for open mail relay, see " + RSS_SITE); sm.setBody("This mail is an attempt to confirm that site " + suspect_relay + "\n" + "is in fact an open mail relay site.\n" + "For more information on the problem of open mail relays,\n" + "please visit site " + RSS_SITE + "\n" + "Please join the fight against spam by closing all open mail relays!\n" + "If this open relay has been closed, please accept our thanks.\n"); sm.sendFile(""); } catch (MessagingException e) { pw.println(e); } catch (Exception e) { pw.println(e); } }
From source file:org.apache.hadoop.hbase.backup.TestBackupDelete.java
/** * Verify that full backup is created on a single table with data correctly. Verify that history * works as expected/* w w w. jav a 2s . c om*/ * @throws Exception */ @Test public void testBackupDeleteCommand() throws Exception { LOG.info("test backup delete on a single table with data: command-line"); List<TableName> tableList = Lists.newArrayList(table1); String backupId = fullTableBackup(tableList); assertTrue(checkSucceeded(backupId)); LOG.info("backup complete"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); String[] args = new String[] { "delete", backupId }; // Run backup try { int ret = ToolRunner.run(conf1, new BackupDriver(), args); assertTrue(ret == 0); } catch (Exception e) { LOG.error("failed", e); } LOG.info("delete_backup"); String output = baos.toString(); LOG.info(baos.toString()); assertTrue(output.indexOf("Deleted 1 backups") >= 0); }
From source file:com.filelocker.gui.Events.java
public void make() { // PrintStream oldOut = System.out; PrintStream printStream = new PrintStream(new OutputStream() { @Override//from ww w.j a v a 2 s .com public void write(byte[] buffer, int offset, int length) throws IOException { final String text = new String(buffer, offset, length); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { vNotificationArea.append(text); } }); } @Override public void write(int b) throws IOException { write(new byte[] { (byte) b }, 0, 1); } }); System.setOut(printStream); vPasswordField.setEchoChar('#'); vPasswordLabel.setFont(bigFont); vBrowseLabel.setFont(bigFont); vNotificationArea.setVisible(false); vNotificationArea.setEditable(false); vScroller.setVisible(false); vScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); vScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); vPanel = new JPanel(); vPanel.add(vLockButton); vPanel.add(vCloseButton); vFrame.getContentPane().add(BorderLayout.SOUTH, vPanel); vPanel = new JPanel(); vPanel.add(vPasswordLabel); vPanel.add(vPasswordField); vPanel.add(vBrowseLabel); vPanel.add(vBrowseField); vPanel.add(vBrowseButton); vPanel.add(vScroller); // vPanel.setLayout (new BoxLayout (vPanel, BoxLayout.Y_AXIS)); vFrame.getContentPane().add(BorderLayout.CENTER, vPanel); vLockButton.addActionListener(new vLockButton_Click()); vCloseButton.addActionListener(new vCloseButton_Click()); vBrowseButton.addActionListener(new vBrowseButton_Click()); }
From source file:ddf.catalog.pubsub.command.ListCommandTest.java
/** * Test subscriptions:list command with no args. Should return all registered subscriptions. * * @throws Exception//w ww .j a va 2 s . c o m */ @Test public void testListNoArgsSubscriptionsFound() throws Exception { ListCommand listCommand = new ListCommand(); BundleContext bundleContext = mock(BundleContext.class); listCommand.setBundleContext(bundleContext); ServiceReference mySubscription = mock(ServiceReference.class); when(mySubscription.getPropertyKeys()).thenReturn(new String[] { SUBSCRIPTION_ID_PROPERTY_KEY }); when(mySubscription.getProperty("subscription-id")).thenReturn(MY_SUBSCRIPTION_ID); ServiceReference yourSubscription = mock(ServiceReference.class); when(yourSubscription.getPropertyKeys()).thenReturn(new String[] { SUBSCRIPTION_ID_PROPERTY_KEY }); when(yourSubscription.getProperty(SUBSCRIPTION_ID_PROPERTY_KEY)).thenReturn(YOUR_SUBSCRIPTION_ID); ServiceReference[] refs = new ServiceReference[] { mySubscription, yourSubscription }; when(bundleContext.getServiceReferences(eq(SubscriptionsCommand.SERVICE_PID), anyString())) .thenReturn(refs); PrintStream realSystemOut = System.out; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); System.setOut(new PrintStream(buffer)); // when listCommand.doExecute(); /* cleanup */ System.setOut(realSystemOut); // then List<String> linesWithText = getConsoleOutputText(buffer); assertThat(linesWithText.size(), is(4)); assertThat(linesWithText, hasItems( "Total subscriptions found: 2", ListCommand.CYAN_CONSOLE_COLOR + ListCommand.SUBSCRIPTION_ID_COLUMN_HEADER + ListCommand.DEFAULT_CONSOLE_COLOR, MY_SUBSCRIPTION_ID, YOUR_SUBSCRIPTION_ID)); buffer.close(); }
From source file:com.clematis.jsmodify.JSExecutionTracer.java
/** * Initialize the plugin and create folders if needed. * /*from w ww .j ava 2 s . c o m*/ * @param browser * The browser. */ public static void preCrawling() { try { points = new JSONArray(); Helper.directoryCheck(getOutputFolder()); output = new PrintStream(getOutputFolder() + getFilename()); // Add opening bracket around whole trace PrintStream oldOut = System.out; System.setOut(output); System.out.println("{"); System.setOut(oldOut); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.duniter.client.actions.NetworkAction.java
@Override public void run() { peerParameters.parse();//from w ww. j a v a2s.c o m final Peer mainPeer = peerParameters.getPeer(); checkOutputFileIfNotNull(); // make sure the file (if any) is writable // Reducing node timeout when broadcast if (peerParameters.timeout != null) { Configuration.instance().getApplicationConfig().setOption(ConfigurationOption.NETWORK_TIMEOUT.getKey(), peerParameters.timeout.toString()); } dateFormat = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.MEDIUM, I18n.getDefaultLocale()); console = new RegexAnsiConsole(); System.setOut(console); log.info(I18n.t("duniter4j.client.network.loadingPeers")); NetworkService service = ServiceLocator.instance().getNetworkService(); if (!autoRefresh) { List<Peer> peers = service.getPeers(mainPeer); showPeersTable(peers, false); } else { service.addPeersChangeListener(mainPeer, peers -> showPeersTable(peers, true)); try { while (true) { Thread.sleep(10000); // 10 s } } catch (InterruptedException e) { e.printStackTrace(); } } }