List of usage examples for java.io PrintWriter flush
public void flush()
From source file:com.msbmsb.genealogeo.ui.cli.GenealoGeoCLI.java
/** * Display usage message/*from w w w.ja v a2 s . c om*/ */ public void usage(String msg) { HelpFormatter hf = new HelpFormatter(); PrintWriter pw = new PrintWriter(System.err); hf.setSyntaxPrefix("Usage: "); hf.printHelp(pw, hf.getWidth(), this.usage, null, this.opts, hf.getLeftPadding(), hf.getDescPadding(), msg, false); pw.flush(); System.exit(1); }
From source file:eu.annocultor.tools.GeneratorOfXmlSchemaForConvertersDoclet.java
static void printRuleDocStart(ClassDoc constr, PrintWriter out) throws Exception { out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.println("<document xmlns=\"http://maven.apache.org/XDOC/2.0\""); out.println(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); out.println(//from w w w. j a va 2s . c om " xsi:schemaLocation=\"http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd\">"); out.println(); out.println(" <properties>"); out.println(" <title>Rule " + constr.name() + "</title>"); out.println(" </properties>"); out.println(" <body>"); out.println(" <h1 id=\"Rule " + constr.name() + "\">Rule <code>" + constr.name() + "</code></h1>"); out.println(); out.println(" <p>" + constr.commentText() + "</p>"); out.println(); out.flush(); }
From source file:Controllers.ProfileController.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w. ja va2 s . c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, ClassNotFoundException { if ("GET_PROFILE".equals(request.getParameter("TASK"))) { //Returns a user as a JSON string from a user ID String userID = request.getParameter("user_id"); User user = new User(); user.setFacebookID(userID); user = user.getUser(); //GET RIDES TAKEN AND GIVEN HERE //user.updateGivenAndTaken(); JSONObject jsonUser = user.toJSON(); response.setContentType("application/json"); PrintWriter out = response.getWriter(); out.append(jsonUser.toString()); //Might be toString instead out.flush(); } else if ("UPDATE_CAR".equals(request.getParameter("TASK"))) { //Returns a user as a JSON string from a user ID String userID = request.getParameter("user_id"); User user = new User(); user.setFacebookID(userID); user = user.getUser(); String newBrand = request.getParameter("car_brand"); String newModel = request.getParameter("car_model"); String newColour = request.getParameter("car_colour"); String newLicence = request.getParameter("licence_plate"); user.setCarBrand(newBrand); user.setCarModel(newModel); user.setCarColour(newColour); user.setLicencePlate(newLicence); user.updateDB(); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.append("Profile Updated"); //Might be toString instead out.flush(); } }
From source file:com.ss.Controller.T4uGetAllScheduleServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w . j a v a 2 s.co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int scheduleId = Integer.parseInt(request.getParameter("scheduleId")); T4uSchedule t4uSchedule = null; t4uSchedule = T4uScheduleDAO.getScheduleById(scheduleId); JSONObject jsonObjectMary = new JSONObject(t4uSchedule); response.setContentType("application/json"); // Get the printwriter object from response to write the required json object to the output stream PrintWriter out = response.getWriter(); // Assuming your json object is **jsonObject**, perform the following, it will return your json object out.print(jsonObjectMary); out.flush(); }
From source file:mack.servlets.TransfServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w. jav a 2 s .co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ private void geraXML() throws FileNotFoundException, IOException { HttpClient cliente = HttpClients.createDefault(); HttpGet httpget = new HttpGet("http://localhost:8081/AppFrontController/LP3Rest/lp3/posicoesXML/denis"); HttpResponse resposta = cliente.execute(httpget); System.out.println("----------------------------------------"); System.out.println(resposta.getStatusLine()); HttpEntity entity = resposta.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); StringBuilder out = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { out.append(line); } PrintWriter w = new PrintWriter("/temp/posicao.xml"); w.print(out.toString()); w.flush(); w.close(); reader.close(); instream.close(); } }
From source file:com.cloudera.branchreduce.onezero.Main.java
@Override public int run(String[] args) throws Exception { if (args.length == 0) { final PrintWriter writer = new PrintWriter(System.out); final HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printUsage(writer, 80, "0-1 Implicit Enumeration", OPTIONS); writer.flush(); return 1; }//from w w w . ja va 2 s.co m CommandLine cmdLine = (new GnuParser()).parse(OPTIONS, args); boolean runLocally = cmdLine.hasOption("local"); File lpFile = new File(cmdLine.getOptionValue("lpfile")); BranchReduceJob<PartialSolution, CurrentBestSolution> job = ImplicitEnumerationSolver.createJob(runLocally, lpFile, getConf()); job.setJobName("BranchReduce: Implicit Enumeration of: " + lpFile.getName()); if (cmdLine.hasOption("workers")) { job.setNumWorkers(new Integer(cmdLine.getOptionValue("workers"))); } if (cmdLine.hasOption("threads")) { job.setNumThreads(new Integer(cmdLine.getOptionValue("threads"))); } if (cmdLine.hasOption("memory")) { job.setMemory(new Integer(cmdLine.getOptionValue("memory"))); } BranchReduceContext<PartialSolution, CurrentBestSolution> ctxt = job.submit(); if (ctxt == null) { return 1; } return 0; }
From source file:com.lyonsdensoftware.vanitymirror.PythonConnectionThread.java
public void sendMessageToServer(String messageType, String message) { // Create JSON and GSon objects JSONObject json = new JSONObject(); Gson gson = new Gson(); // Put message into JSON json.put("messageType", messageType); json.put("message", message); //Make printer writer PrintWriter pw = new PrintWriter(mainWindow.getToServer()); // Send the message pw.println(gson.toJson(json));//from w w w .j a v a 2s .co m pw.flush(); }
From source file:com.shopzilla.ducky.WadlXsltFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (this.requestMatcher.match(request)) { LOG.debug("adding transform"); ByteBufferResponseWrapper wrapper = new ByteBufferResponseWrapper((HttpServletResponse) response); String styleSheetPath = makeProcessingInstruction(request); chain.doFilter(request, wrapper); wrapper.getWriter().flush();/* www. ja va 2 s .c o m*/ String responseStr = injectStyleSheet(wrapper.toString(), styleSheetPath); response.setContentLength(responseStr.length()); PrintWriter out = response.getWriter(); out.append(responseStr); out.flush(); } else { LOG.debug("NOT adding transform"); // just pass it along chain.doFilter(request, response); } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.writers.SentencesWriter.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try {/*from ww w .j a v a 2 s.c o m*/ PrintWriter pw = new PrintWriter(new File(outputFolder, DocumentMetaData.get(aJCas).getDocumentId())); for (Sentence sentence : JCasUtil.select(aJCas, Sentence.class)) { pw.println(sentence.getCoveredText()); } pw.flush(); IOUtils.closeQuietly(pw); } catch (FileNotFoundException e) { throw new AnalysisEngineProcessException(e); } }
From source file:jp.aegif.liferay.experiment.mryoshio.rr.ReservationPortlet.java
@Override public void serveResource(ResourceRequest req, ResourceResponse res) throws IOException, PortletException { if (logger.isDebugEnabled()) debug(req);//from ww w .j a va2 s . c om try { String rid = req.getResourceID(); PortletBag pbag = PortletBagPool.get(PortalUtil.getPortletId(req)); String ajaxResponse = null; if ("add-view".equals(rid) || "update-view".equals(rid)) { ajaxResponse = PortalUtil.renderPage(pbag.getServletContext(), PortalUtil.getHttpServletRequest(req), PortalUtil.getHttpServletResponse(res), editJSP, false); } else if ("list-view".equals(rid)) { ajaxResponse = getListDataAsJson(Integer.parseInt(req.getParameter("itemPerPage")), Integer.parseInt(req.getParameter("targetPage"))); } else if ("update-reservation".equals(rid)) { updateReservation(req); } else if ("delete-reservation".equals(rid)) { deleteReservation(req); } else { ajaxResponse = ERR_NO_TYPE_SPECIFIED; } PrintWriter writer = res.getWriter(); writer.write(ajaxResponse); writer.flush(); writer.close(); } catch (ServletException e) { throw new PortletException(e); } }