List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:net.itransformers.topologyviewer.rightclick.impl.telnet.JTelnetTty.java
public boolean init(Questioner q) { getAuthDetails(q);/* www . j a v a 2 s . c o m*/ try { telnet.connect(host, 23); } catch (IOException e) { e.printStackTrace(); q.showMessage(e.getMessage()); return false; } telnet.setDefaultTimeout(timeout); in = telnet.getInputStream(); out = new PrintStream(telnet.getOutputStream()); readUntil("Username: "); write(user); readUntil("Password: "); write(password); // Advance to a prompt readUntil("*"); return true; }
From source file:com.aestasit.markdown.Markdown.java
public static String printAst(final RootNode node) { final ByteArrayOutputStream data = new ByteArrayOutputStream(); new AstPrinter(new PrintStream(data)).visit(node); return new String(data.toByteArray()); }
From source file:com.ikon.util.ExecutionUtils.java
/** * Execute script/* w ww.ja va 2 s .c om*/ * * @return 0 - Return * 1 - StdOut * 2 - StdErr */ public static Object[] runScript(String script) throws EvalError { Object[] ret = new Object[3]; ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); PrintStream out = new PrintStream(baosOut); ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); PrintStream err = new PrintStream(baosErr); Interpreter i = new Interpreter(null, out, err, false); ret[0] = i.eval(script); out.flush(); ret[1] = baosOut.toString(); err.flush(); ret[2] = baosErr.toString(); log.debug("runScript: {}", Arrays.toString(ret)); return ret; }
From source file:com.ctm.telnet.Telnet.java
/**************************************** * connect method * * Construct that connects to the Pi by * * initiating a stream for each Pi * * identified by its IP address. UserID * * and Password which are the same for * * each PI where only the IP address is * * unique. * ****************************************/ public void connect(String ipAddr) { try {/* w w w . ja va2 s .c om*/ // Connect to specified Pi telnet.connect(ipAddr, usrID, passwrd); // Get input and output stream references in = telnet.getInputStream(); out = new PrintStream(telnet.getOutputStream()); // Log the user in readUntil("login: "); write(usrID); readUntil("Password: "); write(passwrd); // Advance to a prompt readUntil(prompt + " "); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.rwth.dbis.acis.bazaar.service.TestBase.java
/** * Called before the tests start./*from w w w . jav a2s .com*/ * * Sets up the node and initializes connector and users that can be used * throughout the tests. * * @throws Exception */ public static void startServer() throws Exception { // start node node = LocalNode.newNode(); node.storeAgent(testAgent); node.launch(); ServiceAgent testService = ServiceAgent.generateNewAgent(testServiceClass, "a pass"); testService.unlockPrivateKey("a pass"); node.registerReceiver(testService); // start connector logStream = new ByteArrayOutputStream(); connector = new WebConnector(true, HTTP_PORT, false, 1000); connector.setSocketTimeout(10000); connector.setLogStream(new PrintStream(logStream)); connector.start(node); Thread.sleep(1000); // wait a second for the connector to become ready connector.updateServiceList(); // avoid timing errors: wait for the repository manager to get all // services before continuing try { System.out.println("waiting.."); Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:Base64EncoderStream.java
public Base64EncoderStream(OutputStream out, boolean closeOutOnClose) { this.out = new PrintStream(out); this.closeOutOnClose = closeOutOnClose; }
From source file:com.mockey.ui.RequestInspectorAjaxServlet.java
/** * //from www . ja va 2 s .c o m */ public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Long fulfilledRequestId = null; JSONObject jsonObject = new JSONObject(); JSONArray array = new JSONArray(); try { for (Class<?> item : PluginStore.getInstance().getRequestInspectorImplClassList()) { array.put(item.getName()); } jsonObject.putOpt("request_inspectors", array); } catch (Exception e) { try { jsonObject.put("error", "" + "Sorry, history for this conversation (fulfilledRequestId=" + fulfilledRequestId + ") is not available."); } catch (JSONException e1) { logger.error("Unable to create JSON", e1); } } resp.setContentType("application/json"); PrintStream out = new PrintStream(resp.getOutputStream()); out.println(jsonObject.toString()); }
From source file:log4JToXml.xmlToProperties.XmlToLog4jConverterImpl.java
/** * Constructor for basic converter, default settings * * @throws IOException if there is problem creating temporary file in project location *///from w w w. j a v a 2s. co m public XmlToLog4jConverterImpl() throws IOException { //needed for the order of the properties log4jProperties = new LinkedProperties(); doc = null; tempXML = File.createTempFile("tempXML", ".xml"); documentStream = new PrintStream(tempXML); InputStream initialStream = this.getClass().getResourceAsStream("/log4j.dtd"); tempDTD = File.createTempFile("tempDTD", ".dtd"); FileUtils.copyInputStreamToFile(initialStream, tempDTD); }
From source file:hudson.slaves.ComputerLauncherTest.java
private static void assertChecked(String text, String spec) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); ComputerLauncher.checkJavaVersion(new PrintStream(os), "bin/java", new BufferedReader(new StringReader(text))); String logged = os.toString(); assertTrue(logged, logged.contains(Messages.ComputerLauncher_JavaVersionResult("bin/java", spec))); }
From source file:hudson.cli.CliManagerImpl.java
public int main(List<String> args, Locale locale, InputStream stdin, OutputStream stdout, OutputStream stderr) { // remoting sets the context classloader to the RemoteClassLoader, // which slows down the classloading. we don't load anything from CLI, // so counter that effect. Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); PrintStream out = new PrintStream(stdout); PrintStream err = new PrintStream(stderr); String subCmd = args.get(0);//from ww w. jav a 2 s.c om CLICommand cmd = CLICommand.clone(subCmd); if (cmd != null) { Authentication old = SecurityContextHolder.getContext().getAuthentication(); SecurityContextHolder.getContext().setAuthentication(auth); try { // execute the command, do so with the originator of the request as the principal return cmd.main(args.subList(1, args.size()), stdin, out, err); } finally { SecurityContextHolder.getContext().setAuthentication(old); } } err.println("No such command: " + subCmd); new HelpCommand().main(Collections.<String>emptyList(), stdin, out, err); return -1; }