List of usage examples for java.lang System setErr
public static void setErr(PrintStream err)
From source file:org.apache.hadoop.hbase.mapreduce.TestRowCounter.java
/** * test main method. Import should print help and call System.exit *///www . j a v a2 s . c o m @Test public void testImportMain() throws Exception { PrintStream oldPrintStream = System.err; SecurityManager SECURITY_MANAGER = System.getSecurityManager(); LauncherSecurityManager newSecurityManager = new LauncherSecurityManager(); System.setSecurityManager(newSecurityManager); ByteArrayOutputStream data = new ByteArrayOutputStream(); String[] args = {}; System.setErr(new PrintStream(data)); try { System.setErr(new PrintStream(data)); try { RowCounter.main(args); fail("should be SecurityException"); } catch (SecurityException e) { assertEquals(-1, newSecurityManager.getExitCode()); assertTrue(data.toString().contains("Wrong number of parameters:")); assertTrue(data.toString() .contains("Usage: RowCounter [options] <tablename> [--range=[startKey],[endKey]] " + "[<column1> <column2>...]")); assertTrue(data.toString().contains("-Dhbase.client.scanner.caching=100")); assertTrue(data.toString().contains("-Dmapreduce.map.speculative=false")); } data.reset(); try { args = new String[2]; args[0] = "table"; args[1] = "--range=1"; RowCounter.main(args); fail("should be SecurityException"); } catch (SecurityException e) { assertEquals(-1, newSecurityManager.getExitCode()); assertTrue(data.toString().contains( "Please specify range in such format as \"--range=a,b\" or, with only one boundary," + " \"--range=,b\" or \"--range=a,\"")); assertTrue(data.toString() .contains("Usage: RowCounter [options] <tablename> [--range=[startKey],[endKey]] " + "[<column1> <column2>...]")); } } finally { System.setErr(oldPrintStream); System.setSecurityManager(SECURITY_MANAGER); } }
From source file:org.apache.flink.client.program.Client.java
public OptimizedPlan getOptimizedPlan(PackagedProgram prog, int parallelism) throws CompilerException, ProgramInvocationException { Thread.currentThread().setContextClassLoader(prog.getUserCodeClassLoader()); if (prog.isUsingProgramEntryPoint()) { return getOptimizedPlan(prog.getPlanWithJars(), parallelism); } else if (prog.isUsingInteractiveMode()) { // temporary hack to support the optimizer plan preview OptimizerPlanEnvironment env = new OptimizerPlanEnvironment(this.compiler); if (parallelism > 0) { env.setDegreeOfParallelism(parallelism); }/*from w w w.ja v a 2 s . co m*/ env.setAsContext(); // temporarily write syser and sysout to bytearray. PrintStream originalOut = System.out; PrintStream originalErr = System.err; ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); ByteArrayOutputStream baes = new ByteArrayOutputStream(); System.setErr(new PrintStream(baes)); try { ContextEnvironment.disableLocalExecution(); prog.invokeInteractiveModeForExecution(); } catch (ProgramInvocationException e) { throw e; } catch (Throwable t) { // the invocation gets aborted with the preview plan if (env.optimizerPlan != null) { return env.optimizerPlan; } else { throw new ProgramInvocationException("The program caused an error: ", t); } } finally { System.setOut(originalOut); System.setErr(originalErr); System.err.println(baes); System.out.println(baos); } throw new ProgramInvocationException( "The program plan could not be fetched. The program silently swallowed the control flow exceptions.\n" + "System.err: " + StringEscapeUtils.escapeHtml4(baes.toString()) + " \n" + "System.out: " + StringEscapeUtils.escapeHtml4(baos.toString()) + " \n"); } else { throw new RuntimeException(); } }
From source file:org.apache.hadoop.hive.cli.TestCliDriverMethods.java
public void testRun() throws Exception { // clean history String historyDirectory = System.getProperty("user.home"); if ((new File(historyDirectory)).exists()) { File historyFile = new File(historyDirectory + File.separator + ".hivehistory"); historyFile.delete();/*from w w w. ja v a 2s.c o m*/ } HiveConf configuration = new HiveConf(); configuration.setBoolVar(ConfVars.HIVE_SESSION_HISTORY_ENABLED, true); PrintStream oldOut = System.out; ByteArrayOutputStream dataOut = new ByteArrayOutputStream(); System.setOut(new PrintStream(dataOut)); PrintStream oldErr = System.err; ByteArrayOutputStream dataErr = new ByteArrayOutputStream(); System.setErr(new PrintStream(dataErr)); CliSessionState ss = new CliSessionState(configuration); CliSessionState.start(ss); String[] args = {}; try { new FakeCliDriver().run(args); assertTrue(dataOut.toString(), dataOut.toString().contains("test message")); assertTrue(dataErr.toString(), dataErr.toString().contains("Hive history file=")); assertTrue(dataErr.toString(), dataErr.toString().contains("File: fakeFile is not a file.")); dataOut.reset(); dataErr.reset(); } finally { System.setOut(oldOut); System.setErr(oldErr); } }
From source file:net.technicpack.launcher.LauncherMain.java
private static void setupLogging(LauncherDirectories directories, ResourceLoader resources) { System.out.println("Setting up logging"); final Logger logger = Utils.getLogger(); File logDirectory = new File(directories.getLauncherDirectory(), "logs"); if (!logDirectory.exists()) { logDirectory.mkdir();//from ww w .j ava 2 s . c o m } File logs = new File(logDirectory, "techniclauncher_%D.log"); RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath()); fileHandler.setFormatter(new BuildLogFormatter(resources.getLauncherBuild())); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(fileHandler); logger.setUseParentHandlers(false); LauncherMain.consoleFrame = new ConsoleFrame(2500, resources.getImage("icon.png")); Console console = new Console(LauncherMain.consoleFrame, resources.getLauncherBuild()); logger.addHandler(new ConsoleHandler(console)); System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true)); System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true)); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { e.printStackTrace(); logger.log(Level.SEVERE, "Unhandled Exception in " + t, e); // if (errorDialog == null) { // LauncherFrame frame = null; // // try { // frame = Launcher.getFrame(); // } catch (Exception ex) { // //This can happen if we have a very early crash- before Launcher initializes // } // // errorDialog = new ErrorDialog(frame, e); // errorDialog.setVisible(true); // } } }); }
From source file:org.eclipse.virgo.medic.impl.LogController.java
public void logStop() { System.setProperty(PROPERTY_LOGBACK_CONTEXT_SELECTOR, DEFAULT_CONTEXT_SELECTOR); DelegatingContextSelector.setDelegate(null); if (this.sysOut != null) { System.setOut(this.sysOut); }/*from ww w . j a v a2s. c o m*/ if (this.sysErr != null) { System.setErr(this.sysErr); } SLF4JBridgeHandler.uninstall(); enableJulConsoleLogger(); }
From source file:mil.dod.th.ose.junit4xmltestrunner.ant.XMLJUnitResultFormatter.java
/** * The whole test suite ended./*from w w w . ja v a 2 s .c o m*/ * * @param results * Results of the testing * @throws IOException * Thrown if unable to write results to output stream */ public void endTestSuite(final Result results) throws IOException { System.setOut(m_OldStdOut); System.setErr(m_OldStdErr); Logging.log(LogService.LOG_INFO, "%n############%n%s%ntests ran: %d, failures: %d%n############", m_RootElement.getAttribute(ATTR_NAME), results.getRunCount(), results.getFailureCount()); setSystemOutput(); setSystemError(); m_RootElement.setAttribute(ATTR_TESTS, "" + results.getRunCount()); m_RootElement.setAttribute(ATTR_FAILURES, "" + m_Failures); m_RootElement.setAttribute(ATTR_ERRORS, "" + m_Errors); m_RootElement.setAttribute(ATTR_TIME, "" + (results.getRunTime() / ONE_SECOND)); if (m_Out != null) { Writer wri = null; try { wri = new BufferedWriter(new OutputStreamWriter(m_Out, "UTF8")); wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); (new DOMElementWriter()).write(m_RootElement, wri, 0, " "); } finally { if (wri != null) { try { wri.flush(); } catch (final IOException ex) { // ignore } } if (m_Out != System.out && m_Out != System.err) { wri.close(); } } } }
From source file:com.cic.datacrawl.ui.Main.java
private static void startupGUI(String[] args) { // ??/* w ww. jav a2s. c o m*/ boolean isShowChooseWorkspace = true; Main main = new Main(SwingGui.FRAME_TITLE); if (isShowChooseWorkspace) { ChooseWorkspaceDialog dialog = new ChooseWorkspaceDialog(main.debugGui); dialog.setStartupArgs(args); dialog.setVisible(true); } Global global = Global.getInstance(); main.setExitAction(new IProxy(IProxy.EXIT_ACTION)); main.attachTo(com.cic.datacrawl.ui.shell.Shell.shellContextFactory); main.setScope(global); main.setGlobal(global); main.pack(); main.startupBrowser(); main.maxSize(); if (!isShowChooseWorkspace) { main.setVisible(true); } if (args.length == 2) { args = new String[0]; } global.setIn(main.getIn()); global.setOut(main.getOut()); global.setErr(main.getErr()); System.setIn(main.getIn()); System.setOut(main.getOut()); System.setErr(main.getErr()); com.cic.datacrawl.ui.shell.Shell.setDebugGui(main.debugGui); final RhinoDim finalDim = main.dim; new Thread(new Runnable() { @Override public void run() { while (InitializerRegister.getInstance().isNotFinished()) try { Thread.sleep(100); } catch (InterruptedException e) { } ((RunOnStartup) ApplicationContext.getInstance().getBean("runOnStartup")).execute(finalDim); } }).start(); new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(60000); } catch (InterruptedException e) { } System.gc(); } } }).start(); // ? AutoSaveConfiguration autoSaveRunner = new AutoSaveConfiguration(); autoSaveRunner.registerSaveRunner(main.debugGui); autoSaveRunner.setSleepSecond(3600); new Thread(autoSaveRunner).start(); com.cic.datacrawl.ui.shell.Shell.exec(args, global); }
From source file:com.stimulus.archiva.domain.FileSystem.java
public void initLogging() { //PrintStream stdout = System.out; //PrintStream stderr = System.err; LoggingOutputStream los;/* w w w. j a v a 2s . com*/ los = new com.stimulus.util.LoggingOutputStream(logger); System.setOut(new PrintStream(los, true)); System.setErr(new PrintStream(los, true)); }
From source file:org.apache.hadoop.hdfs.server.namenode.TestClusterId.java
/** * Test namenode format with -clusterid -force option. Format command should * fail as no cluster id was provided.//w w w . ja v a 2s.c o m * * @throws IOException */ @Test(timeout = 450000) public void testFormatWithInvalidClusterIdOption() throws IOException { String[] argv = { "-format", "-clusterid", "-force" }; PrintStream origErr = System.err; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream stdErr = new PrintStream(baos); System.setErr(stdErr); NameNode.createNameNode(argv, config); // Check if usage is printed assertTrue(baos.toString("UTF-8").contains("Usage: java NameNode")); System.setErr(origErr); // check if the version file does not exists. File version = new File(hdfsDir, "current/VERSION"); assertFalse("Check version should not exist", version.exists()); }
From source file:edu.clemson.cs.nestbed.server.Server.java
public Server() throws MalformedURLException, RemoteException { System.setOut(//from w w w . j av a2 s. com new PrintStream(new BufferedOutputStream(new LogOutputStream(System.class, Level.WARN)), true)); System.setErr( new PrintStream(new BufferedOutputStream(new LogOutputStream(System.class, Level.ERROR)), true)); log.info("******************************************************\n" + "** NESTbed Server Starting\n" + "******************************************************"); log.info("Version: " + Version.VERSION); ParentClassLoader.setParent(Server.class.getClassLoader()); // Create the RMI registry LocateRegistry.createRegistry(1099); moteManager = MoteManagerImpl.getInstance(); shutdownTrigger = new ShutdownTrigger(); programSymbolManager = ProgramSymbolManagerImpl.getInstance(); progProfSymbolManager = ProgramProfilingSymbolManagerImpl.getInstance(); programManager = ProgramManagerImpl.getInstance(); moteDepConfigManager = MoteDeploymentConfigurationManagerImpl.getInstance(); projDepConfigManager = ProjectDeploymentConfigurationManagerImpl.getInstance(); projectManager = ProjectManagerImpl.getInstance(); moteTypeManager = MoteTypeManagerImpl.getInstance(); moteTbAssignManager = MoteTestbedAssignmentManagerImpl.getInstance(); testbedManger = TestbedManagerImpl.getInstance(); progMsgSymbolManager = ProgramMessageSymbolManagerImpl.getInstance(); progProfMsgSymbolMgnr = ProgramProfilingMessageSymbolManagerImpl.getInstance(); messageManager = MessageManagerImpl.getInstance(); programDeploymentManager = ProgramDeploymentManagerImpl.getInstance(); programCompileManager = ProgramCompileManagerImpl.getInstance(); programWeaverManager = ProgramWeaverManagerImpl.getInstance(); programProbeManager = ProgramProbeManagerImpl.getInstance(); nucleusManager = NucleusManagerImpl.getInstance(); sfManager = SerialForwarderManagerImpl.getInstance(); motePowerManager = MotePowerManagerImpl.getInstance(); bindRemoteObjects(); }