List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:edu.stanford.muse.email.VerifyEmailSetup.java
public static Pair<Boolean, String> run() { PrintStream savedOut = System.out; InputStream savedIn = System.in; try {//from w w w . j av a2 s.c o m // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); session.setDebug(true); String filename = System.getProperty("java.io.tmpdir") + File.separatorChar + "verifyEmailSetup"; PrintStream ps = new PrintStream(new FileOutputStream(filename)); System.setOut(ps); System.setErr(ps); // Get a Store object Store store = null; store = session.getStore("imaps"); store.connect("imap.gmail.com", 993, "checkmuse", ""); // not the real password. unfortunately, the checkmuse a/c will get blocked by google. // Folder folder = store.getFolder("[Gmail]/Sent Mail"); // int totalMessages = folder.getMessageCount(); // System.err.println (totalMessages + " messages!"); ps.close(); String contents = Util.getFileContents(filename); System.out.println(contents); return new Pair<Boolean, String>(Boolean.TRUE, contents); } catch (AuthenticationFailedException e) { /* its ok if auth failed. we only want to check if IMAPS network route is blocked. when network is blocked, we'll get something like javax.mail.MessagingException: No route to host; nested exception is: java.net.NoRouteToHostException: No route to host ... */ log.info("Verification succeeded: " + Util.stackTrace(e)); return new Pair<Boolean, String>(Boolean.TRUE, ""); } catch (Exception e) { log.warn("Verification failed: " + Util.stackTrace(e)); return new Pair<Boolean, String>(Boolean.FALSE, e.toString()); // stack track reveals too much about our code... Util.stackTrace(e)); } finally { System.setOut(savedOut); System.setIn(savedIn); } }
From source file:StdErrOutWindows.java
public StdErrOutWindows() { JScrollPane pain = new JScrollPane(outArea); JFrame outFrame = new JFrame("out"); outFrame.getContentPane().add(pain); outFrame.setVisible(true);//from w w w. j av a2s . c o m pain = new JScrollPane(errArea); JFrame errFrame = new JFrame("err"); errFrame.getContentPane().add(pain); errFrame.setLocation(errFrame.getLocation().x + 20, errFrame.getLocation().y + 20); errFrame.setVisible(true); System.setOut(new PrintStream(new JTextAreaOutputStream(outArea))); System.setErr(new PrintStream(new JTextAreaOutputStream(errArea))); }
From source file:com.iciql.test.IciqlSuite.java
/** * Main entry point for the test suite. Executing this method will run the * test suite on all registered databases. * //from w w w .ja v a 2 s. co m * @param args * @throws Exception */ public static void main(String... args) throws Exception { Params params = new Params(); JCommander jc = new JCommander(params); try { jc.parse(args); } catch (ParameterException t) { usage(jc, t); } // Replace System.out with a file if (!StringUtils.isNullOrEmpty(params.dbPerformanceFile)) { out = new PrintStream(params.dbPerformanceFile); System.setErr(out); } deleteRecursively(new File("testdbs")); // Start the HSQL and H2 servers in-process org.hsqldb.Server hsql = startHSQL(); org.h2.tools.Server h2 = startH2(); // Statement logging final FileWriter statementWriter; if (StringUtils.isNullOrEmpty(params.sqlStatementsFile)) { statementWriter = null; } else { statementWriter = new FileWriter(params.sqlStatementsFile); } IciqlListener statementListener = new IciqlListener() { @Override public void logIciql(StatementType type, String statement) { if (statementWriter == null) { return; } try { statementWriter.append(statement); statementWriter.append('\n'); } catch (IOException e) { e.printStackTrace(); } } }; IciqlLogger.registerListener(statementListener); SuiteClasses suiteClasses = IciqlSuite.class.getAnnotation(SuiteClasses.class); long quickestDatabase = Long.MAX_VALUE; String dividerMajor = buildDivider('*', 79); String dividerMinor = buildDivider('-', 79); // Header out.println(dividerMajor); out.println(MessageFormat.format("{0} {1} ({2}) testing {3} database configurations", Constants.NAME, Constants.VERSION, Constants.VERSION_DATE, TEST_DBS.length)); out.println(dividerMajor); out.println(); showProperty("java.vendor"); showProperty("java.runtime.version"); showProperty("java.vm.name"); showProperty("os.name"); showProperty("os.version"); showProperty("os.arch"); showProperty("available processors", "" + Runtime.getRuntime().availableProcessors()); showProperty("available memory", MessageFormat.format("{0,number,0.0} GB", ((double) Runtime.getRuntime().maxMemory()) / (1024 * 1024))); out.println(); // Test a database long lastCount = 0; for (TestDb testDb : TEST_DBS) { out.println(dividerMinor); out.println("Testing " + testDb.describeDatabase()); out.println(" " + testDb.url); out.println(dividerMinor); // inject a database section delimiter in the statement log if (statementWriter != null) { statementWriter.append("\n\n"); statementWriter.append("# ").append(dividerMinor).append('\n'); statementWriter.append("# ").append("Testing " + testDb.describeDatabase()).append('\n'); statementWriter.append("# ").append(dividerMinor).append('\n'); statementWriter.append("\n\n"); } if (testDb.getVersion().equals("OFFLINE")) { // Database not available out.println("Skipping. Could not find " + testDb.url); out.println(); } else { // Setup system properties System.setProperty("iciql.url", testDb.url); System.setProperty("iciql.user", testDb.username); System.setProperty("iciql.password", testDb.password); // Test database Result result = JUnitCore.runClasses(suiteClasses.value()); // Report results testDb.runtime = result.getRunTime(); if (testDb.runtime < quickestDatabase) { quickestDatabase = testDb.runtime; } testDb.statements = IciqlLogger.getTotalCount() - lastCount; // reset total count for next database lastCount = IciqlLogger.getTotalCount(); out.println(MessageFormat.format( "{0} tests ({1} failures, {2} ignores) {3} statements in {4,number,0.000} secs", result.getRunCount(), result.getFailureCount(), result.getIgnoreCount(), testDb.statements, result.getRunTime() / 1000f)); if (result.getFailureCount() == 0) { out.println(); out.println(" 100% successful test suite run."); out.println(); } else { for (Failure failure : result.getFailures()) { out.println(MessageFormat.format("\n + {0}\n {1}", failure.getTestHeader(), failure.getMessage())); } out.println(); } } } // Display runtime results sorted by performance leader out.println(); out.println(dividerMajor); out.println(MessageFormat.format("{0} {1} ({2}) test suite performance results", Constants.NAME, Constants.VERSION, Constants.VERSION_DATE)); out.println(dividerMajor); List<TestDb> dbs = Arrays.asList(TEST_DBS); Collections.sort(dbs); out.println(MessageFormat.format("{0} {1} {2} {3} {4}", StringUtils.pad("Name", 11, " ", true), StringUtils.pad("Type", 5, " ", true), StringUtils.pad("Version", 23, " ", true), StringUtils.pad("Stats/Sec", 10, " ", true), "Runtime")); out.println(dividerMinor); for (TestDb testDb : dbs) { DecimalFormat df = new DecimalFormat("0.0"); out.println(MessageFormat.format("{0} {1} {2} {3} {4} {5}s ({6,number,0.0}x)", StringUtils.pad(testDb.name, 11, " ", true), testDb.isEmbedded ? "E" : "T", testDb.isMemory ? "M" : "F", StringUtils.pad(testDb.getVersion(), 21, " ", true), StringUtils.pad("" + testDb.getStatementRate(), 10, " ", false), StringUtils.pad(df.format(testDb.getRuntime()), 8, " ", false), ((double) testDb.runtime) / quickestDatabase)); } out.println(dividerMinor); out.println(" E = embedded connection"); out.println(" T = tcp/ip connection"); out.println(" M = memory database"); out.println(" F = file/persistent database"); // cleanup for (PoolableConnectionFactory factory : connectionFactories.values()) { factory.getPool().close(); } IciqlLogger.unregisterListener(statementListener); out.close(); System.setErr(ERR); if (statementWriter != null) { statementWriter.close(); } hsql.stop(); h2.stop(); System.exit(0); }
From source file:com.sec.ose.osi.util.tools.Tools.java
public static String getPrintStackTraceInfoString(Exception e) { String returnStackTraceString = e.toString(); ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(out); e.printStackTrace(printStream);// www.j a v a 2 s .c om returnStackTraceString = out.toString(); return returnStackTraceString; }
From source file:com.amazonaws.codepipeline.jenkinsplugin.TestUtils.java
public static ByteArrayOutputStream setOutputStream() { final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); System.setOut(new PrintStream(outContent)); return outContent; }
From source file:edu.msu.cme.rdp.seqmatch.cli.SeqmatchCheckRevSeq.java
public static void main(String[] args) throws Exception { String trainingFile = null;// w w w .j a va2 s. c o m String queryFile = null; String outputFile = null; PrintWriter revOutputWriter = new PrintWriter(System.out); PrintStream correctedQueryOut = System.out; String traineeDesc = null; int numOfResults = 20; boolean checkReverse = false; float diffScoreCutoff = CheckReverseSeq.DIFF_SCORE_CUTOFF; String format = "txt"; // default try { CommandLine line = new PosixParser().parse(options, args); if (line.hasOption("c")) { checkReverse = true; } if (line.hasOption("t")) { trainingFile = line.getOptionValue("t"); } else { throw new Exception("training file must be specified"); } if (line.hasOption("q")) { queryFile = line.getOptionValue("q"); } else { throw new Exception("query file must be specified"); } if (line.hasOption("o")) { outputFile = line.getOptionValue("o"); } else { throw new Exception("output file must be specified"); } if (line.hasOption("r")) { revOutputWriter = new PrintWriter(line.getOptionValue("r")); } if (line.hasOption("s")) { correctedQueryOut = new PrintStream(line.getOptionValue("s")); } if (line.hasOption("d")) { diffScoreCutoff = Float.parseFloat(line.getOptionValue("d")); } if (line.hasOption("h")) { traineeDesc = line.getOptionValue("h"); } if (line.hasOption("n")) { numOfResults = Integer.parseInt(line.getOptionValue("n")); } if (line.hasOption("f")) { format = line.getOptionValue("f"); if (!format.equals("tab") && !format.equals("dbformat") && !format.equals("xml")) { throw new IllegalArgumentException("Only dbformat, tab or xml format available"); } } } catch (Exception e) { System.out.println("Command Error: " + e.getMessage()); new HelpFormatter().printHelp(120, "SeqmatchCheckRevSeq", "", options, "", true); return; } SeqmatchCheckRevSeq theObj = new SeqmatchCheckRevSeq(); if (!checkReverse) { theObj.doUserLibMatch(queryFile, trainingFile, outputFile, numOfResults, format, traineeDesc); } else { theObj.checkRevSeq(queryFile, trainingFile, outputFile, revOutputWriter, correctedQueryOut, diffScoreCutoff, format, traineeDesc); } }
From source file:com.example.FirestoreSampleAppTests.java
@BeforeClass public static void prepare() { assumeThat("Firestore-sample tests are disabled. Please use '-Dit.firestore=true' " + "to enable them. ", System.getProperty("it.firestore"), is("true")); systemOut = System.out;//from w w w. j a va2 s . c om baos = new ByteArrayOutputStream(); TeeOutputStream out = new TeeOutputStream(systemOut, baos); System.setOut(new PrintStream(out)); }
From source file:ja.lingo.application.util.messages.ErrorDumper.java
public static String dump(Throwable t) { LOG.error("Internal error occured", t); String fileName = EngineFiles.calculateInWorking("log"); try {//from www. j av a 2 s . co m Files.ensureDirectoryExists(fileName); } catch (IOException e) { log(fileName, e, t); } fileName = new File(fileName, FILE_NAME_FORMAT.format(new Date())).toString(); PrintStream ps = null; try { ps = new PrintStream(new FileOutputStream(fileName)); ps.println("JaLingo Internal Error Log"); ps.println("=========================="); ps.println("Version : " + JaLingoInfo.VERSION); ps.println("Exception: ..."); t.printStackTrace(ps); } catch (IOException e) { log(fileName, e, t); } finally { if (ps != null) { ps.close(); } } return fileName; }
From source file:Main.java
public Console() { JTextArea textArea = new JTextArea(24, 80); textArea.setBackground(Color.BLACK); textArea.setForeground(Color.LIGHT_GRAY); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); System.setOut(new PrintStream(new OutputStream() { @Override//from w ww . j av a 2s . c om public void write(int b) throws IOException { textArea.append(String.valueOf((char) b)); } })); frame.add(textArea); }
From source file:fi.jumi.core.suite.SuiteFactoryTest.java
private void createSuiteFactory() { factory = new SuiteFactory(daemon.freeze(), new OutputCapturer(), new PrintStream(new NullOutputStream()), new NullMessageListener()); factory.configure(new SuiteConfiguration()); }