List of usage examples for java.io PrintWriter flush
public void flush()
From source file:com.zimbra.cs.service.authenticator.CertUtil.java
private static void usage(Options options) { System.out.println("\n"); PrintWriter pw = new PrintWriter(System.out, true); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(pw, formatter.getWidth(), "zmjava " + CertUtil.class.getCanonicalName() + " [options]", null, options, formatter.getLeftPadding(), formatter.getDescPadding(), null); System.out.println("\n"); pw.flush(); }
From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java
public static void writeAsSOMLib(InputData data, String fileName) throws IOException { PrintWriter writer = FileUtils.openFileForWriting("Input vector file", fileName, true); InputDataWriter.writeHeaderToFile(writer, data.numVectors(), data.dim()); for (int i = 0; i < data.numVectors(); i++) { InputDatum inputDatum = data.getInputDatum(i); InputDataWriter.writeInputDatumToFile(writer, inputDatum); }//from www. j a v a 2 s .c om writer.flush(); writer.close(); }
From source file:ai.grakn.graql.GraqlShell.java
private static void printUsage(Options options, String footer) { HelpFormatter helpFormatter = new HelpFormatter(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(System.out, Charset.defaultCharset()); PrintWriter printWriter = new PrintWriter(new BufferedWriter(outputStreamWriter)); int width = helpFormatter.getWidth(); int leftPadding = helpFormatter.getLeftPadding(); int descPadding = helpFormatter.getDescPadding(); helpFormatter.printHelp(printWriter, width, "graql.sh", null, options, leftPadding, descPadding, footer); printWriter.flush(); }
From source file:com.caved_in.commons.utilities.StringUtil.java
public static String getStackStr(Throwable err) { if (err == null) {// || err.getCause() == null) { return ""; }//ww w. j a va2s .co m StringUtil stackoutstream = new StringUtil(); PrintWriter stackstream = new PrintWriter(stackoutstream); err.printStackTrace(stackstream); stackstream.flush(); stackstream.close(); return stackoutstream.text.toString(); }
From source file:dictinsight.utils.io.HttpUtils.java
public static String getDataFromOtherServer(String url, String param) { PrintWriter out = null; BufferedReader in = null;/* ww w. ja va2s .co m*/ String result = ""; try { URL realUrl = new URL(url); URLConnection conn = realUrl.openConnection(); conn.setConnectTimeout(1000 * 10); conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); conn.setDoOutput(true); conn.setDoInput(true); out = new PrintWriter(conn.getOutputStream()); out.print(param); out.flush(); in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("get date from " + url + param + " error!"); e.printStackTrace(); } // finally????? finally { try { if (out != null) { out.close(); } if (in != null) { in.close(); } } catch (IOException ex) { ex.printStackTrace(); } } return result; }
From source file:com.dien.upload.server.UploadServlet.java
/** * Writes a response to the client.//from w ww . j a v a 2 s . c om */ protected static void renderMessage(HttpServletResponse response, String message, String contentType) throws IOException { response.setContentType(contentType + "; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(message); out.flush(); out.close(); }
From source file:com.dien.upload.server.UploadServlet.java
protected static void renderJSONResponse(HttpServletRequest request, HttpServletResponse response, String message) throws IOException { //json????/*from w w w . j ava 2s . c om*/ response.setContentType("text/html;charset=utf-8"); PrintWriter out; try { out = response.getWriter(); out.write(message); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:it.greenvulcano.util.txt.TextUtils.java
/** * Writes a text String into a file//from w w w.ja va 2 s .co m * * @param contentString * The String to be written into the file * @param file * The destination file * @param append * If true the data are appended to existent file * @throws IOException */ public static void writeFile(String contentString, File file, boolean append) throws IOException { PrintWriter out = null; try { out = new PrintWriter(new FileWriter(file, append)); out.print(contentString); out.flush(); } finally { if (out != null) { out.close(); } } }
From source file:com.jsmartframework.web.manager.WebContext.java
/** * Write response directly as String. Note that by using this method the response * as HTML will not be generated and the response will be what you have defined. * * @param response String to write in the response. * @throws IOException/*from w w w . j av a 2s.c o m*/ */ public static void writeResponseAsString(String response) throws IOException { WebContext context = getCurrentInstance(); if (context != null) { context.responseWritten = true; PrintWriter writer = context.response.getWriter(); writer.write(response); writer.flush(); } }
From source file:it.greenvulcano.util.txt.TextUtils.java
/** * Writes a text String into a file// ww w .java2 s . co m * * @param contentString * The StringBuffer to be written into the file * @param file * The destination file * @param append * If true the data are appended to existent file * @throws IOException */ @SuppressWarnings("deprecation") public static void writeFile(StringBuffer contentString, File file, boolean append) throws IOException { PrintWriter out = null; try { out = new PrintWriter(new FileWriter(file, append)); IOUtils.write(contentString, out); out.flush(); } finally { if (out != null) { out.close(); } } }