List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:hudson.slaves.ComputerLauncherTest.java
@Test(expected = IOException.class) public void jdk5() throws IOException { ComputerLauncher.checkJavaVersion(new PrintStream(new NullOutputStream()), "-", new BufferedReader(new StringReader( "java version \"1.5.0_22\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)\nJava HotSpot(TM) Server VM (build 1.5.0_22-b03, mixed mode)\n"))); }
From source file:Base64EncoderStream.java
public Base64EncoderStream(OutputStream out) { this.out = new PrintStream(out); closeOutOnClose = true; }
From source file:de.ifgi.fmt.web.filter.ServiceErrorMapper.java
/** * //w w w . j a v a2 s.c om * @param e * @return */ @Override public Response toResponse(ServiceError e) { if (e.getMessage() != null) { try { log.info("Mapping Exception: HTTP {}: {}", e.getErrorCode(), e.getMessage()); JSONObject j = new JSONObject().put(JSONConstants.ERRORS_KEY, new JSONArray().put(new JSONObject().put(JSONConstants.MESSAGE_KEY, e.getMessage()))); return Response.status(e.getErrorCode()).entity(j).type(MediaTypes.ERRORS).build(); } catch (JSONException e1) { throw ServiceError.internal(e); } } else { log.warn("Mapping Exception", e); ByteArrayOutputStream out = null; try { out = new ByteArrayOutputStream(); e.printStackTrace(new PrintStream(out)); return Response.status(e.getErrorCode()).entity(new String(out.toByteArray())) .type(MediaType.TEXT_PLAIN).build(); } catch (Throwable t) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(out); } } }
From source file:com.consol.citrus.admin.service.TestExecutionService.java
/** * Adds failure stack information to test result. * @param result/*from w w w . jav a 2 s .com*/ * @param e */ private void setFailureStack(TestResult result, Exception e) { result.setSuccess(false); ByteArrayOutputStream os = new ByteArrayOutputStream(); e.printStackTrace(new PrintStream(os)); result.setStackTrace("Caused by: " + os.toString()); if (e instanceof CitrusRuntimeException) { result.setFailureStack(((CitrusRuntimeException) e).getFailureStackAsString()); } }
From source file:com.replaymod.replaystudio.launcher.DaemonLauncher.java
public void launch(CommandLine cmd) throws Exception { int threads = Integer.parseInt(cmd.getOptionValue('d', "" + Runtime.getRuntime().availableProcessors())); worker = Executors.newFixedThreadPool(threads); System.setOut(new PrintStream(systemOut = new ThreadLocalOutputStream(System.out))); ServerSocket serverSocket = new ServerSocket(PORT); System.out.println("Daemon started on port " + PORT + " with " + threads + " worker threads."); while (!Thread.interrupted()) { Socket socket = serverSocket.accept(); try {// w w w. j a v a 2s .c o m Client client = new Client(socket); new Thread(client).start(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.sap.prd.mobile.ios.mios.FileUtilsTest.java
private static boolean checkForSymbolicLink(final File f) throws IOException { ByteArrayOutputStream byteOs = new ByteArrayOutputStream(); PrintStream stream = new PrintStream(byteOs); try {//w ww . j av a2 s.c om Forker.forkProcess(stream, null, "ls", "-l", f.getAbsolutePath()); stream.flush(); return byteOs.toString().startsWith("l"); } finally { IOUtils.closeQuietly(stream); } }
From source file:com.comcast.cats.recorder.TelnetHandler.java
/** * Connect, authenticate and initialize vlc Telnet session * /*w w w .j av a 2s .c o m*/ * @param server * @param port * @param password * @throws SocketException * @throws IOException */ private void connect(String server, Integer port, String password) throws SocketException, IOException, VideoRecorderConnectionException { LOGGER.info("[VLC][Telnet Connect][" + server + "][" + port + "]"); // Connect to the specified server telnet.connect(server, port); // Get input and output stream references in = telnet.getInputStream(); out = new PrintStream(telnet.getOutputStream()); readUntil("Password: "); write(password); // Advance to a prompt readUntil(prompt + " "); }
From source file:net.lr.jmsbridge.BridgeServlet.java
/** * Forward HTTP request to a jms queue and listen on a temporary queue for the reply. * Connects to the jms server by using the username and password from the HTTP basic auth. *//* ww w. j a v a 2s . co m*/ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String authHeader = req.getHeader("Authorization"); if (authHeader == null) { resp.setHeader("WWW-Authenticate", "Basic realm=\"Bridge\""); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "auth"); return; } UserNameAndPassword auth = extractUserNamePassword(authHeader); PrintStream out = new PrintStream(resp.getOutputStream()); String contextPath = req.getContextPath(); String uri = req.getRequestURI(); String queueName = uri.substring(contextPath.length() + 1); final StringBuffer reqContent = retrieveRequestContent(req.getReader()); ConnectionFactory cf = connectionPool.getConnectionFactory(auth); JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setConnectionFactory(cf); jmsTemplate.setReceiveTimeout(10000); final Destination replyDest = connectionPool.getReplyDestination(cf, auth); jmsTemplate.send(queueName, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(reqContent.toString()); message.setJMSReplyTo(replyDest); return message; } }); Message replyMsg = jmsTemplate.receive(replyDest); if (replyMsg instanceof TextMessage) { TextMessage replyTMessage = (TextMessage) replyMsg; try { out.print(replyTMessage.getText()); } catch (JMSException e) { JmsUtils.convertJmsAccessException(e); } } }
From source file:net.algart.simagis.live.json.minimal.SimagisLiveUtils.java
/** * Fully disable any output via <tt>System.out</tt>. * Can be useful to disable possible output of third-party libraries. *//* w ww . j av a 2 s .c om*/ public static void disableStandardOutput() { System.setOut(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { // no operations } })); }
From source file:fi.jumi.core.testbench.TestBench.java
public void run(SuiteListener suiteListener, Class<?>... testClasses) { SingleThreadedActors actors = new SingleThreadedActors(new DynamicEventizerProvider(), actorsFailureHandler, actorsMessageListener);/*from ww w .j a v a 2 s.c o m*/ ActorThread actorThread = actors.startActorThread(); Executor testExecutor = actors.getExecutor(); RunIdSequence runIdSequence = new RunIdSequence(); ClassLoader classLoader = getClass().getClassLoader(); ActorRef<TestFileFinderListener> suiteRunner = actorThread.bindActor(TestFileFinderListener.class, new SuiteRunner( new DriverFactory(suiteListener, actorThread, outputCapturer, driverFinder, runIdSequence, classLoader), suiteListener, actorThread, testExecutor, new PrintStream(new NullOutputStream()))); suiteListener.onSuiteStarted(); testExecutor.execute(new TestFileFinderRunner(new StubTestFileFinder(testClasses), suiteRunner)); actors.processEventsUntilIdle(); }