List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:edu.msu.cme.rdp.classifier.train.validation.distance.BoxPlotUtils.java
public static void readData(String inFile, File outdir, String xAxisLabel, String yAxisLabel) throws IOException { XYSeriesCollection dataset = new XYSeriesCollection(); DefaultBoxAndWhiskerCategoryDataset scatterDataset = new DefaultBoxAndWhiskerCategoryDataset(); BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = reader.readLine(); while ((line = reader.readLine()) != null) { String[] values = line.split("\\t"); XYSeries series = new XYSeries(values[2]); dataset.addSeries(series);//from www . j a va 2 s. c o m double average = Double.parseDouble(values[4]); int Q1 = Integer.parseInt(values[6]); ; int median = Integer.parseInt(values[7]); int Q3 = Integer.parseInt(values[8]); int pct_98 = Integer.parseInt(values[9]); int pct_2 = Integer.parseInt(values[10]); int minOutlier = 0; // we don't care about the outliers int maxOutlier = 0; // BoxAndWhiskerItem item = new BoxAndWhiskerItem(average, median, Q1, Q3, pct_2, pct_98, minOutlier, maxOutlier, new ArrayList()); scatterDataset.add(item, values[2], ""); } String title = new File(inFile).getName(); int index = title.indexOf("."); if (index != -1) { title = title.substring(0, index); } Font lableFont = new Font("Helvetica", Font.BOLD, 28); createBoxplot(scatterDataset, new PrintStream(new File(outdir, title + ".boxchart.png")), title, xAxisLabel, yAxisLabel, lableFont); }
From source file:jp.terasoluna.fw.util.ExceptionUtil.java
/** * ?????/*from ww w . j a va 2 s .co m*/ * * <p> * ?????????????? * ???????? * ???getRootCause()????????ServletException?? * </p> * * @param throwable * @return ??? */ public static String getStackTrace(Throwable throwable) { StringBuilder sb = new StringBuilder(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); while (throwable != null) { baos.reset(); throwable.printStackTrace(new PrintStream(baos)); sb.append(baos.toString()); //throwable?Class?? Class<? extends Throwable> throwableClass = throwable.getClass(); // ServletException ?? getRootCause ? if (SERVLET_EXCEPTION_NAME.equals(throwableClass.getName())) { try { //throwable = ((ServletException) throwable).getRootCause() //Class?????? Method method = throwableClass.getMethod(GET_ROOT_CAUSE); throwable = (Throwable) method.invoke(throwable); } catch (NoSuchMethodException e) { //??????? log.error(e.getMessage()); throwable = null; } catch (IllegalAccessException e) { //????????? log.error(e.getMessage()); throwable = null; } catch (InvocationTargetException e) { //????? log.error(e.getMessage()); throwable = null; } } else { throwable = throwable.getCause(); } } return sb.toString(); }
From source file:de.langmi.spring.batch.examples.basics.purejava.jobruns.PureJavaJobRunTest.java
@Before public void setup() throws Exception { // catch and set new system out oldSysOut = System.out;//w w w . j av a2 s . com System.setOut(new PrintStream(newSysOut)); setupBatchInfrastructure(); }
From source file:CraftAPI.java
/** * Construct the object./*from w w w . j a va 2s . com*/ */ public CraftAPI() { eventDispatcher = new EventDispatcher(); listener = new CraftAPIListener(eventDispatcher); try { System.setOut(new PrintStream(new CopyingEventOuputStream(System.out, eventDispatcher))); System.setErr(new PrintStream(new CopyingEventOuputStream(System.err, eventDispatcher))); // Logger.GLOBAL_LOGGER_NAME doesn't seem to work Logger.getLogger("Minecraft").addHandler(new LoggingEventHandler(eventDispatcher, new LogFormat())); } catch (Throwable t) { logger.log(Level.WARNING, "CraftAPI: Could not redirect stdout/stderr"); t.printStackTrace(); } }
From source file:de.ifgi.fmt.web.filter.RuntimeExceptionMapper.java
/** * //from ww w .ja v a 2 s . com * @param t * @return */ @Override public Response toResponse(Throwable t) { if (t instanceof WebApplicationException) { log.warn("Mapping Exception", t); return ((WebApplicationException) t).getResponse(); } Throwable e = t; while (e != null) { if (e instanceof ServiceError) { return new ServiceErrorMapper().toResponse((ServiceError) e); } e = e.getCause(); } log.info("Mapping Exception", t); ByteArrayOutputStream out = null; try { out = new ByteArrayOutputStream(); t.printStackTrace(new PrintStream(out)); return Response.serverError().entity(new String(out.toByteArray())).type(MediaType.TEXT_PLAIN).build(); } catch (Throwable t2) { throw new RuntimeException(t); } finally { IOUtils.closeQuietly(out); } }
From source file:com.liferay.ide.project.core.modules.BladeCLI.java
public static String[] execute(String args) throws BladeCLIException { IPath bladeCLIPath = getBladeCLIPath(); if (FileUtil.notExists(bladeCLIPath)) { throw new BladeCLIException("Could not get blade cli jar."); }//from w w w . ja v a2s . c o m Project project = new Project(); Java javaTask = new Java(); javaTask.setProject(project); javaTask.setFork(true); javaTask.setFailonerror(true); javaTask.setJar(bladeCLIPath.toFile()); javaTask.setArgs(args); DefaultLogger logger = new DefaultLogger(); project.addBuildListener(logger); List<String> lines = new ArrayList<>(); int returnCode = 0; try (StringBufferOutputStream out = new StringBufferOutputStream(); PrintStream printStream = new PrintStream(out)) { logger.setOutputPrintStream(printStream); logger.setMessageOutputLevel(Project.MSG_INFO); returnCode = javaTask.executeJava(); try (Scanner scanner = new Scanner(out.toString())) { while (scanner.hasNextLine()) { lines.add(scanner.nextLine().replaceAll(".*\\[null\\] ", "")); } } boolean hasErrors = false; StringBuilder errors = new StringBuilder(); for (String line : lines) { if (line.startsWith("Error")) { hasErrors = true; } else if (hasErrors) { errors.append(line); } } if ((returnCode != 0) || hasErrors) { throw new BladeCLIException(errors.toString()); } } catch (IOException e) { throw new BladeCLIException(e.getMessage(), e); } return lines.toArray(new String[0]); }
From source file:dk.netarkivet.common.utils.warc.WARCUtils.java
/** * Create new WARCWriter, writing to warcfile newFile. * @param newFile the WARCfile, that the WARCWriter writes to. * @return new WARCWriter, writing to warcfile newFile. *//*from www.j av a2 s. c o m*/ public static WARCWriter createWARCWriter(File newFile) { WARCWriter writer; PrintStream ps = null; try { ps = new PrintStream(new FileOutputStream(newFile)); writer = new WARCWriterNAS(new AtomicInteger(), ps, //This name is used for the first (file metadata) record newFile, false, //Don't compress //Use current time ArchiveDateConverter.getWarcDateFormat().format(new Date()), null //No particular file metadata to add ); } catch (IOException e) { if (ps != null) { ps.close(); } String message = "Could not create WARCWriter to file '" + newFile + "'.\n"; log.warn(message); throw new IOFailure(message, e); } return writer; }
From source file:com.findcomputerstuff.nips.DefaultSecurityModule.java
private String processMessage(String message, MessageAction action) { String outStr = null;//from ww w .j a va 2 s. com SSMLib ssm = new nfp.ssm.core.SSMLib(publicKeyFile, privateKeyFile); try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { PrintStream console = System.out; try (PrintStream ps = new PrintStream(os)) { System.setOut(ps); /* redirect stdout */ } switch (action) { case DECRYPT: outStr = ssm.decryptFile(message, privateKeyPassword); break; case ENCRYPT: outStr = ssm.encryptMessage(message); break; } System.out.flush(); System.setOut(console); /* restore stdout */ if (StringUtils.isBlank(outStr)) throw new SsmEncryptionException(os.toString()); } catch (IOException e) { e.printStackTrace(); } return outStr; }
From source file:edu.msu.cme.rdp.kmer.cli.KmerCoverage.java
/** * This program maps the kmers from reads to kmers on each contig, * writes the mean, median coverage of each contig to a file * writes the kmer abundance to a file/*from ww w . j a v a 2s .c o m*/ * @param args * @throws IOException */ public static void main(String[] args) throws IOException, InterruptedException { int kmerSize = 45; final int maxThreads; final int maxTasks = 1000; final PrintStream match_reads_out; try { CommandLine cmdLine = new PosixParser().parse(options, args); args = cmdLine.getArgs(); if (args.length < 5) { throw new Exception("Unexpected number of arguments"); } kmerSize = Integer.parseInt(args[0]); if (kmerSize > Kmer.max_nucl_kmer_size) { throw new Exception("kmerSize should be less than " + Kmer.max_nucl_kmer_size); } if (cmdLine.hasOption("match_reads_out")) { match_reads_out = new PrintStream(cmdLine.getOptionValue("match_reads_out")); } else { match_reads_out = null; } if (cmdLine.hasOption("threads")) { maxThreads = Integer.valueOf(cmdLine.getOptionValue("threads")); if (maxThreads >= Runtime.getRuntime().availableProcessors()) { System.err.println(" Runtime.getRuntime().availableProcessors() " + Runtime.getRuntime().availableProcessors()); } } else { maxThreads = 1; } final KmerCoverage kmerCoverage = new KmerCoverage(kmerSize, new SequenceReader(new File(args[1]))); final AtomicInteger outstandingTasks = new AtomicInteger(); ExecutorService service = Executors.newFixedThreadPool(maxThreads); Sequence seq; // parse one file at a time for (int index = 4; index < args.length; index++) { SequenceReader reader = new SequenceReader(new File(args[index])); while ((seq = reader.readNextSequence()) != null) { if (seq.getSeqString().length() < kmerSize) { continue; } final Sequence threadSeq = seq; Runnable r = new Runnable() { public void run() { try { kmerCoverage.processReads(threadSeq, match_reads_out); outstandingTasks.decrementAndGet(); } catch (Exception e) { e.printStackTrace(); } } }; outstandingTasks.incrementAndGet(); service.submit(r); while (outstandingTasks.get() >= maxTasks) ; } reader.close(); } service.shutdown(); service.awaitTermination(1, TimeUnit.DAYS); kmerCoverage.printCovereage(new FileOutputStream(new File(args[2])), new FileOutputStream(new File(args[3]))); if (match_reads_out != null) { match_reads_out.close(); } } catch (Exception e) { new HelpFormatter().printHelp( "KmerCoverage <kmerSize> <query_file> <coverage_out> <abundance_out> <reads_file> <reads_file>...\nmaximum kmerSize " + Kmer.max_nucl_kmer_size, options); e.printStackTrace(); System.exit(1); } }
From source file:com.twineworks.kettle.ruby.step.RubyStepParseErrorHelper.java
RubyStepParseErrorHelper() { Display display = Display.getDefault(); errorLineColor = new Color(display, new RGB(255, 220, 220)); container = RubyStepFactory.createScriptingContainer(false); // do not litter the console with potential parse errors container.setError(new PrintStream(new NullOutputStream())); container.setOutput(new PrintStream(new NullOutputStream())); }