List of usage examples for java.io PrintWriter flush
public void flush()
From source file:org.zkoss.zkgrails.ZKGrailsPageFilter.java
/** Write the original page data to the response. */ private void writeOriginal(HttpServletRequest request, HttpServletResponse response, Page page) throws IOException { response.setContentLength(page.getContentLength()); if (request.getAttribute(USING_STREAM).equals(Boolean.TRUE)) { PrintWriter writer = new PrintWriter(response.getOutputStream()); page.writePage(writer);/* www . ja v a 2 s. co m*/ //flush writer to underlying outputStream writer.flush(); response.getOutputStream().flush(); } else { page.writePage(response.getWriter()); response.getWriter().flush(); } }
From source file:ch.epfl.lsir.xin.algorithm.baseline.ItemAverage.java
@Override public void saveModel(String file) { // TODO Auto-generated method stub //each line corresponds to each item try {/*from ww w .ja v a 2s .c om*/ PrintWriter printer = new PrintWriter(file); for (int i = 0; i < this.ratingMatrix.getItemsMean().size(); i++) { printer.println(this.ratingMatrix.getItemsMean().get(i)); } printer.flush(); printer.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ch.epfl.lsir.xin.algorithm.baseline.UserAverage.java
@Override public void saveModel(String file) { // TODO Auto-generated method stub //each line corresponds to each user try {//from w w w. ja v a 2s . c o m PrintWriter printer = new PrintWriter(file); for (int i = 0; i < this.ratingMatrix.getUsersMean().size(); i++) { printer.println(this.ratingMatrix.getUsersMean().get(i)); } printer.flush(); printer.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:graphql.servlet.GraphQLServletTest.java
@Test @SneakyThrows/*w w w .j a va 2 s . c o m*/ public void schema() { GraphQLServlet servlet = new GraphQLServlet(); HttpServletRequest req = mock(HttpServletRequest.class); when(req.getPathInfo()).thenReturn("/schema.json"); HttpServletResponse resp = mock(HttpServletResponse.class); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PrintWriter writer = new PrintWriter(outputStream, true); when(resp.getWriter()).thenReturn(writer); verify(resp, times(0)).setStatus(anyInt()); servlet.bindQueryProvider(new TestQueryProvider()); servlet.doGet(req, resp); writer.flush(); Map<String, Object> response = new ObjectMapper().readValue(outputStream.toByteArray(), new TypeReference<Map<String, Object>>() { }); assertTrue(response.containsKey("data")); assertFalse(response.containsKey("errors")); }
From source file:com.reelfx.model.ScreenRecorder.java
public void stopRecording() { if (Applet.IS_LINUX || Applet.IS_WINDOWS) { PrintWriter pw = new PrintWriter(recordingProcess.getOutputStream()); pw.print("q"); pw.flush(); } else if (Applet.IS_MAC) { PrintWriter pw = new PrintWriter(recordingProcess.getOutputStream()); pw.println("stop"); pw.flush();//w w w . j a v a2 s. c o m } logger.info("Screen recording should be stopped."); }
From source file:org.apache.sling.testing.tools.http.RequestDocumentor.java
void generateDocumentation(RequestExecutor executor, String[] metadata) throws IOException { final File f = getOutputFile(); final File dir = f.getParentFile(); dir.mkdirs();//from w ww . j a v a2 s . co m if (!dir.isDirectory()) { throw new IOException("Failed to create output folder " + dir.getAbsolutePath()); } final PrintWriter pw = new PrintWriter(new FileWriter(f, true)); try { System.out.println("Appending documentation of " + executor + " to " + f.getAbsolutePath()); documentRequest(pw, executor, metadata); } finally { pw.flush(); pw.close(); } }
From source file:org.biopax.paxtools.client.BiopaxValidatorClient.java
/** * Checks a BioPAX OWL file(s) or resource * using the online BioPAX Validator //from w ww . j a v a 2 s .c o m * and prints the results to the output stream. * * @param autofix true/false (experimental) * @param profile validation profile name * @param retFormat xml, html, or owl (no errors, just modified owl, if autofix=true) * @param filterBy filter validation issues by the error/warning level * @param maxErrs errors threshold - max no. critical errors to collect before quitting * (warnings not counted; null/0/negative value means unlimited) * @param biopaxUrl check the BioPAX at the URL * @param biopaxFiles an array of BioPAX files to validate * @param out validation report data output stream * @throws IOException when there is an I/O error */ public void validate(boolean autofix, String profile, RetFormat retFormat, Behavior filterBy, Integer maxErrs, String biopaxUrl, File[] biopaxFiles, OutputStream out) throws IOException { MultipartEntityBuilder meb = MultipartEntityBuilder.create(); meb.setCharset(Charset.forName("UTF-8")); if (autofix) meb.addTextBody("autofix", "true"); //TODO add extra options (normalizer.fixDisplayName, normalizer.inferPropertyOrganism, normalizer.inferPropertyDataSource, normalizer.xmlBase)? if (profile != null && !profile.isEmpty()) meb.addTextBody("profile", profile); if (retFormat != null) meb.addTextBody("retDesired", retFormat.toString().toLowerCase()); if (filterBy != null) meb.addTextBody("filter", filterBy.toString()); if (maxErrs != null && maxErrs > 0) meb.addTextBody("maxErrors", maxErrs.toString()); if (biopaxFiles != null && biopaxFiles.length > 0) for (File f : biopaxFiles) //important: use MULTIPART_FORM_DATA content-type meb.addBinaryBody("file", f, ContentType.MULTIPART_FORM_DATA, f.getName()); else if (biopaxUrl != null) { meb.addTextBody("url", biopaxUrl); } else { log.error("Nothing to do (no BioPAX data specified)!"); return; } //execute the query and get results as string HttpEntity httpEntity = meb.build(); // httpEntity.writeTo(System.err); String content = Executor.newInstance()//Executor.newInstance(httpClient) .execute(Request.Post(url).body(httpEntity)).returnContent().asString(); //save: append to the output stream (file) BufferedReader res = new BufferedReader(new StringReader(content)); String line; PrintWriter writer = new PrintWriter(out); while ((line = res.readLine()) != null) { writer.println(line); } writer.flush(); res.close(); }
From source file:com.bmwcarit.barefoot.tracker.TrackerServerTest.java
public MatcherKState requestState(InetAddress host, int port, String id) throws JSONException, InterruptedException, IOException { int trials = 120; int timeout = 500; Socket client = null;/*from w w w . ja va 2s . c o m*/ while (client == null || !client.isConnected()) { try { client = new Socket(host, port); } catch (IOException e) { Thread.sleep(timeout); if (trials == 0) { logger.error(e.getMessage()); client.close(); throw new IOException(); } else { trials -= 1; } } } JSONObject json = new JSONObject(); json.put("id", id); PrintWriter writer = new PrintWriter(client.getOutputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream())); writer.println(json.toString()); writer.flush(); String code = reader.readLine(); assertEquals("SUCCESS", code); String response = reader.readLine(); client.close(); return new MatcherKState(new JSONObject(response), new MatcherFactory(TrackerControl.getServer().getMap())); }
From source file:com.reelfx.model.ScreenRecorder.java
public void startRecording() { if (Applet.IS_MAC) { PrintWriter pw = new PrintWriter(recordingProcess.getOutputStream()); pw.println("start"); pw.flush(); }/*from www . j a v a2s . co m*/ // nothing for linux or windows }