List of usage examples for java.lang System setErr
public static void setErr(PrintStream err)
From source file:com.izforge.izpack.event.AntAction.java
/** * Performs all defined actions.//from w ww. j a v a 2 s.c o m * * @param uninstall An install/uninstall switch. If this is <tt>true</tt> only the uninstall * actions, otherwise only the install actions are being performed. * @throws IzPackException for any error * @see #performInstallAction() for calling all install actions. * @see #performUninstallAction() for calling all uninstall actions. */ public void performAction(boolean uninstall) throws IzPackException { if (verbose) { System.out.print("Calling ANT with buildfile: " + buildFile); System.out.print(buildDir != null ? " in directory " + buildDir : " in default base directory"); System.out.println(); } SecurityManager oldsm = null; if (!JavaEnvUtils.isJavaVersion("1.0") && !JavaEnvUtils.isJavaVersion("1.1")) { oldsm = System.getSecurityManager(); } PrintStream err = System.err; PrintStream out = System.out; Project antProj = new Project(); try { antProj.setInputHandler(new AntActionInputHandler()); antProj.setName("antcallproject"); if (verbose) { logLevel = AntLogLevel.VERBOSE; } else if (quiet) { logLevel = AntLogLevel.WARNING; } final int antLogLevel = logLevel.getLevel(); antProj.addBuildListener(new AntSystemLogBuildListener(antLogLevel)); if (logFile != null) { antProj.addBuildListener(new AntActionLogBuildListener(logFile, logFileAppend, antLogLevel)); } antProj.setSystemProperties(); addProperties(antProj, getProperties()); addPropertiesFromPropertyFiles(antProj); // TODO: propertyfiles, logFile antProj.fireBuildStarted(); antProj.init(); List<Ant> antcalls = new ArrayList<Ant>(); List<String> choosenTargets = (uninstall) ? uninstallTargets : targets; if (choosenTargets.size() > 0) { Ant antcall; for (String choosenTarget : choosenTargets) { antcall = (Ant) antProj.createTask("ant"); if (buildDir != null) { antcall.setDir(buildDir); } antcall.setAntfile(buildFile.getAbsolutePath()); antcall.setTarget(choosenTarget); antcalls.add(antcall); } } Target target = new Target(); target.setName("calltarget"); for (Ant antcall : antcalls) { target.addTask(antcall); } antProj.addTarget(target); System.setOut(new PrintStream(new DemuxOutputStream(antProj, false))); System.setErr(new PrintStream(new DemuxOutputStream(antProj, true))); antProj.executeTarget("calltarget"); antProj.fireBuildFinished(null); } catch (BuildException exception) { antProj.fireBuildFinished(exception); throw new IzPackException("Ant build failed", exception, getSeverity()); } finally { if (oldsm != null) { System.setSecurityManager(oldsm); } System.setOut(out); System.setErr(err); } }
From source file:dk.netarkivet.archive.bitarchive.distribute.BitarchiveServer.java
/** * The server creates an instance of the bitarchive it provides access to * and starts to listen to JMS messages on the incomming jms queue * <p/>//w ww .j ava 2 s. c om * Also, heartbeats are sent out at regular intervals to the Bitarchive * Monitor, to tell that this bitarchive is alive. * * @throws UnknownID - if there was no heartbeat frequency or temp * dir defined in settings or if the * bitarchiveid cannot be created. * @throws PermissionDenied - if the temporary directory or the file * directory cannot be written */ private BitarchiveServer() throws UnknownID, PermissionDenied { System.setOut( new PrintStream(new LoggingOutputStream(LoggingOutputStream.LoggingLevel.INFO, log, "StdOut: "))); System.setErr( new PrintStream(new LoggingOutputStream(LoggingOutputStream.LoggingLevel.WARN, log, "StdErr: "))); boolean listening = false; // are we listening to queue ANY_BA File serverdir = FileUtils.getTempDir(); if (!serverdir.exists()) { serverdir.mkdirs(); } if (!serverdir.canWrite()) { throw new PermissionDenied("Not allowed to write to temp directory '" + serverdir + "'"); } log.info("Storing temporary files at '" + serverdir.getPath() + "'"); bitarchiveAppId = createBitarchiveAppId(); allBa = Channels.getAllBa(); anyBa = Channels.getAnyBa(); baMon = Channels.getTheBamon(); ba = Bitarchive.getInstance(); con = JMSConnectionFactory.getInstance(); con.setListener(allBa, this); baa = BitarchiveAdmin.getInstance(); if (baa.hasEnoughSpace()) { con.setListener(anyBa, this); listening = true; } else { log.warn("Not enough space to guarantee store -- not listening " + "to " + anyBa.getName()); } // create map for batchjobs batchProcesses = Collections.synchronizedMap(new HashMap<String, Thread>()); // Create and start the heartbeat sender Timer timer = new Timer(true); heartBeatSender = new HeartBeatSender(baMon, this); long frequency = Settings.getLong(ArchiveSettings.BITARCHIVE_HEARTBEAT_FREQUENCY); timer.scheduleAtFixedRate(heartBeatSender, 0, frequency); log.info("Heartbeat frequency: '" + frequency + "'"); // Next logentry depends on whether we are listening to ANY_BA or not String logmsg = "Created bitarchive server listening on: " + allBa.getName(); if (listening) { logmsg += " and " + anyBa.getName(); } log.info(logmsg); log.info("Broadcasting heartbeats on: " + baMon.getName()); }
From source file:org.apache.oozie.tools.TestOozieSharelibCLI.java
/** * test fake command//from w w w . j ava 2s . c om */ public void testFakeCommand() throws Exception { ByteArrayOutputStream data = new ByteArrayOutputStream(); PrintStream oldPrintStream = System.err; System.setErr(new PrintStream(data)); try { String[] argsFake = { "fakeCommand" }; assertEquals(1, execOozieSharelibCLICommands(argsFake)); assertTrue(data.toString().contains("Invalid sub-command: invalid sub-command [fakeCommand]")); assertTrue(data.toString().contains("use 'help [sub-command]' for help details")); } finally { System.setErr(oldPrintStream); } }
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 ww w . ja v a2 s . c om*/ })); this.className = className; openOutputFile(); }
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.pantsbuild.tools.junit.impl.ConsoleRunnerTest.java
@Test public void testConsoleOutput() { ByteArrayOutputStream outContent = new ByteArrayOutputStream(); PrintStream stdout = System.out; PrintStream stderr = System.err; try {/*from w w w . j a va 2 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.lnicholls.galleon.util.Tools.java
public static void redirectStandardStreams() { // Determine the path to the log dir String logDir = ""; if (System.getProperty("logfile") == null) { File file = new File("."); logDir = file.getAbsolutePath() + "/../logs"; } else {/*w ww . j a v a2 s . c o m*/ File logFile = new File(System.getProperty("logfile")); File dir = new File(logFile.getPath().substring(0, logFile.getPath().lastIndexOf(File.separator))); logDir = dir.getAbsolutePath(); } // Create a new output stream for the standard output. PrintStream stdout = null; try { stdout = new PrintStream(new FileOutputStream(logDir + "/Redirect.out")); System.setOut(stdout); } catch (Exception e) { log.error(e.toString()); } // Create new output stream for the standard error output. PrintStream stderr = null; try { stderr = new PrintStream(new FileOutputStream(logDir + "/Redirect.err")); System.setErr(stderr); } catch (Exception e) { log.error(e.toString()); } }
From source file:org.jetbrains.webdemo.executors.JunitExecutor.java
@Override public void testStarted(Description description) { currentTestRunInfo = new TestRunInfo(); currentTestRunInfo.className = description.getClassName(); currentTestRunInfo.methodName = description.getMethodName(); JunitExecutor.output.add(currentTestRunInfo); testOutputStream = new ByteArrayOutputStream(); errorStream = new ErrorStream(testOutputStream); outStream = new OutStream(testOutputStream); System.setOut(new PrintStream(outStream)); System.setErr(new PrintStream(errorStream)); startTime = System.currentTimeMillis(); }
From source file:org.kaaproject.kaa.server.control.cli.ControlServerCliIT.java
/** * Before test./* w w w . j av a 2s . c o m*/ * * @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); }
From source file:org.commonjava.sjbi.sant.SimpleAntMechanism.java
private void build(final File buildFile, final String[] targets, final SimpleAntResult result) { final InputStream origIn = System.in; final PrintStream origOut = System.out; final PrintStream origErr = System.err; final Project project = new Project(); Throwable error = null;//from w w w .j av a 2 s.c om try { project.addBuildListener(new DefaultLogger()); project.setDefaultInputStream(System.in); System.setIn(new DemuxInputStream(project)); System.setOut(new PrintStream(new DemuxOutputStream(project, false))); System.setErr(new PrintStream(new DemuxOutputStream(project, true))); project.fireBuildStarted(); project.init(); // TODO: Handle properties, via context...? // project.setUserProperty(arg, value); project.setUserProperty(MagicNames.ANT_FILE, buildFile.getAbsolutePath()); project.setUserProperty(MagicNames.ANT_FILE_TYPE, MagicNames.ANT_FILE_TYPE_FILE); project.setKeepGoingMode(false); ProjectHelper.configureProject(project, buildFile); project.executeTargets(new Vector<String>(Arrays.asList(targets))); } catch (final RuntimeException e) { error = e; result.addError(new SJBIException("Error occurred in Ant build: %s\nTargets: [%s]\nBuild file: %s", e, e.getMessage(), join(targets, ", "), buildFile)); } catch (final Error e) { error = e; result.addError(new SJBIException("Error occurred in Ant build: %s\nTargets: [%s]\nBuild file: %s", e, e.getMessage(), join(targets, ", "), buildFile)); } finally { project.fireBuildFinished(error); System.setIn(origIn); System.setOut(origOut); System.setErr(origErr); } }