List of usage examples for java.lang System setOut
public static void setOut(PrintStream out)
From source file:eu.scape_project.droid_identify.DroidIdentification.java
public void startApplication() throws IOException { long startClock = System.currentTimeMillis(); File dir = new File(appConfig.getInputStr()); // if (!dir.isDirectory()) { // throw new IllegalArgumentException("Input is not a directory: " + appConfig.getInputStr()); // }//from w ww.ja va 2 s . c om PrintStream pout = null; String outputPathStr = appConfig.getOutputStr(); if (outputPathStr != null) { FileOutputStream fos; try { fos = new FileOutputStream(outputPathStr, true); pout = new PrintStream(fos); System.setOut(pout); } catch (FileNotFoundException ex) { LOG.error("File not found error", ex); } } this.processFiles(new File(appConfig.getInputStr())); if (pout != null) { pout.close(); } long elapsedTimeMillis = System.currentTimeMillis() - startClock; LOG.info("Identification finished after " + elapsedTimeMillis + " milliseconds"); }
From source file:com.blackberry.logtools.LogTools.java
public void setConsoleOutput(File local_output, boolean quiet, boolean silent) throws Exception { //Setting all system outputs to write to local_output file FileOutputStream logfile = new FileOutputStream(local_output); System.setOut(new PrintStream(new TeeOutputStream(System.out, logfile))); System.setOut(new PrintStream(new TeeOutputStream(System.err, logfile))); //Setting all LOGs to write to local_output file Properties prop = new Properties(); if (!quiet && !silent) { prop.setProperty("log4j.rootLogger", "INFO, console, WORKLOG"); prop.setProperty("log4j.appender.console", "org.apache.log4j.ConsoleAppender"); prop.setProperty("log4j.appender.console.target", "System.err"); prop.setProperty("log4j.appender.console.layout", "org.apache.log4j.PatternLayout"); prop.setProperty("log4j.appender.console.layout.ConversionPattern", "%d [%p - %l] %m%n"); } else {/*from w w w . ja v a 2 s . com*/ prop.setProperty("log4j.rootLogger", "INFO, WORKLOG"); } prop.setProperty("log4j.appender.WORKLOG", "org.apache.log4j.FileAppender"); prop.setProperty("log4j.appender.WORKLOG.File", local_output.toString()); prop.setProperty("log4j.appender.WORKLOG.layout", "org.apache.log4j.PatternLayout"); prop.setProperty("log4j.appender.WORKLOG.layout.ConversionPattern", "%d %c{1} - %m%n"); PropertyConfigurator.configure(prop); }
From source file:org.apache.rocketmq.tools.command.message.ConsumeMessageCommandTest.java
@Test public void testExecuteDefaultWhenPullMessageByQueueGotException() throws SubCommandException, InterruptedException, RemotingException, MQClientException, MQBrokerException, NoSuchFieldException, IllegalAccessException { DefaultMQPullConsumer defaultMQPullConsumer = mock(DefaultMQPullConsumer.class); when(defaultMQPullConsumer.pull(any(MessageQueue.class), anyString(), anyLong(), anyInt())) .thenThrow(Exception.class); Field producerField = ConsumeMessageCommand.class.getDeclaredField("defaultMQPullConsumer"); producerField.setAccessible(true);/*from w ww . ja v a 2 s . c o m*/ producerField.set(consumeMessageCommand, defaultMQPullConsumer); PrintStream out = System.out; ByteArrayOutputStream bos = new ByteArrayOutputStream(); System.setOut(new PrintStream(bos)); Options options = ServerUtil.buildCommandlineOptions(new Options()); String[] subargs = new String[] { "-t topic-not-existu", "-n localhost:9876" }; CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + consumeMessageCommand.commandName(), subargs, consumeMessageCommand.buildCommandlineOptions(options), new PosixParser()); consumeMessageCommand.execute(commandLine, options, null); System.setOut(out); String s = new String(bos.toByteArray()); Assert.assertTrue(!s.contains("Consume ok")); }
From source file:org.apache.hadoop.yarn.client.cli.TestYarnCLI.java
@Before public void setup() { sysOutStream = new ByteArrayOutputStream(); sysOut = spy(new PrintStream(sysOutStream)); sysErrStream = new ByteArrayOutputStream(); sysErr = spy(new PrintStream(sysErrStream)); System.setOut(sysOut); }
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 w w w .java 2s . c o m })); this.className = className; openOutputFile(); }
From source file:org.codice.ddf.catalog.pubsub.command.ListCommandTest.java
/** * Test subscriptions:list command with source and enterprise subscriptions. Make sure enterprise * and source id info is printed.//from w w w . ja v a 2 s. com * * @throws Exception */ @Test public void testListNoArgsSourceAndEnterpriseSubscriptionFound() throws Exception { ListCommand listCommand = new ListCommand(); BundleContext bundleContext = mock(BundleContext.class); listCommand.setBundleContext(bundleContext); Subscription sourceSubscription = mock(Subscription.class); when(sourceSubscription.getSourceIds()).thenReturn(Collections.singleton("source.id")); when(sourceSubscription.isEnterprise()).thenReturn(false); ServiceReference<Subscription> sourceSubscriptionReference = mock(ServiceReference.class); when(sourceSubscriptionReference.getPropertyKeys()) .thenReturn(new String[] { SUBSCRIPTION_ID_PROPERTY_KEY }); when(sourceSubscriptionReference.getProperty("subscription-id")).thenReturn(MY_SUBSCRIPTION_ID); when(bundleContext.getService(sourceSubscriptionReference)).thenReturn(sourceSubscription); Subscription enterpriseSubscription = mock(Subscription.class); when(enterpriseSubscription.getSourceIds()).thenReturn(null); when(enterpriseSubscription.isEnterprise()).thenReturn(true); ServiceReference enterpriseSubscriptionReference = mock(ServiceReference.class); when(enterpriseSubscriptionReference.getPropertyKeys()) .thenReturn(new String[] { SUBSCRIPTION_ID_PROPERTY_KEY }); when(enterpriseSubscriptionReference.getProperty(SUBSCRIPTION_ID_PROPERTY_KEY)) .thenReturn(YOUR_SUBSCRIPTION_ID); when(bundleContext.getService(enterpriseSubscriptionReference)).thenReturn(enterpriseSubscription); ServiceReference[] refs = new ServiceReference[] { sourceSubscriptionReference, enterpriseSubscriptionReference }; 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.execute(); /* cleanup */ System.setOut(realSystemOut); // then List<String> linesWithText = getConsoleOutputText(buffer); assertThat(linesWithText.size(), is(4)); assertThat(linesWithText, hasItems(containsString("Total subscriptions found: 2"), allOf(containsString(MY_SUBSCRIPTION_ID), containsString("false"), containsString("source.id")), allOf(containsString(YOUR_SUBSCRIPTION_ID), containsString("true")))); buffer.close(); }
From source file:org.pantsbuild.tools.junit.impl.ConsoleRunnerTest.java
@Test public void testConsoleOutput() { ByteArrayOutputStream outContent = new ByteArrayOutputStream(); PrintStream stdout = System.out; PrintStream stderr = System.err; try {/* www.ja va2 s . c o m*/ System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(new ByteArrayOutputStream())); invokeConsoleRunner("MockTest4 -parallel-threads 1 -xmlreport"); Assert.assertEquals("test41 test42", TestRegistry.getCalledTests()); String output = outContent.toString(); assertThat(output, containsString("test41")); assertThat(output, containsString("start test42")); assertThat(output, containsString("end test42")); } finally { System.setOut(stdout); System.setErr(stderr); } }
From source file:org.jamocha.gui.JamochaGui.java
@Override public void stop() { saveState(this.primaryStage); this.jamocha.shutdown(); System.setOut(this.out); System.setErr(this.err); }
From source file:org.kaaproject.kaa.server.control.cli.ControlServerCliIT.java
/** * Before test./*w w w . j a v a2 s . c om*/ * * @throws Exception the exception */ @Before public void beforeTest() throws Exception { MongoDataLoader.loadData(); TestCluster.checkStarted(controlService); controlClientSession = new ControlClientSessionState(); controlClientSession.in = System.in; systemOut = new ByteArrayOutputStream(); PrintStream out = new PrintStream(systemOut, true, "UTF-8"); System.setOut(out); systemErr = new ByteArrayOutputStream(); PrintStream err = new PrintStream(systemErr, true, "UTF-8"); System.setErr(err); cliOut = new ByteArrayOutputStream(); controlClientSession.out = new PrintStream(cliOut, true, "UTF-8"); cliErr = new ByteArrayOutputStream(); controlClientSession.err = new PrintStream(cliErr, true, "UTF-8"); ControlClientSessionState.start(controlClientSession); }