List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:cz.muni.fi.mir.mathmlunificator.MathMLUnificatorCommandLineToolTest.java
@Test public void testMain_multiple_formulae_non_operators() throws Exception { String testFile = "multiple-formulae"; String[] argv = { getTestResourceAsFilepath(testFile + ".input.xml") }; ByteArrayOutputStream stdoutContent = new ByteArrayOutputStream(); PrintStream stdout = System.out; System.setOut(new PrintStream(stdoutContent)); MathMLUnificatorCommandLineTool.main(argv); System.setOut(stdout);/*from w w w . j a v a 2 s . co m*/ String output = stdoutContent.toString(StandardCharsets.UTF_8.toString()); System.out.println("testMain_multiple_formulae_non_operators non-operators output:\n" + output); assertEquals( IOUtils.toString(getExpectedXMLTestResource(testFile + ".non-operator"), StandardCharsets.UTF_8), output); }
From source file:javancss.JavancssTest.java
private Javancss measureWithArgs(String[] args) throws IOException { // turn stdout off PrintStream psStdout = System.out; try {/*ww w .j a v a 2 s . c o m*/ System.setOut(new PrintStream(new ByteArrayOutputStream())); return new Javancss(args); } finally { // turn stdout back on System.setOut(psStdout); } }
From source file:com.ibm.sbt.services.client.connections.activities.ActivityEntryPerformanceTest.java
@Test @org.junit.Ignore("Issue with Mime Depdency") public void testCreateActivityEntries() throws ClientServicesException { System.setErr(new PrintStream(new ByteArrayOutputStream())); Activity activity = createActivity(); String activityUuid = activity.getActivityUuid(); String title = activity.getThemeId(); FileField fileField = new FileField(); fileField.setName("test_file"); fileField.setHidden(true);/*from w w w . j a v a 2s. c o m*/ fileField.setPosition(2000); byte[] bytes = new byte[Integer.valueOf(1024)]; Arrays.fill(bytes, (byte) 0); StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); writer.println("#,NodeUUID,Time(ms)"); for (int i = 0; i < 500; i++) { try { long start = System.currentTimeMillis(); System.out.print(i + " "); ActivityNode activityNode = new ActivityNode(); activityNode.setActivityUuid(activityUuid); activityNode.setTitle(title + " - " + i); activityNode.setType(ActivityNode.TYPE_ENTRY); for (int j = 0; j < 5; j++) { TextField textField = new TextField(); textField.setName("test_text" + j); textField.setPosition(1000); textField.setSummary("Test_Text_Field"); activityNode.addField(textField); } activityNode.addField(fileField); activityNode.addAttachment(new ActivityAttachment("test_file", new String(bytes), "text/plain")); activityNode = activityService.createActivityNode(activityNode); long duration = System.currentTimeMillis() - start; writer.println(i + "," + activityNode.getActivityNodeUuid() + "," + duration); } catch (Exception e) { } } System.out.println(stringWriter.toString()); /* long start = System.currentTimeMillis(); Map<String, String> params = new HashMap<String, String>(); params.put("page", "1"); params.put("ps", "1"); activityService.getActivityNodeDescendants(activityUuid, params); long duration = System.currentTimeMillis() - start; System.out.println("Reading all activity descendants took "+duration+"(ms)"); start = System.currentTimeMillis(); params.put("tag", "personal"); activityService.getActivityNodeChildren(activityUuid, params); duration = System.currentTimeMillis() - start; System.out.println("Reading all activity children took "+duration+"(ms)"); */ }
From source file:corina.logging.CorinaLog.java
private static PrintStream createPrintStream(final Log log, final boolean error) { return new PrintStream(new OutputStream() { public void write(int b) { byte[] barray = { (byte) b }; write(barray, 0, 1);/*from w ww. j a v a 2s .c o m*/ } public void write(byte[] b, int off, int len) { String str = new String(b, off, len); // skip any trailing EOL if ("\r".equals(str) || "\n".equals(str) || "\r\n".equals(str)) return; if (error) { log.error(str); } else { log.info(str); } } }); }
From source file:com.microsoft.windowsazure.core.tracing.util.JavaTracingInterceptorTest.java
@Test public void testInformationSendRequest() { // Arrange// w w w . j a va 2s . c om logContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(logContent)); CloudTracing.addTracingInterceptor(new JavaTracingInterceptor()); HttpRequest httpRequest = new HttpPost("http://www.bing.com"); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2012-03-01"); // Act CloudTracing.sendRequest("test", httpRequest); // Assert String result = logContent.toString(); assertTrue(result.contains("INFO: invocationId: test\r\nrequest: POST http://www.bing.com HTTP/1.1")); CloudTracing.information("hello there"); result = logContent.toString(); assertTrue(result.contains("INFO: hello there")); }
From source file:com.intel.podm.rest.ReplicatedStreamHttpServletResponse.java
ReplicatedStreamHttpServletResponse(HttpServletResponse response) { super(response); byteArrayOutputStream = new ByteArrayOutputStream(); printStream = new PrintStream(byteArrayOutputStream); }
From source file:infowall.infrastructure.service.GroovyExecutor.java
public String exec(File file) { try {//from w w w . j a va2 s .c om ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream wrappedOut = new PrintStream(out); Binding binding = new Binding(); binding.setProperty("out", wrappedOut); GroovyShell shell = new GroovyShell(binding); shell.run(file, Collections.emptyList()); return out.toString("UTF-8"); } catch (IOException e) { logger.error("Cannot exec groovy script " + file.getAbsolutePath(), e); } return null; }
From source file:com.adaptris.util.stream.Slf4jLoggingOutputStreamTest.java
@Test public void testLogTrace() throws Exception { PrintStream out = new PrintStream(new Slf4jLoggingOutputStream("TRACE")); out.println(TEXT);/*from w w w .jav a 2 s. c o m*/ out.flush(); out.close(); }
From source file:com.jivesoftware.jive.deployer.jaxrs.util.ResponseHelperTest.java
@Test public void testErrorResponse() throws Exception { ObjectNode jsonNode = objectMapper.createObjectNode(); jsonNode.put("Foobar", true); String message = "This is a BAD request!"; Exception e = new Exception(); OutputStream outputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(outputStream); e.printStackTrace(printStream);/*from www.ja v a 2 s.co m*/ Response response = ResponseHelper.INSTANCE.errorResponse(Response.Status.BAD_REQUEST, message, e, jsonNode); assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); String bodyString = objectMapper.writeValueAsString(response.getEntity()); System.out.println(bodyString); ObjectNode body = (ObjectNode) objectMapper.readTree(bodyString); assertEquals(body.get("message").textValue(), message); assertEquals(body.get("trace").textValue(), outputStream.toString()); assertEquals(body.get("relatedData"), jsonNode); }
From source file:Main.java
public InputStream getWWWPageStream(String host, String file) throws IOException, UnknownHostException { InetAddress webServer = InetAddress.getByName(host); Socket httpPipe = new Socket(webServer, 80); if (httpPipe == null) { System.out.println("Socket to Web server creation failed."); return null; }//from w w w.j ava 2s. co m InputStream inn = httpPipe.getInputStream(); // get raw streams OutputStream outt = httpPipe.getOutputStream(); DataInputStream in = new DataInputStream(inn); // turn into higher-level ones PrintStream out = new PrintStream(outt); if (inn == null || outt == null) { System.out.println("Failed to open streams to socket."); return null; } out.println("GET " + file + " HTTP/1.0\n"); String response; while ((response = in.readUTF()).length() > 0) { System.out.println(response); } return in; }