List of usage examples for java.io PrintWriter flush
public void flush()
From source file:be.solidx.hot.web.deprecated.HotControllerImpl.java
protected String extractStackTrace(Exception e) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter);/*w ww .j a v a 2 s. c o m*/ printWriter.flush(); return printWriter.toString(); }
From source file:cn.vlabs.umt.ui.servlet.AppProxyServlet.java
private void sendRandom(HttpServletRequest request, HttpServletResponse response) throws IOException { RandomUtil ru = new RandomUtil(); String random = ru.getRandom(20); request.getSession().setAttribute("proxy_random", random); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(random);/*www. j ava 2s .c om*/ out.flush(); out.close(); }
From source file:se.vgregion.sitemap.servlet.DefaultSitemapServlet.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) *//* w w w. j a va 2 s . co m*/ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { getLogger().debug("doGet(): Starting to put together the sitemap."); long startTimeMillis = System.currentTimeMillis(); String sitemapContent = getSitemapService().getSitemapContent(); long endTimeMillis = System.currentTimeMillis(); getLogger() .debug("Generation finished. It took: " + (endTimeMillis - startTimeMillis) / 1000 + " seconds."); response.setCharacterEncoding(ENCODING_UTF8); PrintWriter pw = response.getWriter(); pw.write(sitemapContent); pw.flush(); pw.close(); }
From source file:com.att.api.immn.controller.GetMsgContentController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); OAuthToken token = (OAuthToken) session.getAttribute("token"); IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token); final String msgId = request.getParameter("contentMsgId"); final String partNumb = request.getParameter("contentPartNumber"); JSONObject jresponse = new JSONObject(); try {//from w w w .j a v a 2 s . c o m final MessageContent msgContent = srvc.getMessageContent(msgId, partNumb); jresponse.put("success", true); final String type = msgContent.getContentType().toLowerCase(); /* TODO: handle unknown type */ if (type.contains("text")) { jresponse.put("text", "Message Content: " + new String(msgContent.getContent())); } else if (type.contains("image")) { final byte[] binary = msgContent.getContent(); final String base64 = new String(Base64.encodeBase64(binary)); final JSONObject image = new JSONObject().put("type", msgContent.getContentType()).put("base64", base64); jresponse.put("image", image); } else if (type.contains("video")) { final byte[] binary = msgContent.getContent(); final String base64 = new String(Base64.encodeBase64(binary)); final JSONObject image = new JSONObject().put("type", msgContent.getContentType()).put("base64", base64); jresponse.put("video", image); } else if (type.contains("audio")) { final byte[] binary = msgContent.getContent(); final String base64 = new String(Base64.encodeBase64(binary)); final JSONObject image = new JSONObject().put("type", msgContent.getContentType()).put("base64", base64); jresponse.put("audio", image); } } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:com.controlj.green.istat.web.BookmarkServlet.java
public void writeLocations(final ServletOutputStream out, final String locations[], HttpServletRequest req) throws IOException, SystemException, ActionExecutionException, InvalidConnectionRequestException { final JSONArray arrayData = new JSONArray(); if (locations != null) { SystemConnection connection = DirectAccess.getDirectAccess().getUserSystemConnection(req); connection.runReadAction(new ReadAction() { public void execute(@NotNull SystemAccess access) throws Exception { for (String location : locations) { JSONObject next = new JSONObject(); Location loc = access.getGeoRoot().getTree().resolve(location); next.put("display", loc.getDisplayName()); next.put("id", location); arrayData.put(next); }/* w w w.j a va 2 s.co m*/ } }); } try { PrintWriter writer = new PrintWriter(out); arrayData.write(writer); writer.flush(); } catch (JSONException e) { Logging.LOGGER.println("Unexpected exception encoding JSON:"); e.printStackTrace(Logging.LOGGER); } }
From source file:edu.cornell.mannlib.vitro.webapp.sparql.GetClazzDataProperties.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!isAuthorizedToDisplayPage(request, response, SimplePermission.USE_MISCELLANEOUS_PAGES.ACTION)) { return;// w w w . ja v a 2 s . co m } VitroRequest vreq = new VitroRequest(request); String vClassURI = vreq.getParameter("vClassURI"); if (vClassURI == null || vClassURI.trim().equals("")) { return; } String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; respo += "<options>"; // Add rdfs:label to the list respo += "<option>" + "<key>" + "label" + "</key>" + "<value>" + "http://www.w3.org/2000/01/rdf-schema#label" + "</value>" + "</option>"; DataPropertyDao ddao = vreq.getUnfilteredWebappDaoFactory().getDataPropertyDao(); Collection<DataProperty> dataProps = ddao.getDataPropertiesForVClass(vClassURI); Iterator<DataProperty> dataPropIt = dataProps.iterator(); HashSet<String> dpropURIs = new HashSet<String>(); while (dataPropIt.hasNext()) { DataProperty dp = dataPropIt.next(); if (!(dpropURIs.contains(dp.getURI()))) { dpropURIs.add(dp.getURI()); DataProperty dprop = (DataProperty) ddao.getDataPropertyByURI(dp.getURI()); if (dprop != null) { respo += "<option>" + "<key>" + dprop.getLocalName() + "</key>" + "<value>" + dprop.getURI() + "</value>" + "</option>"; } } } respo += "</options>"; response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.println(respo); out.flush(); out.close(); }
From source file:com.oracle.weblogic.examples.spring.jmx.WebLogicRESTJMXProxy.java
@RequestMapping(value = "/att/{namespace}/{beanName}/{attName}", method = RequestMethod.PUT) @ResponseBody//w w w.j ava2s . co m public String setAttributeValueFromPUT(@RequestBody String newValue, @PathVariable("namespace") String namespace, @PathVariable("beanName") String beanName, @PathVariable("attName") String attName) { ObjectNameWrapper beanObjectNameWrapper = new ObjectNameWrapper(); beanObjectNameWrapper.setBeanName(beanName); beanObjectNameWrapper.setNamespace(namespace); StringBuilder sb = new StringBuilder(); try { proxy.setAttributeValue(beanObjectNameWrapper, attName, newValue); sb.append("Success!"); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter writer = new PrintWriter(sw); e.printStackTrace(writer); writer.flush(); sb.append(sw.toString()); } return sb.toString(); }
From source file:com.oracle.weblogic.examples.spring.jmx.WebLogicRESTJMXProxy.java
@RequestMapping(value = "/att/{namespace}/{beanName}/{attName}/{newValue}", method = RequestMethod.GET) @ResponseBody/*from w w w .j a va2s . c om*/ public String setAttributeValueFromGET(@PathVariable("namespace") String namespace, @PathVariable("beanName") String beanName, @PathVariable("attName") String attName, @PathVariable("newValue") String newValue) { StringBuilder sb = new StringBuilder(); ObjectNameWrapper beanObjectNameWrapper = new ObjectNameWrapper(); beanObjectNameWrapper.setBeanName(beanName); beanObjectNameWrapper.setNamespace(namespace); try { proxy.setAttributeValue(beanObjectNameWrapper, attName, newValue); sb.append("Success!"); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter writer = new PrintWriter(sw); e.printStackTrace(writer); writer.flush(); sb.append(sw.toString()); } return sb.toString(); }
From source file:gate.termraider.output.CsvGenerator.java
public void generateAndSaveCsv(AbstractTermbank termbank, double threshold, File outputFile) throws GateException { this.termbank = termbank; this.debugMode = termbank.getDebugMode(); this.scorePropertyName = termbank.getScoreProperty(); PrintWriter writer = initializeWriter(outputFile); generateCsv(writer, threshold);/* www . j a v a 2 s.c o m*/ writer.flush(); writer.close(); if (debugMode) { System.out.println("Termbank: saved CSV in " + outputFile.getAbsolutePath()); } }
From source file:bookUtilities.AddBookServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*www.jav a 2s. c o 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 { response.setContentType("text/html;charset=UTF-8"); JSONObject message = addBook(request.getParameter("title"), request.getParameter("cover"), request.getParameter("author"), request.getParameter("genre"), request.getParameter("description"), request.getParameter("language"), request.getParameter("publisher"), request.getParameter("file")); PrintWriter printout = response.getWriter(); printout.print(message); printout.flush(); }