List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:htsjdk.samtools.tabix.IndexingFeatureWriterNGTest.java
@Test public void blockCompressFile() throws FileNotFoundException { String file = "/home/sol/Downloads/test.chain.gff"; String out = "/home/sol/Downloads/t.bgz"; BlockCompressedOutputStream bcos = new BlockCompressedOutputStream(new File(out)); PrintStream ps = new PrintStream(bcos); Scanner scan = new Scanner(new File(file)); while (scan.hasNext()) { ps.println(scan.nextLine());// w ww.j a va 2s.c o m } ps.close(); }
From source file:com.azaptree.services.spring.application.SpringApplicationService.java
private static void logEnvironment(final Logger log) { if (log.isDebugEnabled()) { final TreeMap<String, String> sysProps = new TreeMap<>(System.getenv()); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final PrintStream ps = new PrintStream(bos); for (final Map.Entry<String, String> entry : sysProps.entrySet()) { ps.print(entry.getKey());//from ww w . j a v a2 s.com ps.print('='); ps.println(entry.getValue()); } log.debug("Environment:\n{}", bos); } }
From source file:com.oakesville.mythling.util.Reporter.java
private JSONObject buildJson() throws JSONException { JSONObject json = new JSONObject(); JSONObject report = new JSONObject(); json.put("report", report); report.put("source", "Mythling v" + AppSettings.staticGetMythlingVersion() + " (sdk " + AppSettings.getAndroidVersion() + ")"); report.put("message", message == null ? "No message" : message); if (throwable != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); throwable.printStackTrace(new PrintStream(out)); report.put("stackTrace", new String(out.toByteArray())); }//from ww w. j a va 2 s .c o m return json; }
From source file:com.samsung.sjs.ExplanationsTest.java
private static String explainErrors(JSEnvironment env, String sourceCode) { AstRoot root = new Parser().parse(sourceCode, "", 1); SatSolver sat = new Sat4J(); SJSTypeTheory theory = new SJSTypeTheory(env, null, root); List<Integer> hard = new ArrayList<>(); List<Integer> soft = new ArrayList<>(); List<ITypeConstraint> constraints = theory.getConstraints(); for (int i = 0; i < constraints.size(); ++i) { (theory.hackyGenerator().hasExplanation(constraints.get(i)) ? soft : hard).add(i); }//from w w w. j a v a 2 s. co m Pair<TypeAssignment, Collection<Integer>> result = TheorySolver.solve(theory, new SatFixingSetFinder<>(sat), hard, soft); ConstraintGenerator g = theory.hackyGenerator(); StringBuilder buf = new StringBuilder(); for (int broken : result.getRight()) { ITypeConstraint c = theory.hackyConstraintAccess().get(broken); ByteArrayOutputStream stream = new ByteArrayOutputStream(); g.explainFailure(c, result.getLeft()).prettyprint(new PrintStream(stream)); buf.append(stream.toString()); } return buf.toString(); }
From source file:de.tudarmstadt.lt.n2n.annotators.ExpansionsPrinter.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); if (_printstream_as_string == null || "sysout".equals(_printstream_as_string) || "System.out".equals(_printstream_as_string) || "stdout".equals(_printstream_as_string)) _printstream = System.out; else if ("syserr".equals(_printstream_as_string) || "System.err".equals(_printstream_as_string) || "stderr".equals(_printstream_as_string)) _printstream = System.err; else//from w w w . j a v a 2 s. c o m try { _printstream = new PrintStream(_printstream_as_string); } catch (FileNotFoundException e) { throw new ResourceInitializationException(e); } }
From source file:net.dv8tion.jda.core.utils.SimpleLog.java
/** * Will duplicate the output-streams to the specified Files. * This will catch everything that is sent to sout and serr (even stuff not logged via SimpleLog). * * @param std/*from w w w .j a va2s. c om*/ * The file to use for System.out logging, or null to not LOG System.out to a file * @param err * The file to use for System.err logging, or null to not LOG System.err to a file * @throws java.io.IOException * If an IO error is encountered while dealing with the file. Most likely * to be caused by a lack of permissions when creating the log folders or files. */ @SuppressWarnings("ResultOfMethodCallIgnored") public static void addFileLogs(File std, File err) throws IOException { if (std != null) { if (origStd == null) origStd = System.out; if (!std.getAbsoluteFile().getParentFile().exists()) { std.getAbsoluteFile().getParentFile().mkdirs(); } if (!std.exists()) { std.createNewFile(); } FileOutputStream fOut = new FileOutputStream(std, true); System.setOut(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { origStd.write(b); fOut.write(b); } })); if (stdOut != null) stdOut.close(); stdOut = fOut; } else if (origStd != null) { System.setOut(origStd); stdOut.close(); origStd = null; } if (err != null) { if (origErr == null) origErr = System.err; if (!err.getAbsoluteFile().getParentFile().exists()) { err.getAbsoluteFile().getParentFile().mkdirs(); } if (!err.exists()) { err.createNewFile(); } FileOutputStream fOut = new FileOutputStream(err, true); System.setErr(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { origErr.write(b); fOut.write(b); } })); if (errOut != null) errOut.close(); errOut = fOut; } else if (origErr != null) { System.setErr(origErr); errOut.close(); origErr = null; } }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.ResultFileInfo.java
@Override public void run(CommandLine commandLine) throws Exception { Problem problem = null;/* w ww . jav a 2 s .c o m*/ PrintStream output = null; ResultFileReader reader = null; try { // setup the problem if (commandLine.hasOption("problem")) { problem = ProblemFactory.getInstance().getProblem(commandLine.getOptionValue("problem")); } else { problem = new ProblemStub(Integer.parseInt(commandLine.getOptionValue("dimension"))); } try { // setup the output stream if (commandLine.hasOption("output")) { output = new PrintStream(new File(commandLine.getOptionValue("output"))); } else { output = System.out; } // display info for all result files for (String filename : commandLine.getArgs()) { try { int count = 0; reader = new ResultFileReader(problem, new File(filename)); while (reader.hasNext()) { reader.next(); count++; } output.println(filename + " " + count); } finally { if (reader != null) { reader.close(); } } } } finally { if ((output != null) && (output != System.out)) { output.close(); } } } finally { if (problem != null) { problem.close(); } } }
From source file:ape_test.CLITest.java
public void testMainWithEmptyString() { PrintStream originalOut = System.out; OutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps);//from w ww . j a va2s . c o m String[] arg = new String[1]; arg[0] = ""; Main.main(arg); System.setOut(originalOut); assertNotSame("", os.toString()); }
From source file:hudson.slaves.ComputerLauncherTest.java
@Test(expected = IOException.class) public void j2sdk4() throws IOException { ComputerLauncher.checkJavaVersion(new PrintStream(new NullOutputStream()), "-", new BufferedReader(new StringReader( "java version \"1.4.2_19\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_19-b04)\nJava HotSpot(TM) Client VM (build 1.4.2_19-b04, mixed mode)\n"))); }
From source file:com.kelveden.rastajax.servlet.DefaultHtmlServlet.java
private void writeRepresentationToResponse(Set<FlatResource> representation, HttpServletResponse httpResponse) throws IOException { httpResponse.setContentType("text/html; charset=utf8"); final OutputStream outputStream = httpResponse.getOutputStream(); final PrintStream printStream = new PrintStream(outputStream); printStream.println("<html>"); printStream.println("<body>"); printStream.println("<head>"); printStream.println("<style type=\"text/css\">"); printStream.println("* { font-size:10px; }"); printStream.println("table { border-width: 1px; border-collapse: collapse; margin-left: 10px; }"); printStream.println("table th { border: 1px solid; padding: 4px; background-color: #dedede; }"); printStream.println("table td { border: 1px solid; padding: 4px; }"); printStream.println("</style>"); printStream.println("</head>"); for (FlatResource resource : representation) { writeResource(resource, printStream); }/*from ww w . j a v a 2 s .c o m*/ printStream.println("</body>"); printStream.println("</html>"); printStream.flush(); }