List of usage examples for java.io PrintStream flush
public void flush()
From source file:org.kuali.kfs.module.tem.batch.service.impl.PerDiemLoadServiceImpl.java
/** * validate the given per diem records/*from w w w . ja v a 2s . c om*/ * * @return the valid per diem records */ protected <T extends PerDiem> List<T> validatePerDiem(List<T> perDiemList, String fileName) { List<T> validPerDiems = new ArrayList<T>(); PrintStream reportDataStream = this.getReportPrintStream(); this.writeReportHeader(reportDataStream, fileName); for (T perDiem : perDiemList) { List<Message> errorMessage = this.getPerDiemLoadValidationService().validate(perDiem); if (ObjectUtils.isNotNull(errorMessage) && !errorMessage.isEmpty()) { this.writeErrorToReport(reportDataStream, perDiem, errorMessage); } else { validPerDiems.add(perDiem); } } if (reportDataStream != null) { reportDataStream.flush(); reportDataStream.close(); } return validPerDiems; }
From source file:es.cnio.bioinfo.bicycle.gatk.MethylationFilePair.java
private void flushCrick() { PrintStream stream; try {//from w w w . j a v a 2 s. c o m stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(crickFile, true))); stream.print(crickBuffer.toString()); crickBuffer.setLength(0); stream.flush(); stream.close(); printCrickCount = 0; } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
From source file:es.cnio.bioinfo.bicycle.gatk.MethylationFilePair.java
private void flushWatson() { PrintStream stream; try {// www .ja v a2s . c o m stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(watsonFile, true))); stream.print(watsonBuffer.toString()); watsonBuffer.setLength(0); stream.flush(); stream.close(); printWatsonCount = 0; } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
From source file:com.esri.geoportal.harvester.api.base.DataReferenceSerializer.java
/** * Serializes data reference/* w w w. ja v a 2s . c o m*/ * * @param out output print stream * @param ref data reference * @throws IOException if serialization fails */ public void serialize(PrintStream out, DataReference ref) throws IOException { byte[] bBrokerUri = ENCODER.encode(ref.getBrokerUri().toASCIIString().getBytes("UTF-8")); byte[] bBrokerName = ENCODER.encode(StringUtils.trimToEmpty(ref.getBrokerName()).getBytes("UTF-8")); byte[] bId = ENCODER.encode(ref.getId().getBytes("UTF-8")); byte[] bLastModifiedDate = ENCODER .encode((ref.getLastModifiedDate() != null ? formatIsoDate(ref.getLastModifiedDate()) : "") .getBytes("UTF-8")); byte[] bSourceUri = ENCODER.encode(ref.getSourceUri().toASCIIString().getBytes("UTF-8")); byte[] bContent = ENCODER.encode(ref.getContent()); byte[] bContentType = ENCODER.encode( ref.getContentType() != null ? ref.getContentType().toString().getBytes("UTF-8") : new byte[0]); out.write(bBrokerUri); out.write(','); out.write(bBrokerName); out.write(','); out.write(bId); out.write(','); out.write(bLastModifiedDate); out.write(','); out.write(bSourceUri); out.write(','); out.write(bContentType); out.write(','); out.write(bContent); out.write('\r'); out.write('\n'); out.flush(); }
From source file:org.pantsbuild.tools.junit.impl.ConsoleRunnerImpl.java
/** * Returns a thread that records a system exit to the listener, and then halts(1). */// www .j a v a2 s . com private Thread createAbnormalExitHook(final AbortableListener listener, final PrintStream out) { Thread abnormalExitHook = new Thread() { @Override public void run() { try { listener.abort(new UnknownError("Abnormal VM exit - test crashed.")); // We want to trap and log no matter why abort failed for a better end user message. // SUPPRESS CHECKSTYLE RegexpSinglelineJava } catch (Exception e) { out.println(e); e.printStackTrace(out); } // This error might be a call to `System.exit(0)`, which we definitely do // not want to go unnoticed. out.println("FATAL: VM exiting uncleanly."); out.flush(); Runtime.getRuntime().halt(1); } }; return abnormalExitHook; }
From source file:org.apache.streams.instagram.test.data.InstagramMediaFeedDataConverterIT.java
@Test public void InstagramMediaFeedDataConverterITCase() throws Exception { InputStream is = InstagramMediaFeedDataConverterIT.class.getResourceAsStream("/testMediaFeedObjects.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); PrintStream outStream = new PrintStream(new BufferedOutputStream( new FileOutputStream("target/test-classes/InstagramMediaFeedDataConverterITCase.txt"))); try {/* w w w. j a v a 2 s . co m*/ while (br.ready()) { String line = br.readLine(); if (!StringUtils.isEmpty(line)) { LOGGER.info("raw: {}", line); MediaFeedData mediaFeedData = gson.fromJson(line, MediaFeedData.class); ActivityConverter<MediaFeedData> converter = new InstagramMediaFeedDataConverter(); Activity activity = converter.toActivityList(mediaFeedData).get(0); LOGGER.info("activity: {}", activity.toString()); assertThat(activity, is(not(nullValue()))); assertThat(activity.getId(), is(not(nullValue()))); assertThat(activity.getActor(), is(not(nullValue()))); assertThat(activity.getActor().getId(), is(not(nullValue()))); assertThat(activity.getVerb(), is(not(nullValue()))); assertThat(activity.getProvider(), is(not(nullValue()))); outStream.println(mapper.writeValueAsString(activity)); } } outStream.flush(); } catch (Exception ex) { LOGGER.error("Exception: ", ex); outStream.flush(); Assert.fail(); } }
From source file:org.codehaus.enunciate.modules.amf.AMFDeploymentModule.java
/** * Reads a resource into string form.// w w w . j ava2 s .co m * * @param resource The resource to read. * @return The string form of the resource. */ protected String readResource(String resource) throws IOException, EnunciateException { HashMap<String, Object> model = new HashMap<String, Object>(); model.put("sample_service_method", getModelInternal().findExampleWebMethod()); model.put("sample_resource", getModelInternal().findExampleResourceMethod()); URL res = AMFDeploymentModule.class.getResource(resource); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bytes); try { processTemplate(res, model, out); out.flush(); bytes.flush(); return bytes.toString("utf-8"); } catch (TemplateException e) { throw new EnunciateException(e); } }
From source file:abfab3d.io.output.SVXWriter.java
private void writeManifest(AttributeGrid grid, OutputStream os) { int subvoxelBits = 8; // where it should came from? AttributeDesc attDesc = grid.getAttributeDesc(); if (attDesc == null) throw new RuntimeException("grid attribute description is null"); PrintStream ps = new PrintStream(os); double[] bounds = new double[6]; grid.getGridBounds(bounds);/*from www .ja v a 2 s . co m*/ printf(ps, "<?xml version=\"1.0\"?>\n"); printf(ps, "<grid gridSizeX=\"%d\" gridSizeY=\"%d\" gridSizeZ=\"%d\" voxelSize=\"%f\" subvoxelBits=\"%d\" originX=\"%f\" originY=\"%f\" originZ=\"%f\" slicesOrientation=\"%s\">\n", grid.getWidth(), grid.getHeight(), grid.getDepth(), grid.getVoxelSize(), subvoxelBits, bounds[0], bounds[2], bounds[4], m_orientationNames[m_orientation]); String indent = " "; String indent2 = indent + indent; printf(ps, indent + "<channels>\n"); for (int i = 0; i < attDesc.size(); i++) { AttributeChannel channel = attDesc.getChannel(i); String channelPattern = channel.getName() + "/" + "slice%04d.png"; int bits = channel.getBitCount(); if (DEBUG) printf("channel type: %s name: %s\n", channel.getType(), channel.getName()); printf(ps, indent2 + "<channel type=\"%s\" slices=\"%s\" bits=\"%d\" />\n", channel.getType(), channelPattern, bits); } printf(ps, indent + "</channels>\n"); printf(ps, "</grid>\n"); ps.flush(); }
From source file:com.aliyun.odps.mapred.bridge.BridgeRunningJob.java
/** * Print job progress./* ww w .j a v a 2 s . co m*/ * * @throws IOException * @throws OdpsException * if get task progress failed */ private void printProgress() throws OdpsException { PrintStream out = System.out; List<StageProgress> stages = null; stages = instance.getTaskProgress(taskName); if (stages != null && stages.size() != 0) { out.print(Instance.getStageProgressFormattedString(stages)); int mappers = 0; int reducers = 0; mapProgress = 0; reduceProgress = 0; for (StageProgress stage : stages) { int totalWorkers = stage.getTotalWorkers(); if (stage.getName().startsWith("M")) { mappers += totalWorkers; mapProgress += stage.getFinishedPercentage() / 100.0 * totalWorkers; } else { reducers += totalWorkers; reduceProgress += stage.getFinishedPercentage() / 100.0 * totalWorkers; } } mapProgress = mappers == 0 ? 0 : mapProgress / mappers; reduceProgress = reducers == 0 ? 0 : reduceProgress / reducers; } else { out.print("..."); } out.print('\r'); out.flush(); }
From source file:org.openhab.binding.ebus.tools.EBusJsonConfTool.java
@SuppressWarnings("unchecked") public void run() throws JsonParseException, JsonMappingException, IOException { final File currentDir = new File("").getAbsoluteFile(); final ObjectMapper mapper = new ObjectMapper(); List<Map<String, ?>> configurationMap = new ArrayList<Map<String, ?>>(); File folder = new File(currentDir, "src/main/resources/"); File[] listOfFiles = folder.listFiles(); PrintStream out = null; PrintStream mainOut = new PrintStream(new File(currentDir, "docs/json-configs.md")); mainOut.print("# JSON configuration files\n"); mainOut.print("\n"); mainOut.print("This is an automatic created list of all included configuration files.\n"); mainOut.print("\n"); EBusConfigurationProvider ebuscfg = new EBusConfigurationProvider(); for (File file : listOfFiles) { if (file.getName().endsWith("configuration.json")) { String string = StringUtils.substringBefore(file.getName(), "-configuration.json"); out = new PrintStream(new File(currentDir, "docs/json-files/" + string + ".md")); out.print("# JSON configuration for _" + string + "_\n"); out.print("\n"); ebuscfg.loadConfigurationFile(file.toURI().toURL()); List<Map<String, ?>> readValue = mapper.readValue(file, List.class); writeMarkdownIdTable(readValue, out); out.print("\n"); out.print("_bold part is the command-id part_\n"); out.print("\n"); configurationMap.addAll(readValue); out.flush(); out.close();/* w w w. j a va 2s. c om*/ mainOut.print("* [" + string + "](./json-files/" + string + ".md)\n"); } } mainOut.println(); mainOut.flush(); mainOut.close(); checkConfiguration(configurationMap); }