List of usage examples for java.lang System setOut
public static void setOut(PrintStream out)
From source file:com.findcomputerstuff.nips.DefaultSecurityModule.java
private String processMessage(String message, MessageAction action) { String outStr = null;/*from w ww . ja v a 2 s . c o m*/ SSMLib ssm = new nfp.ssm.core.SSMLib(publicKeyFile, privateKeyFile); try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { PrintStream console = System.out; try (PrintStream ps = new PrintStream(os)) { System.setOut(ps); /* redirect stdout */ } switch (action) { case DECRYPT: outStr = ssm.decryptFile(message, privateKeyPassword); break; case ENCRYPT: outStr = ssm.encryptMessage(message); break; } System.out.flush(); System.setOut(console); /* restore stdout */ if (StringUtils.isBlank(outStr)) throw new SsmEncryptionException(os.toString()); } catch (IOException e) { e.printStackTrace(); } return outStr; }
From source file:edu.rit.flick.util.FlickTest.java
@BeforeClass public static void setUpStreams() { oldOut = System.out;/*from ww w . j a va 2 s . c o m*/ oldErr = System.err; System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); }
From source file:org.apache.zookeeper.server.persistence.TxnLogToolkitTest.java
@After public void tearDown() throws IOException { System.setOut(System.out); System.setErr(System.err); mySnapDir.setWritable(true);//from w ww . j a va2s. com FileUtils.deleteDirectory(mySnapDir); }
From source file:com.example.DatastoreSampleApplicationTests.java
@BeforeClass public static void checkToRun() { assumeThat(System.getProperty("it.datastore")).as("Datastore sample integration tests are disabled. " + "Please use '-Dit.datastore=true' to enable them.").isEqualTo("true"); systemOut = System.out;/* w w w . ja v a 2 s . com*/ baos = new ByteArrayOutputStream(); TeeOutputStream out = new TeeOutputStream(systemOut, baos); System.setOut(new PrintStream(out)); }
From source file:com.tvh.infrastructure.openedge.Broker.java
public BrokerStatus getStatus() throws RemoteException { PrintStream nulloutput = new PrintStream(new NullOutputStream()); PrintStream out = System.out; PrintStream err = System.err; int maxAgents = 0; int maxClients = 0; try {//w ww . java2s . c om System.setOut(nulloutput); System.setErr(nulloutput); IChimeraRemoteCommand connect = server.connect(getBrokerName()); int result = connect.runIt(new String[] { (type == BrokerType.ASBROKER ? "AS" : "WS"), "q" }); if (connect.getSystemOutput().contains("(8313)")) { return new BrokerStatus(BrokerStatus.RunningStatus.STOPPED); } connect.runIt(new String[] { (type == BrokerType.ASBROKER ? "AS" : "WS"), "z", "maxSrvrInstance" }); maxAgents = Integer.parseInt(connect.getStructuredSystemOutput().get("maxSrvrInstance").toString()); connect.runIt(new String[] { (type == BrokerType.ASBROKER ? "AS" : "WS"), "z", "maxClientInstance" }); maxClients = Integer.parseInt(connect.getStructuredSystemOutput().get("maxClientInstance").toString()); } finally { System.setOut(out); System.setErr(err); } HashMap<Integer, String> labels = new HashMap<>(15); HashMap<String, String> values = new HashMap<>(15); ToolRemoteCmdDescriptor cmd = new ToolRemoteCmdDescriptor(); ToolRemoteCmdStatus cmdStatus; cmd.makeGetSummaryStatusLblPkt((type == BrokerType.ASBROKER ? "AS." : "WS.") + getBrokerName()); /*cmd.makeGetSummaryStatusDataPkt( (type == BrokerType.ASBROKER ? "AS." : "WS.") + getBrokerName() );*/ ToolRemoteCmdStatus labelFetcher = remoteStub.getRemoteManageObject().doRemoteToolCmd(cmd); Enumeration summaryLabels = labelFetcher.fetchGetSummaryStatuslblStatus(); if (summaryLabels != null) { int i = 0; while (summaryLabels.hasMoreElements()) { String label = (String) summaryLabels.nextElement(); labels.put(i, label.trim()); i++; } cmd.makeGetSummaryStatusDataPkt((type == BrokerType.ASBROKER ? "AS." : "WS.") + getBrokerName()); ToolRemoteCmdStatus statusFetcher = remoteStub.getRemoteManageObject().doRemoteToolCmd(cmd); Enumeration summaryValues = statusFetcher.fetchGetSummaryStatusDataStatus(); i = 0; while (summaryValues.hasMoreElements()) { String value = (String) summaryValues.nextElement(); values.put(labels.get(i), value.trim()); i++; } } return new BrokerStatus(values, maxAgents, maxClients); }
From source file:org.apache.oozie.cli.TestValidation.java
private String captureOutput(String[] args) throws ParseException { OozieCLI cli = new OozieCLI(); CLIParser parser = cli.getCLIParser(); CLIParser.Command command = parser.parse(args); PrintStream original = System.out; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); String outStr = null;//from w w w .j a v a 2 s. co m System.out.flush(); try { System.setOut(ps); cli.validateCommandV41(command.getCommandLine()); System.out.flush(); outStr = baos.toString(); } catch (OozieCLIException e) { outStr = e.getMessage(); } finally { System.setOut(original); if (outStr != null) { System.out.print(outStr); } System.out.flush(); } return outStr; }
From source file:org.apache.hadoop.gateway.KnoxCliLdapFuncTestNegative.java
@BeforeClass public static void setupSuite() throws Exception { LOG_ENTER();/* w w w.j a v a 2 s.c o m*/ System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); setupLdap(); setupGateway(); LOG_EXIT(); }
From source file:org.apache.hadoop.hdfs.server.namenode.TestFsck.java
static String runFsck(Configuration conf, int expectedErrCode, boolean checkErrorCode, String... path) throws Exception { PrintStream oldOut = System.out; ByteArrayOutputStream bStream = new ByteArrayOutputStream(); PrintStream newOut = new PrintStream(bStream, true); System.setOut(newOut); ((Log4JLogger) FSPermissionChecker.LOG).getLogger().setLevel(Level.ALL); int errCode = ToolRunner.run(new DFSck(conf), path); if (checkErrorCode) assertEquals(expectedErrCode, errCode); ((Log4JLogger) FSPermissionChecker.LOG).getLogger().setLevel(Level.INFO); System.setOut(oldOut);/* w w w. j a va 2 s. co m*/ return bStream.toString(); }
From source file:com.excilys.ebi.utils.spring.log.logback.LogbackConfigurerTestExecutionListenerTest.java
/** * The logback-test.xml defines a Console output. Console output is * temporarily trapped so that we can check what is written. *//*from w w w . j a v a2 s . c o m*/ @Test public void testConsoleLogger() { PrintStream stdout = System.out; String log = null; try { // replace console standard output ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps); logger.debug("something in DEBUG"); log = os.toString(); } finally { // restore console standard output System.setOut(stdout); } Assert.assertTrue("Output log is incorrect", log.contains( "DEBUG c.e.e.u.s.l.l.LogbackConfigurerTestExecutionListenerTest.testConsoleLogger - something in DEBUG")); }
From source file:cpd3314.project.CPD3314ProjectTest.java
@After public void tearDown() { System.setOut(null); System.setErr(null); }