List of usage examples for java.io PrintStream flush
public void flush()
From source file:com.adaptris.core.MimeEncoder.java
/** * Encode the <code>AdaptrisMessage</code> object. * <p>// ww w .j a v a 2 s .c om * The target object is assumed to be of the type <code>OutputStream</code> * </p> * * @see AdaptrisMessageEncoder#writeMessage(AdaptrisMessage, Object) */ public void writeMessage(AdaptrisMessage msg, Object target) throws CoreException { try { if (!(target instanceof OutputStream)) { throw new IllegalArgumentException("MimeEncoder can only encode to an OutputStream"); } OutputStream encodedOutput = (OutputStream) target; // Use the message unique id as the message id. MultiPartOutput output = new MultiPartOutput(msg.getUniqueId()); output.addPart(msg.getPayload(), payloadEncoding, PAYLOAD_CONTENT_ID); output.addPart(MimeEncoder.getMetadata(msg), metadataEncoding, METADATA_CONTENT_ID); if (msg.getObjectHeaders().containsKey(CoreConstants.OBJ_METADATA_EXCEPTION)) { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream pout = new PrintStream(out); Exception e = (Exception) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION); e.printStackTrace(pout); pout.flush(); output.addPart(out.toByteArray(), EXCEPTION_CONTENT_ID); } encodedOutput.write(output.getBytes()); encodedOutput.flush(); } catch (Exception e) { throw new CoreException("Could not encode the AdaptrisMessage object", e); } }
From source file:com.act.lcms.plotter.WriteAndPlotMS1Results.java
private void writeFeedMS1Values(List<Pair<Double, Double>> concentrationIntensity, OutputStream os) throws IOException { PrintStream out = new PrintStream(os); for (Pair<Double, Double> ci : concentrationIntensity) { out.format("%f\t%f\n", ci.getLeft(), ci.getRight()); }//from ww w . ja v a 2s . co m out.flush(); }
From source file:org.jajuk.services.players.AbstractMPlayerImpl.java
/** * Send a command to mplayer slave./*from w w w .jav a 2 s . c o m*/ * * @param command */ protected void sendCommand(String command) { if (proc != null) { PrintStream out = new PrintStream(proc.getOutputStream()); // Do not use println() : it doesn't work under windows out.print(command + '\n'); out.flush(); // don't close out here otherwise the output stream of the Process // will be closed as well and subsequent sendCommand() calls will silently // fail!! } }
From source file:com.starit.diamond.server.service.TimerTaskService.java
private void productConfigInfoCheckBatchFile(List<ConfigInfo> configInfos) { String GROUP = "$GROUP$"; String DATAID = "$DATAID$"; String urlPattern = "$GROUP$\t$DATAID$"; try {/*from ww w . j ava 2 s . c o m*/ File f = new File("slf_check_urls.txt"); fn = f.getAbsolutePath(); System.out.println(" :" + f.getAbsolutePath()); PrintStream out = new PrintStream(new FileOutputStream(f)); for (ConfigInfo configInfo : configInfos) { String url = urlPattern.replace(GROUP, configInfo.getGroup()); url = url.replace(DATAID, configInfo.getDataId()); out.println(url); } out.flush(); out.close(); } catch (FileNotFoundException e) { throw new RuntimeException("can not create check.sh"); } }
From source file:org.opendatakit.logging.WebLoggerImpl.java
public void printStackTrace(Throwable e) { //e.printStackTrace(); ByteArrayOutputStream ba = new ByteArrayOutputStream(); PrintStream w; try {/*from w w w. j a v a2 s .co m*/ w = new PrintStream(ba, false, "UTF-8"); e.printStackTrace(w); w.flush(); w.close(); log(ba.toString("UTF-8")); } catch (UnsupportedEncodingException ignored) { // error if it ever occurs throw new IllegalStateException("unable to specify UTF-8 Charset!"); } catch (IOException e1) { Log.e(TAG, Log.getStackTraceString(e1), e1); } }
From source file:org.apache.mahout.classifier.ConfusionMatrixDumper.java
@Override public int run(String[] args) throws IOException { addInputOption();//w w w . j av a2s . c o m addOption("output", "o", "Output path", null); // AbstractJob output feature requires param addOption(DefaultOptionCreator.overwriteOption().create()); addFlag("html", null, "Create complete HTML page"); addFlag("text", null, "Dump simple text"); Map<String, List<String>> parsedArgs = parseArguments(args); if (parsedArgs == null) { return -1; } Path inputPath = getInputPath(); String outputFile = hasOption("output") ? getOption("output") : null; boolean text = parsedArgs.containsKey("--text"); boolean wrapHtml = parsedArgs.containsKey("--html"); PrintStream out = getPrintStream(outputFile); if (text) { exportText(inputPath, out); } else { exportTable(inputPath, out, wrapHtml); } out.flush(); if (out != System.out) { out.close(); } return 0; }
From source file:eu.project.ttc.tools.cli.TermSuiteAlignerCLI.java
public void readArguments(CommandLine line, PrintStream out) throws IOException { if (!line.hasOption(TERM) && !line.hasOption(TERM_LIST)) { String msg = String.format("ERROR: One option of --%s or --%s must be provided.", TERM, TERM_LIST); LOGGER.error(msg);/*from ww w .j a v a 2 s. co m*/ System.err.flush(); out.flush(); System.err.println(msg); System.exit(1); } if (line.hasOption(TERM)) terms.add(line.getOptionValue(TERM)); if (line.hasOption(TERM_LIST)) { File file = new File(line.getOptionValue(TERM_LIST)); for (String term : FileUtils.readLines(file, "UTF-8")) terms.add(Splitter.on("\t").splitToList(term).get(0).trim()); } if (line.hasOption(N)) n = Integer.parseInt(line.getOptionValue(N)); if (line.hasOption(DISTANCE)) { if (line.getOptionValue(DISTANCE).equals(DISTANCE_COSINE)) distance = new Cosine(); else if (line.getOptionValue(DISTANCE).equals(DISTANCE_JACCARD)) distance = new Jaccard(); else TermSuiteCLIUtils.exitWithErrorMessage(String.format("Unknown distance: %s. Allowed values: %s;%s", line.getOptionValue(DISTANCE), DISTANCE_COSINE, DISTANCE_JACCARD)); } LOGGER.info("loading source termino {}", line.getOptionValue(SOURCE_TERMINO)); JsonOptions loadOptions = new JsonOptions().withContexts(true); sourceTermino = Optional .of(JsonTermIndexIO.load(new FileReader(line.getOptionValue(SOURCE_TERMINO)), loadOptions)); LOGGER.info("loading target termino {}", line.getOptionValue(TARGET_TERMINO)); targetTermino = Optional .of(JsonTermIndexIO.load(new FileReader(line.getOptionValue(TARGET_TERMINO)), loadOptions)); dicoPath = line.getOptionValue(DICTIONARY); showExplanation = line.hasOption(EXPLAIN); }
From source file:com.zhonghui.tool.controller.HttpClient.java
/** * HTTP Post???/*ww w.j a va 2 s. com*/ * * @param connection * @param message ??? * @throws IOException */ private void requestServer(final URLConnection connection, String message, String encoder) throws Exception { PrintStream out = null; try { connection.connect(); out = new PrintStream(connection.getOutputStream(), false, encoder); out.print(message); out.flush(); } catch (Exception e) { throw e; } finally { if (null != out) { out.close(); } } }
From source file:org.fusesource.meshkeeper.control.ControlServer.java
private final void saveControllerProps() throws IOException { // Let's dump some controller properties to our working directory: Properties props = new Properties(); props.put(MeshKeeperFactory.MESHKEEPER_REGISTRY_PROPERTY, registryServer.getServiceUri()); String provisionerId = System.getProperty(Provisioner.MESHKEEPER_PROVISIONER_ID_PROPERTY); if (provisionerId != null) { log.info("Writing provisioner id: " + provisionerId); props.put(Provisioner.MESHKEEPER_PROVISIONER_ID_PROPERTY, provisionerId); } else {/*from w ww .j a v a2 s.c om*/ props.put(Provisioner.MESHKEEPER_PROVISIONER_ID_PROPERTY, "none"); } File f = new File(getDirectory(), CONTROLLER_PROP_FILE_NAME); if (f.exists()) { f.delete(); } f.getParentFile().mkdirs(); f.deleteOnExit(); PrintStream fout = new PrintStream(f); props.store(fout, null); fout.flush(); fout.close(); //Lock the properties file: lockPropsFile(); }
From source file:com.act.lcms.plotter.WriteAndPlotMS1Results.java
public void plotScan(List<MS1.YZ> scan, String outPrefix, String fmt) throws IOException { String outPDF = outPrefix + "." + fmt; String outDATA = outPrefix + ".data"; // Write data output to outfile PrintStream out = new PrintStream(new FileOutputStream(outDATA)); // print out the spectra to outDATA for (MS1.YZ yz : scan) { out.format("%.4f\t%.4f\n", yz.getMZ(), yz.getIntensity()); out.flush(); }//w w w . j a va 2 s . c om // close the .data out.close(); // render outDATA to outPDF using gnuplot new Gnuplotter().plot2DImpulsesWithLabels(outDATA, outPDF, new String[] { "mz distribution at TIC max" }, null, "mz", null, "intensity", fmt); }