List of usage examples for java.io PrintWriter close
public void close()
From source file:org.vbossica.springbox.metrics.PingController.java
@RequestMapping(value = "/metrics/ping", method = RequestMethod.GET) public void process(HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); resp.setStatus(HttpServletResponse.SC_OK); if (message != null || message.isEmpty()) { PrintWriter writer = resp.getWriter(); try {// ww w.j a v a 2 s .c o m writer.println(message); } finally { writer.close(); } } }
From source file:FileTableHTML.java
public static String makeHTMLTable(String dirname) { // Look up the contents of the directory File dir = new File(dirname); String[] entries = dir.list(); // Set up an output stream we can print the table to. // This is easier than concatenating strings all the time. StringWriter sout = new StringWriter(); PrintWriter out = new PrintWriter(sout); // Print the directory name as the page title out.println("<H1>" + dirname + "</H1>"); // Print an "up" link, unless we're already at the root String parent = dir.getParent(); if ((parent != null) && (parent.length() > 0)) out.println("<A HREF=\"" + parent + "\">Up to parent directory</A><P>"); // Print out the table out.print("<TABLE BORDER=2 WIDTH=600><TR>"); out.print("<TH>Name</TH><TH>Size</TH><TH>Modified</TH>"); out.println("<TH>Readable?</TH><TH>Writable?</TH></TR>"); for (int i = 0; i < entries.length; i++) { File f = new File(dir, entries[i]); out.println("<TR><TD>" + (f.isDirectory() ? "<a href=\"" + f + "\">" + entries[i] + "</a>" : entries[i]) + "</TD><TD>" + f.length() + "</TD><TD>" + new Date(f.lastModified()) + "</TD><TD align=center>" + (f.canRead() ? "x" : " ") + "</TD><TD align=center>" + (f.canWrite() ? "x" : " ") + "</TD></TR>"); }// w ww .j a v a2 s .c o m out.println("</TABLE>"); out.close(); // Get the string of HTML from the StringWriter and return it. return sout.toString(); }
From source file:cn.sharesdk.analysis.util.CrashHandler.java
private String getErrorInfo(Throwable arg1) { Writer writer = new StringWriter(); PrintWriter pw = new PrintWriter(writer); arg1.printStackTrace(pw);/*from w w w .ja v a 2 s. co m*/ pw.close(); String error = writer.toString(); return error; }
From source file:com.uniquesoft.uidl.servlet.UploadServlet.java
/** * Writes a response to the client./* ww w. ja v a 2 s . co m*/ */ protected static void renderMessage(HttpServletResponse response, String message, String contentType) throws IOException { response.addHeader("Cache-Control", "no-cache"); response.setContentType(contentType + "; charset=GB2312"); response.setCharacterEncoding("GB2312"); PrintWriter out = response.getWriter(); out.print(message); System.out.println("=======>" + message); out.flush(); out.close(); }
From source file:cz.muni.fi.pb138.cvmanager.controller.PDFcontroller.java
/** * Http Get request for "/auth/download" * Converts cv from xml format to latex and uploads pdf to users pc * * @param lang language of cv in downloaded pdf * @param response http server response// www. j a va 2s . c om */ @RequestMapping(value = "/auth/download", method = RequestMethod.GET) public void downloadPDF(@RequestParam("l") String lang, HttpServletResponse response) { try { //uncomment the calling of method when login finished pdfGenerator.xmlToLatex(getPrincipalUsername(), lang); InputStream pdf = pdfGenerator.latexToPdf(getPrincipalUsername()); response.setContentType("application/pdf"); FileCopyUtils.copy(pdf, response.getOutputStream()); response.flushBuffer(); } catch (Exception ex) { System.out.print(ex.toString()); try { PrintWriter out = response.getWriter(); out.println("Sorry, generating of CV to PDF failed"); out.close(); } catch (Exception e) { System.out.print("not able to print on web site"); } } }
From source file:TheReplacements.java
public void write(String fileName) throws IOException { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName))); for (int i = 0; i < size(); i++) out.println(get(i));//from w w w. j a v a 2 s . co m out.close(); }
From source file:com.verisignlabs.dnssec.cl.DSTool.java
public void execute() throws Exception { DnsKeyPair key = BINDKeyUtils.loadKey(state.keyname, null); DNSKEYRecord dnskey = key.getDNSKEYRecord(); if ((dnskey.getFlags() & DNSKEYRecord.Flags.SEP_KEY) == 0) { log.warning("DNSKEY is not an SEP-flagged key."); }//from w w w .j a v a 2s . co m DSRecord ds = SignUtils.calculateDSRecord(dnskey, state.digest_id, dnskey.getTTL()); Record res = ds; if (state.createDLV) { log.fine("creating DLV."); DLVRecord dlv = new DLVRecord(ds.getName(), ds.getDClass(), ds.getTTL(), ds.getFootprint(), ds.getAlgorithm(), ds.getDigestID(), ds.getDigest()); res = dlv; } if (state.outputfile != null) { PrintWriter out = new PrintWriter(new FileWriter(state.outputfile)); out.println(res); out.close(); } else { System.out.println(res); } }
From source file:de.undercouch.gradle.tasks.download.SslTest.java
@Override protected Handler[] makeHandlers() throws IOException { ContextHandler sslHandler = new ContextHandler("/" + SSL) { @Override/*from w w w . ja v a2 s .co m*/ public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { response.setStatus(200); PrintWriter rw = response.getWriter(); rw.write("Hello"); rw.close(); } }; return new Handler[] { sslHandler }; }
From source file:TimeServer.java
public void run() { Socket client = null;//from w w w . ja va 2 s. c o m while (true) { if (sock == null) return; try { client = sock.accept(); BufferedOutputStream bos = new BufferedOutputStream(client.getOutputStream()); PrintWriter os = new PrintWriter(bos, false); String outLine; Date now = new Date(); os.println(now); os.flush(); os.close(); client.close(); } catch (IOException e) { System.out.println("Error: couldn't connect to client."); System.exit(1); } } }
From source file:org.sakaiproject.imagegallery.web.MultiFileUploaderController.java
public void multiFileUpload(HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isInfoEnabled()) log.info("req contextPath=" + request.getContextPath() + ", pathInfo=" + request.getPathInfo() + ", query=" + request.getQueryString() + ", URI=" + request.getRequestURI() + ", URL=" + request.getRequestURL() + ", servlet=" + request.getServletPath()); if (request instanceof MultipartHttpServletRequest) { String newImageId = storeNewImage((MultipartHttpServletRequest) request); response.setContentType("text/plain"); PrintWriter responseWriter = response.getWriter(); responseWriter.print(newImageId); responseWriter.close(); }// www . j a v a2s . co m }