List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.logging.LoggerDestinationFastTest.java
@Test public void stdoutLoggerDestination() throws IOException, LoggerDestination.LoggerException { PrintStream outStream = null; try {//from w w w.ja va 2 s . co m // redirect stdout to a file String outfile = OUTPUT_PATH + "stdout.txt"; //noinspection IOResourceOpenedButNotSafelyClosed outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); System.setOut(outStream); // send message to logger destination StdoutLoggerDestination dest = new StdoutLoggerDestination(); dest.setMinLevel(Level.DEBUG); String message = "THIS IS AN ERROR MESSAGE"; dest.logToDestination(Level.ERROR, message); outStream.close(); // read in output file and compare to expected assertEquals(message, readFirstLine(outfile)); new File(outfile).deleteOnExit(); } finally { IOUtils.closeQuietly(outStream); } }
From source file:AloneService.java
/** * init and destroy were added in jakarta-tomcat-daemon. *///from w ww .j ava2 s .c om public void init(String[] arguments) throws Exception { /* Set the err */ System.setErr(new PrintStream(new FileOutputStream(new File("/ServiceDaemon.err"), true))); System.err.println("ServiceDaemon: instance " + this.hashCode() + " init"); /* read the properties file */ prop = new ExtendedProperties("startfile"); /* create an array to store the processes */ int i = 0; for (Iterator e = prop.getKeys(); e.hasNext();) { e.next(); i++; } System.err.println("ServiceDaemon: init for " + i + " processes"); proc = new Process[i]; readout = new ServiceDaemonReadThread[i]; readerr = new ServiceDaemonReadThread[i]; for (i = 0; i < proc.length; i++) { proc[i] = null; readout[i] = null; readerr[i] = null; } System.err.println("ServiceDaemon: init done "); }
From source file:io.stallion.plugins.javascript.JavascriptShell.java
private static Context makeContext(InputStream in, OutputStream out, OutputStream err, String[] args) { PrintStream pout = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out); PrintStream perr = err instanceof PrintStream ? (PrintStream) err : new PrintStream(err); PrintWriter wout = new PrintWriter(pout, true); PrintWriter werr = new PrintWriter(perr, true); ErrorManager errors = new ErrorManager(werr); Options options = new Options("nashorn", werr); if (args != null) { try {//from w ww .ja va2 s. com options.process(args); } catch (IllegalArgumentException var27) { werr.println(bundle.getString("shell.usage")); options.displayHelp(var27); return null; } } return new Context(options, errors, wout, werr, Thread.currentThread().getContextClassLoader()); }
From source file:com.khubla.antlr4formatter.Antlr4Formatter.java
/** * format an input file//from w w w .jav a2 s. c o m */ private static void format(InputStream inputStream, OutputStream outputStream) throws Exception { try { if (null != inputStream) { final Reader reader = new InputStreamReader(inputStream, "UTF-8"); final ANTLRv4Lexer lexer = new ANTLRv4Lexer(new ANTLRInputStream(reader)); final CommonTokenStream commonTokenStream = new CommonTokenStream(lexer); final ANTLRv4Parser parser = new ANTLRv4Parser(commonTokenStream); final GrammarSpecContext grammarSpecContext = parser.grammarSpec(); ParseTreeWalker.DEFAULT.walk( new Antlr4ParseTreeListenerImpl(new PrintStream(outputStream), commonTokenStream), grammarSpecContext); } else { throw new IllegalArgumentException(); } } catch (final Exception e) { throw new Exception("Exception reading and parsing file", e); } }
From source file:com.kotcrab.vis.editor.Log.java
/** Initializes logging facility, called once by VisEditor. */ public static void init() { if (initialized) throw new IllegalStateException("Log cannot be initialized twice!"); initialized = true;/*from ww w . j a va2s. c o m*/ prepareLogFile(); System.setOut(new PrintStream(new TeeOutputStream(System.out, logFileStream))); System.setErr(new PrintStream(new TeeOutputStream(System.err, logFileStream))); }
From source file:de.langmi.spring.batch.examples.basics.tasklet.SimpleTaskletStepTest.java
@Before public void setup() { // catch and set new system out oldSysOut = System.out; System.setOut(new PrintStream(newSysOut)); }
From source file:b2s.idea.mavenize.AppTest.java
@Before public void setUp() throws Exception { output = new ByteArrayOutputStream(); App.jarCombiner = combiner;//w w w . j av a2 s . c om originalSysOut = System.out; System.setOut(new PrintStream(output)); ideaFolder = temporaryFolder.newFolder(); outputFolder = temporaryFolder.newFolder(); ideaLibFolder = new File(ideaFolder, "lib"); IOUtils.write("build-version", new FileOutputStream(new File(ideaFolder, "build.txt"))); }
From source file:com.music.service.text.SentimentAnalyzer.java
@PostConstruct public void init() { // because scientists can't code, and write debug messages to System.err PrintStream err = new PrintStream(System.err) { @Override// w w w. j a va 2s . c o m public void println(String x) { if (!x.startsWith("Adding annotator")) { super.println(x); } } }; System.setErr(err); }
From source file:MyTest.java
@Test public void test() throws Exception { InputStream input = null;/*ww w . j ava 2 s. c o m*/ InputStream expectedOutput = null; int i = 0; do { input = Thread.currentThread().getContextClassLoader().getResourceAsStream("input" + String.valueOf(i)); expectedOutput = Thread.currentThread().getContextClassLoader() .getResourceAsStream("output" + String.valueOf(i)); if (input != null) { System.out.println("Running case #" + String.valueOf(i) + " input:"); System.out.println(IOUtils.toString(Thread.currentThread().getContextClassLoader() .getResourceAsStream("input" + String.valueOf(i)), "US-ASCII")); System.setIn(input); if (expectedOutput != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); PrintStream realOutput = new PrintStream(byteArrayOutputStream); PrintStream preservedOut = System.out; System.setOut(realOutput); long start = System.currentTimeMillis(); MySolution.main(null); long end = System.currentTimeMillis(); System.setOut(preservedOut); System.out.println("Output:"); System.out.println(byteArrayOutputStream.toString("US-ASCII")); System.out.println("Time: " + (end - start)); assertEquals(IOUtils.toString(expectedOutput, "US-ASCII"), byteArrayOutputStream.toString("US-ASCII")); } else { MySolution.main(null); } } i++; } while (input != null); }