List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:cpd3314.project.CPD3314ProjectTest.java
@Before public void setUp() { outContent = new ByteArrayOutputStream(); errContent = new ByteArrayOutputStream(); System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); }
From source file:com.creactiviti.piper.plugin.ffmpeg.Ffprobe.java
@Override public Map<String, Object> handle(Task aTask) throws Exception { CommandLine cmd = new CommandLine("ffprobe"); cmd.addArgument("-v").addArgument("quiet").addArgument("-print_format").addArgument("json") .addArgument("-show_error").addArgument("-show_format").addArgument("-show_streams") .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);/* www. ja va 2 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); } }
From source file:info.mikaelsvensson.devtools.analysis.localaccesslog.LocalAccessLogReportGenerator.java
@Override public void generateReport(File outputFile, ReportPrinter reportPrinter) throws FileNotFoundException { final PrintStream ps = new PrintStream(outputFile); final Collection<LocalAccessLogSample> allSamples = _log.getSamples(); Map<String, Collection<LocalAccessLogSample>> samplesByTestSession = SampleCollector.COLLECTOR_BY_SESSION_DATE .getFilteredAndGrouped(allSamples); for (Map.Entry<String, Collection<LocalAccessLogSample>> sessionEntry : samplesByTestSession.entrySet()) { final Collection<LocalAccessLogSample> sessionSamples = sessionEntry.getValue(); Map<String, Collection<LocalAccessLogSample>> samples = SAMPLE_COLLECTOR .getFilteredAndGrouped(sessionSamples); String[][] data = new String[samples.size() + 1][]; int i = 0; int sumCount = 0; final DefaultPieDataset dataset = new DefaultPieDataset(); final JFreeChart chart = ChartFactory.createPieChart( "Status Codes For Session " + sessionEntry.getKey(), dataset, true, false, Locale.ENGLISH); final File chartFile = new File(outputFile.getAbsolutePath() + "." + StringUtils.remove(sessionEntry.getKey(), ':').replace(' ', '-') + ".png"); final PiePlot plot = (PiePlot) chart.getPlot(); for (Map.Entry<String, Collection<LocalAccessLogSample>> entry : samples.entrySet()) { final Collection<LocalAccessLogSample> responseCodeSamples = entry.getValue(); final int count = responseCodeSamples.size(); data[i++] = new String[] { entry.getKey(), ToStringUtil.toString(count), ToStringUtil.toString(_log.calculateAverage(responseCodeSamples)), ToStringUtil.toString(_log.calculateMin(responseCodeSamples)), ToStringUtil.toString(_log.calculateMax(responseCodeSamples)) }; sumCount += count;// www . j a va2 s. co m final String label = entry.getKey() + " (" + count + " reqs)"; dataset.setValue(label, count); plot.setSectionPaint(label, entry.getKey().equals("200") ? Color.GREEN : Color.RED); } data[i] = new String[] { "All", ToStringUtil.toString(sumCount), ToStringUtil.toString(_log.calculateAverage(sessionSamples)), ToStringUtil.toString(_log.calculateMin(sessionSamples)), ToStringUtil.toString(_log.calculateMax(sessionSamples)) }; reportPrinter.printTable(ps, sessionEntry.getKey(), 10, new String[] { "Status Code", "# Requests", "Avg [ms]", "Min [ms]", "Max [ms]" }, data, null); if (sumCount > NUMBER_OF_REQUESTS_IN_SHORT_TEST) { try { ChartUtilities.saveChartAsPNG(chartFile, chart, 500, 500); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } } ps.close(); }
From source file:com.github.arven.sleuth.WatchedInterpreter.java
public WatchedInterpreter(Interpreter in, InputStream is, OutputStream os) { this.in = in; this.is = new BufferedReader(new InputStreamReader(is)); this.os = new PrintStream(os); this.in.setOut(this.os); this.history = new ArrayList<String>(); this.historyReverse = Lists.reverse(this.history); this.map = new ObjectMapper(); }
From source file:com.meetingninja.csse.database.ProjectDatabaseAdapter.java
public static Project createProject(Project p) throws IOException, MalformedURLException { // Server URL setup String _url = getBaseUri().build().toString(); // establish connection URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); addRequestHeader(conn, true);/*from w w w . j a v a 2 s . c o m*/ // prepare POST payload ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object jgen.writeStartObject(); jgen.writeStringField(Keys.Project.TITLE, p.getProjectTitle()); jgen.writeArrayFieldStart(Keys.Project.MEETINGS); for (Meeting meeting : p.getMeetings()) { jgen.writeStartObject(); jgen.writeStringField(Keys.Meeting.ID, meeting.getID()); jgen.writeEndObject(); } jgen.writeEndArray(); jgen.writeArrayFieldStart(Keys.Project.NOTES); for (Note note : p.getNotes()) { jgen.writeStartObject(); jgen.writeStringField(Keys.Note.ID, note.getID()); jgen.writeEndObject(); } jgen.writeEndArray(); jgen.writeArrayFieldStart(Keys.Project.MEMBERS); for (User member : p.getMembers()) { jgen.writeStartObject(); jgen.writeStringField(Keys.User.ID, member.getID()); jgen.writeEndObject(); } jgen.writeEndArray(); jgen.writeEndObject(); jgen.close(); // Get JSON Object payload from print stream String payload = json.toString("UTF8"); ps.close(); // send payload sendPostPayload(conn, payload); String response = getServerResponse(conn); // prepare to get the id of the created Meeting // Map<String, String> responseMap = new HashMap<String, String>(); /* * result should get valid={"meetingID":"##"} */ String result = new String(); if (!response.isEmpty()) { // responseMap = MAPPER.readValue(response, // new TypeReference<HashMap<String, String>>() { // }); JsonNode projectNode = MAPPER.readTree(response); if (!projectNode.has(Keys.Project.ID)) { result = "invalid"; } else result = projectNode.get(Keys.Project.ID).asText(); } if (!result.equalsIgnoreCase("invalid")) p.setProjectID(result); conn.disconnect(); return p; }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** Write debugging messages to a file */ private static final void debugWrite(String str) { if (debug == null) { try {/*from w ww . ja v a2 s . co m*/ debug = new PrintStream("/var/tmp/chart.txt"); } catch (FileNotFoundException nfex) { } } if (debug != null) { debug.println(str); debug.flush(); } }
From source file:cz.muni.fi.mir.mathmlunificator.MathMLUnificatorCommandLineToolTest.java
@Test public void testMain_multiple_formulae_operators() throws Exception { String testFile = "multiple-formulae"; String[] argv = { "-p", getTestResourceAsFilepath(testFile + ".input.xml") }; ByteArrayOutputStream stdoutContent = new ByteArrayOutputStream(); PrintStream stdout = System.out; System.setOut(new PrintStream(stdoutContent)); MathMLUnificatorCommandLineTool.main(argv); System.setOut(stdout);/*ww w .j a v a 2 s .c om*/ String output = stdoutContent.toString(StandardCharsets.UTF_8.toString()); System.out.println("testMain_multiple_formulae_operators operators output:\n" + output); assertEquals(IOUtils.toString(getExpectedXMLTestResource(testFile + ".operator"), StandardCharsets.UTF_8), output); }
From source file:net.sf.taverna.raven.helloworld.TestHelloWorld.java
@Test public void runWithPrinter() throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(outStream); new HelloWorld().run(printStream); printStream.close();//from ww w . ja v a2 s . co m String printedString = new String(outStream.toByteArray()); assertEquals("Did not print expected output", HelloWorld.TEST_DATA, printedString); }
From source file:org.drugis.addis.gui.GUIFactory.java
public static void suppressErrors(boolean suppress) { if (suppress) { System.setErr(new PrintStream(new OutputStream() { // suppress system.err output public void write(int b) { }/* w ww . j av a 2 s .c o m*/ })); } else { System.setErr(s_errorStream); // reset system.err output } }
From source file:edu.rit.flick.util.FlickTest.java
@BeforeClass public static void setUpStreams() { oldOut = System.out;// w w w . ja v a 2s. c o m oldErr = System.err; System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); }