List of usage examples for java.io PrintWriter close
public void close()
From source file:com.qperior.gsa.oneboxprovider.QPOneBoxProviderServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String resString = "Method 'doPost' is not supported!"; this.log.warn(resString); // Defines response MIME type response.setContentType("text/xml"); // Wirte response back as XML string PrintWriter out = response.getWriter(); out.print(resString);/*from w w w .ja v a 2 s . co m*/ out.close(); }
From source file:net.sourceforge.ajaxtags.struts.BaseAjaxAction.java
@Override public ActionForward execute(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws IOException { try {/*from w w w .j a va 2 s. c om*/ setForm(form); final String xml = AjaxActionHelper.invoke(this, request, response); if (xml != null) { // response.setCharacterEncoding(getXMLEncoding()); final PrintWriter writer = response.getWriter(); writer.write(xml); // IOUtils.closeQuietly(writer); writer.close(); if (log.isDebugEnabled()) { log.debug(xml.length() + " characters written to XML response"); } } } catch (Exception e) { final String message = getErrorMessage(e); log.error(message, e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, StringEscapeUtils.escapeHtml(message)); } setForm(null); return null; }
From source file:com.vmware.identity.openidconnect.protocol.HttpResponse.java
public void applyTo(HttpServletResponse httpServletResponse) throws IOException { Validate.notNull(httpServletResponse, "httpServletResponse"); for (Cookie cookie : this.cookies) { httpServletResponse.addCookie(cookie); }/*from w ww. j av a 2 s. c o m*/ for (Header header : this.headers) { httpServletResponse.addHeader(header.getName(), header.getValue()); } if (this.errorObject != null) { httpServletResponse.sendError(this.errorObject.getStatusCode().getValue(), this.errorObject.getErrorCode().getValue() + ": " + this.errorObject.getDescription()); } else if (this.redirectTarget != null) { httpServletResponse.sendRedirect(this.redirectTarget.toString()); } else if (this.htmlContent != null) { httpServletResponse.setStatus(this.statusCode.getValue()); httpServletResponse.setHeader("Cache-Control", "no-cache, no-store"); httpServletResponse.setHeader("Pragma", "no-cache"); httpServletResponse.setContentType("text/html;charset=UTF-8"); PrintWriter writer = httpServletResponse.getWriter(); writer.print(this.htmlContent); writer.close(); } else if (this.jsonContent != null) { httpServletResponse.setStatus(this.statusCode.getValue()); httpServletResponse.setHeader("Cache-Control", "no-store"); httpServletResponse.setHeader("Pragma", "no-cache"); httpServletResponse.setContentType("application/json;charset=UTF-8"); PrintWriter writer = httpServletResponse.getWriter(); writer.print(this.jsonContent.toString()); writer.close(); } else { throw new IllegalStateException("unexpected"); } }
From source file:com.jiangyifen.ec2.servlet.http.common.filter.HttpCommonFilter.java
/** * @Description ??????/* w w w . ja v a2 s . co m*/ * * @author JRH * @date 201488 ?12:43:21 * @param response HttpServletResponse * @param commonRespBo ?? * @throws IOException */ private void operateResponse(HttpServletResponse response, CommonRespBo commonRespBo) throws IOException { response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); response.setContentType("text/plain"); out.println("" + GsonUtil.toJson(commonRespBo)); out.close(); }
From source file:com.meltmedia.cadmium.servlets.guice.CadmiumListener.java
public final static Injector graphGood(File file, Injector inj) { try {// w w w . ja va 2 s .c om ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter out = new PrintWriter(baos); Injector injector = Guice.createInjector(new GrapherModule(), new GraphvizModule()); GraphvizRenderer renderer = injector.getInstance(GraphvizRenderer.class); renderer.setOut(out).setRankdir("TB"); injector.getInstance(InjectorGrapher.class).of(inj).graph(); out = new PrintWriter(file, "UTF-8"); String s = baos.toString("UTF-8"); s = fixGrapherBug(s); s = hideClassPaths(s); out.write(s); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return inj; }
From source file:es.eucm.mokap.backend.server.MokapBackend.java
/** * Method: POST Processes post requests. * //from w ww. j a va 2s .com * <pre> * - Requests must be multipart/form-data. * - The field with the file must be named "file". * - The file must be a .zip compressed file with the structure * defined in {@link UploadZipStructure}. * </pre> */ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { MokapInsertController iCont = new MokapInsertController(); // Check api key if (!ApiKeyVerifier.checkApiKey(req, resp)) { return; } else { try { // Get the uploaded file stream FileItemStream fis = getUploadedFile(req); if (fis != null) { // Actually process the uploaded resource String str = iCont.processUploadedResource(fis); // Send the response PrintWriter out = resp.getWriter(); out.print(str); out.flush(); out.close(); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, ServerReturnMessages.INVALID_UPLOAD_FILENOTFOUND); } } catch (Exception e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ServerReturnMessages.m(ServerReturnMessages.GENERIC_INTERNAL_ERROR, e.getMessage())); } } }
From source file:es.eucm.mokap.backend.server.MokapBackend.java
/** * Method: GET Processes get requests to perform a search. It performs an * index search with the keyword in that header. Requires a valid api key to * work./*from w w w . j a va 2s . c o m*/ */ @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) { MokapSearchController sCont = new MokapSearchController(); // Check api key try { if (!ApiKeyVerifier.checkApiKey(req, resp)) { PrintWriter out = resp.getWriter(); out.print("Wrong API key."); out.flush(); out.close(); } else { PrintWriter out = resp.getWriter(); // Get the parameters from the header / parameter SearchParams sp = SearchParamsFactory.create(req); String str = sCont.performSearch(sp); // Set the response encoding resp.setCharacterEncoding("UTF-8"); resp.setContentType("application/json"); out.print(str); out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:DataTextWriter.java
/** * This method creates a flat file containing the data added to this DataTextWriter. * @param sFilename The name of flat file to create. *//*from w w w . jav a 2s .co m*/ public void writeFile(String sFilename) throws Exception { try { FileOutputStream fos = new FileOutputStream(sFilename); PrintWriter pw = new PrintWriter(fos); pw.print(getText()); pw.close(); fos.close(); } catch (Exception e) { throw new Exception(e.getMessage()); } }
From source file:com.sir_m2x.messenger.utils.CustomExceptionHandler.java
@Override public void uncaughtException(final Thread t, final Throwable e) { ((NotificationManager) this.context.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll(); Utils.saveEventLog(MessengerService.getEventLog()); SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd HHMM"); String timestamp = df.format(new Date(System.currentTimeMillis())); final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); e.printStackTrace(printWriter);//w w w. j a v a 2s. c o m String stacktrace = result.toString(); printWriter.close(); String filename = timestamp + " " + Build.VERSION.SDK_INT + ".stacktrace"; if (Preferences.logCrash) // if (this.url != null) // sendToServer(stacktrace, filename); if (this.localPath != null) writeToFile(stacktrace, filename); this.defaultUEH.uncaughtException(t, e); }
From source file:com.st.qunar.order.web.order.OrderController.java
@RequestMapping(value = "export") public void mockQnOrderExportServer(HttpServletResponse resp) throws IOException { resp.setCharacterEncoding("UTF-8"); PrintWriter pw = resp.getWriter(); String xml = FileUtils.readFileToString(new File("qn?50?.xml")); System.out.println("getFile:" + xml); pw.write(xml);//w ww.j a va2 s. c om pw.close(); }