List of usage examples for java.io PrintWriter flush
public void flush()
From source file:gov.nih.nci.caintegrator.application.util.CSVUtil.java
public static void renderCSV(HttpServletResponse response, List<List> csv) { PrintWriter out = null; long randomness = System.currentTimeMillis(); response.setContentType("application/csv"); response.setHeader("Content-Disposition", "attachment; filename=report_" + randomness + ".csv"); try {// w ww . j a v a 2s . c o m for (List row : csv) { out = response.getWriter(); out.write(StringUtils.join(row.toArray(), ",") + "\r\n"); out.flush(); } } catch (Exception e) { out.write("error generating report"); } }
From source file:org.jodconverter.cli.Convert.java
private static void printErr(final String message, final Object... values) { final PrintWriter writer = new PrintWriter(System.err); // NOSONAR writer.println(String.format(message, values)); writer.flush(); }
From source file:org.jodconverter.cli.Convert.java
private static void printInfo(final String message, final Object... values) { final PrintWriter writer = new PrintWriter(System.out); // NOSONAR writer.println(String.format(message, values)); writer.flush(); }
From source file:jenkins.plugins.coverity.CoverityUtils.java
/** * Gets the stacktrace from an exception, so that this exception can be handled. *//* w w w .j a v a 2 s .c o m*/ public static String getStackTrace(Exception e) { StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); e.printStackTrace(printWriter); printWriter.flush(); String stackTrace = writer.toString(); try { writer.close(); printWriter.close(); } catch (IOException e1) { } return stackTrace; }
From source file:com.google.gsa.valve.modules.utils.HTTPAuthZProcessor.java
/** * If the document is HTML, this method processes its content in order to * rewrite the URLs it includes/*from w w w .j a v a 2s. co m*/ * * @param response HTTP response * @param method HTTP method * @param url document url * @param loginUrl login url * @param contenType content Type * * @throws IOException * @throws ParserException */ public static void processHTML(HttpServletResponse response, HttpMethodBase method, String url, String loginUrl, String contentType) throws IOException, ParserException { logger.debug("Processing an HTML document"); String stream = null; Parser parser = null; NodeVisitor visitor = null; // Retrieve HTML stream stream = readFully(new InputStreamReader(method.getResponseBodyAsStream())); // Protection if (stream != null) { logger.debug("Stream content size: " + stream.length()); // Parse HTML stream to replace any links to include the path to the valve parser = Parser.createParser(stream, null); // Instantiate visitor visitor = new HTTPVisitor(url, loginUrl); // Parse nodes parser.visitAllNodesWith(visitor); // Get writer PrintWriter out = response.getWriter(); // Push HTML content if (out != null) { out.flush(); out.print(((HTTPVisitor) visitor).getModifiedHTML()); out.close(); logger.debug("Wrote: " + ((HTTPVisitor) visitor).getModifiedHTML().length()); } response.setHeader("Content-Type", contentType); // Garbagge collect stream = null; parser = null; visitor = null; } }
From source file:mobile.tiis.appv2.helpers.Utils.java
public static void writeNetworkLogFileOnSD(String sBody) { try {//from w ww . j av a 2 s . co m File root = new File(Environment.getExternalStorageDirectory(), "TIIS"); if (!root.exists()) { root.mkdirs(); } File gpxfile = new File(root, "network_log_file.txt"); PrintWriter fileStream = new PrintWriter(new FileOutputStream(gpxfile, true)); fileStream.append(System.getProperty("line.separator")); fileStream.append(sBody); fileStream.flush(); fileStream.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.discovery.darchrow.http.ResponseUtil.java
/** * ./*w w w . j av a2 s . c o m*/ * * @param response * HttpServletResponse * @param content * * @param contentType * the content type * @param characterEncoding * the character encoding * @throws UncheckedIOException * the unchecked io exception * @see javax.servlet.ServletResponse#getWriter() * @see java.io.PrintWriter#print(Object) * @see java.io.PrintWriter#flush() * @since 1.0.9 */ public static void write(HttpServletResponse response, Object content, String contentType, String characterEncoding) throws UncheckedIOException { try { //? ? getWriter? if (Validator.isNotNullOrEmpty(contentType)) { response.setContentType(contentType); } if (Validator.isNotNullOrEmpty(characterEncoding)) { response.setCharacterEncoding(characterEncoding); } PrintWriter printWriter = response.getWriter(); printWriter.print(content); printWriter.flush(); //http://www.iteye.com/problems/56543 //tomcatjetty?? printWriter.close(); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:boa.BoaMain.java
protected static final void printHelp(final Options options, final String message) { if (message != null) System.err.println(message); final HelpFormatter help = new HelpFormatter(); final PrintWriter pw = new PrintWriter(System.out); help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, "The available options are:"); help.printOptions(pw, HelpFormatter.DEFAULT_WIDTH, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD); help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, "\nPlease report issues at http://www.github.com/boalang/compiler"); pw.flush(); }
From source file:edu.gmu.csiss.automation.pacs.utils.BaseTool.java
/** * send a HTTP POST request//from www .j a v a 2 s .c o m * @param param * @param input_url * @return */ public static String POST(String param, String input_url) { try { URL url = new URL(input_url); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setDoOutput(true); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/xml"); con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); PrintWriter xmlOut = new PrintWriter(con.getOutputStream()); xmlOut.write(param); xmlOut.flush(); BufferedReader response = new BufferedReader(new InputStreamReader(con.getInputStream())); String result = ""; String line; while ((line = response.readLine()) != null) { result += "\n" + line; } return result.toString(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:org.openiot.gsn.utils.GSNMonitor.java
public static String getStackTrace(Throwable t) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter, true); t.printStackTrace(printWriter);/*from w w w . j a v a 2 s. c om*/ printWriter.flush(); stringWriter.flush(); return stringWriter.toString(); }