List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:diplomka.telnet.AutoTelnetClient.java
public AutoTelnetClient(String server, int port) { try {/* ww w. j a va2 s . c o m*/ // Connect to the specified server telnet.connect(server, port); in = telnet.getInputStream(); //in = new BufferedReader(new InputStreamReader(telnet.getInputStream())); out = new PrintStream(telnet.getOutputStream()); } catch (IOException ex) { System.err.println("AutomatedTelnetClient could not connect to the server " + server); } }
From source file:edu.msu.cme.rdp.readseq.writers.StkWriter.java
public StkWriter(int seqIDLength, OutputStream o, String header) throws IOException { this.out = new PrintStream(o); max_seqIDLength = seqIDLength;//from w w w. j a va2s . c o m out.println(header + "\n"); }
From source file:ape_test.CLITest.java
public void testVersionPrint() { PrintStream originalOut = System.out; OutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps);/*from ww w. j a v a 2s . c om*/ String[] theArgs = new String[1]; theArgs[0] = "-V"; Main.main(theArgs); assertEquals("ChaosMonkey version: " + Main.getVersion() + "\n", os.toString()); System.setOut(originalOut); }
From source file:com.creactiviti.piper.core.taskhandler.script.Bash.java
@Override public String handle(Task aTask) throws Exception { File scriptFile = File.createTempFile("_script", ".sh"); File logFile = File.createTempFile("log", null); FileUtils.writeStringToFile(scriptFile, aTask.getRequiredString("script")); try (PrintStream stream = new PrintStream(logFile);) { Process chmod = Runtime.getRuntime().exec(String.format("chmod u+x %s", scriptFile.getAbsolutePath())); int chmodRetCode = chmod.waitFor(); if (chmodRetCode != 0) { throw new ExecuteException("Failed to chmod", chmodRetCode); }/*from ww w . j a v a 2s.c o m*/ CommandLine cmd = new CommandLine(scriptFile.getAbsolutePath()); logger.debug("{}", cmd); DefaultExecutor exec = new DefaultExecutor(); exec.setStreamHandler(new PumpStreamHandler(stream)); exec.execute(cmd); return FileUtils.readFileToString(logFile); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(), e.getExitValue(), new RuntimeException(FileUtils.readFileToString(logFile))); } finally { FileUtils.deleteQuietly(logFile); FileUtils.deleteQuietly(scriptFile); } }
From source file:edu.cmu.cs.lti.ark.fn.utils.LemmatizeStuff.java
private static void run() throws FileNotFoundException { Scanner sc = new Scanner(new FileInputStream(infilename)); PrintStream ps = new PrintStream(new FileOutputStream(outfilename)); while (sc.hasNextLine()) { String line = sc.nextLine(); ps.print(line + "\t"); String[] toks = line.trim().split("\\s"); int sentLen = Integer.parseInt(toks[0]); for (int i = 0; i < sentLen; i++) { String lemma = lemmatizer.getLemma(toks[i + 1].toLowerCase(), toks[i + 1 + sentLen]); ps.print(lemma + "\t"); }/* ww w . j a v a 2s . c o m*/ ps.println(); } sc.close(); closeQuietly(ps); }
From source file:com.ibm.research.rdf.store.cmd.DumpRdfStore.java
@Override public void doWork(Connection conn) { // create the store. try {// w w w. ja v a2 s .com Store store = StoreManager.connectStore(conn, Backend.valueOf(params.get("-backend")), params.get("-schema"), storeName, Context.defaultContext); Dataset ds = RdfStoreFactory.connectDataset(store, conn, Backend.valueOf(params.get("-backend"))); PrintStream ps = new PrintStream(new BufferedOutputStream(System.out, 1000000)); RiotWriter.writeNQuads(ps, ds.asDatasetGraph()); ps.close(); } catch (RdfStoreException e) { log.error(e); System.out.println(e.getLocalizedMessage()); } catch (Exception e) { log.error(e); System.out.println(e.getLocalizedMessage()); } }
From source file:de.langmi.spring.batch.examples.basics.tasklet.CustomTaskletStepTest.java
@Before public void setUp() { // catch and set new system out oldSysOut = System.out; System.setOut(new PrintStream(newSysOut)); }
From source file:com.iterative.groovy.service.GroovyShellThread.java
@Override public void run() { PrintStream out = null;/* w w w . j av a 2 s .com*/ InputStream in = null; try { out = new PrintStream(socket.getOutputStream()); in = socket.getInputStream(); logger.debug("Created socket IO streams..."); binding.setVariable(OUT_KEY, out); logger.debug("Added output stream to binding collection as {}", OUT_KEY); final GroovyClassLoader loader = new GroovyClassLoader(this.getContextClassLoader()); final IO io = new IO(in, out, out); final Groovysh gsh = new Groovysh(loader, binding, io); try { logger.debug("Launching groovy interactive shell"); gsh.run(new String[] {}); } catch (final Exception e) { logger.error(e.getMessage(), e); } } catch (final Exception e) { logger.error(e.getMessage(), e); } finally { if (out != null) { IOUtils.closeQuietly(out); } if (in != null) { IOUtils.closeQuietly(in); } if (socket != null) { IOUtils.closeQuietly(this.socket); } } }
From source file:J2MEFileConnection.java
public void commandAction(Command command, Displayable displayable) { if (command == exit) { destroyApp(false);// w w w .ja v a 2 s. co m notifyDestroyed(); } else if (command == start) { try { OutputConnection connection = (OutputConnection) Connector.open("file://c:/myfile.txt;append=true", Connector.WRITE); OutputStream out = connection.openOutputStream(); PrintStream output = new PrintStream(out); output.println("This is a test."); out.close(); connection.close(); Alert alert = new Alert("Completed", "Data Written", null, null); alert.setTimeout(Alert.FOREVER); alert.setType(AlertType.ERROR); display.setCurrent(alert); } catch (Exception error) { Alert alert = new Alert("Error", error.toString(), null, null); alert.setTimeout(Alert.FOREVER); alert.setType(AlertType.ERROR); display.setCurrent(alert); } } }
From source file:com.creactiviti.piper.plugin.ffmpeg.Mediainfo.java
@Override public Map<String, Object> handle(Task aTask) throws Exception { CommandLine cmd = new CommandLine("mediainfo"); cmd.addArgument(aTask.getRequiredString("input")); log.debug("{}", cmd); DefaultExecutor exec = new DefaultExecutor(); File tempFile = File.createTempFile("log", null); try (PrintStream stream = new PrintStream(tempFile);) { exec.setStreamHandler(new PumpStreamHandler(stream)); exec.execute(cmd);//from w ww .ja v a2 s. c o m return parse(FileUtils.readFileToString(tempFile)); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(), e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile))); } finally { FileUtils.deleteQuietly(tempFile); } }