List of usage examples for java.io PrintWriter flush
public void flush()
From source file:com.zimbra.cs.redolog.util.PlaybackUtil.java
private static void usage(String errmsg) { if (errmsg != null) { System.err.println(errmsg); }/*www.j av a 2 s . c o m*/ String usage = "zmplayredo <options>"; Options opts = sOptions; PrintWriter pw = new PrintWriter(System.err, true); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(pw, formatter.getWidth(), usage, null, opts, formatter.getLeftPadding(), formatter.getDescPadding(), null); pw.flush(); String trailer = SoapCLI.getAllowedDatetimeFormatsHelp(); if (trailer != null && trailer.length() > 0) { System.err.println(); System.err.println(trailer); } }
From source file:com.curecomp.primefaces.migrator.PrimefacesMigration.java
private static void printHelp() { final PrintWriter writer = new PrintWriter(System.out); final HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printHelp(writer, 80, "PrimefacesMigration", "Migrates files from Primefaces version 4 to 5", OPTIONS, 10, 10, "curecomp.com"); writer.flush(); System.exit(0);//from w w w. j a v a 2 s.c o m }
From source file:Main.java
public static String post(String url, Map<String, String> params) { try {//w ww . j a v a 2s . co m URL u = new URL(url); HttpURLConnection connection = (HttpURLConnection) u.openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); PrintWriter pw = new PrintWriter(connection.getOutputStream()); StringBuilder sbParams = new StringBuilder(); if (params != null) { for (String key : params.keySet()) { sbParams.append(key + "=" + params.get(key) + "&"); } } if (sbParams.length() > 0) { String strParams = sbParams.substring(0, sbParams.length() - 1); Log.e("cat", "strParams:" + strParams); pw.write(strParams); pw.flush(); pw.close(); } BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuffer response = new StringBuffer(); String readLine = ""; while ((readLine = br.readLine()) != null) { response.append(readLine); } br.close(); return response.toString(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:disko.DU.java
/** * <p>/*from w w w. ja v a 2 s . c om*/ * Print the full stack trace of a <code>Throwable</code> object into a * string buffer and return the corresponding string. * </p> */ public static String printStackTrace(Throwable t) { if (t == null) return null; java.io.StringWriter strWriter = new java.io.StringWriter(); java.io.PrintWriter prWriter = new PrintWriter(strWriter); t.printStackTrace(prWriter); prWriter.flush(); return strWriter.toString(); }
From source file:com.linecorp.armeria.server.ServerTest.java
private static void testSimple(String reqLine, String expectedStatusLine, String... expectedHeaders) throws Exception { try (Socket socket = new Socket()) { socket.setSoTimeout((int) (idleTimeoutMillis * 4)); socket.connect(server().activePort().get().localAddress()); PrintWriter outWriter = new PrintWriter(socket.getOutputStream(), false); outWriter.print(reqLine);/*from w w w . j a v a 2 s . c o m*/ outWriter.print("\r\n"); outWriter.print("Connection: close\r\n"); outWriter.print("Content-Length: 0\r\n"); outWriter.print("\r\n"); outWriter.flush(); BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream(), StandardCharsets.US_ASCII)); assertThat(in.readLine(), is(expectedStatusLine)); // Read till the end of the connection. List<String> headers = new ArrayList<>(); for (;;) { String line = in.readLine(); if (line == null) { break; } // This is not really correct, but just wanna make it as simple as possible. headers.add(line); } for (String expectedHeader : expectedHeaders) { if (!headers.contains(expectedHeader)) { fail("does not contain '" + expectedHeader + "': " + headers); } } } }
From source file:com.act.lcms.v2.fullindex.Searcher.java
private static void writeOutput(PrintWriter writer, List<TMzI> results) throws IOException { int counter = 0; writer.println(OUTPUT_HEADER);//ww w . j a v a 2 s . c om for (TMzI triple : results) { writer.format("%d\t%.6f\t%.6f\t%.6f\n", counter, triple.getTime(), triple.getMz(), triple.getIntensity()); counter++; } writer.flush(); }
From source file:cn.vlabs.umt.ui.servlet.AddClientServlet.java
public static void writeJSONObject(HttpServletResponse response, Object object) { PrintWriter writer = null; try {//from ww w .ja va2 s . c om //IE???text/html? response.setContentType("text/html"); writer = response.getWriter(); writer.write(object.toString()); } catch (IOException e) { } finally { if (writer != null) { writer.flush(); writer.close(); } } }
From source file:net.erdfelt.android.sdkfido.project.FilteredFileUtil.java
public static String loadExpandedAsString(String resourceId, Map<String, String> props) throws OutputProjectException { LOG.log(Level.INFO, "Loading resource: " + resourceId); if (StringUtils.isBlank(resourceId)) { throw new IllegalArgumentException("resourceId cannot be blank"); }/* www . j ava 2 s .com*/ URL url = FilteredFileUtil.class.getResource(resourceId); if (url == null) { throw new OutputProjectException("Unable to find resourceID: " + resourceId); } InputStream in = null; InputStreamReader reader = null; BufferedReader buf = null; StringWriter writer = null; PrintWriter out = null; try { in = url.openStream(); reader = new InputStreamReader(in); buf = new BufferedReader(reader); writer = new StringWriter(); out = new PrintWriter(writer); PropertyExpander expander = new PropertyExpander(props); String line; while ((line = buf.readLine()) != null) { out.println(expander.expand(line)); } out.flush(); writer.flush(); return writer.toString(); } catch (IOException e) { throw new OutputProjectException("Unable to open input stream for url: " + url, e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(writer); IOUtils.closeQuietly(buf); IOUtils.closeQuietly(reader); IOUtils.closeQuietly(in); } }
From source file:com.glaf.core.util.IOUtils.java
/** * write lines./*from w w w.ja v a 2s . co m*/ * * @param os * output stream. * @param lines * lines. * @throws IOException */ public static void writeLines(OutputStream os, String[] lines) throws IOException { PrintWriter writer = new PrintWriter(new OutputStreamWriter(os)); try { for (String line : lines) writer.println(line); writer.flush(); } finally { writer.close(); } }
From source file:com.spotify.heroic.HeroicShell.java
static void standalone(List<String> arguments, Builder builder) throws Exception { final String taskName = arguments.iterator().next(); final List<String> rest = arguments.subList(1, arguments.size()); log.info("Running standalone task {}", taskName); final HeroicCore core = builder.build(); log.info("Starting Heroic..."); final HeroicCoreInstance instance = core.newInstance(); instance.start().get();//from ww w. j av a 2 s . c om final ShellTask task = instance.inject(c -> c.tasks().resolve(taskName)); final TaskParameters params = task.params(); final CmdLineParser parser = setupParser(params); try { parser.parseArgument(rest); } catch (CmdLineException e) { log.error("Error parsing arguments", e); System.exit(1); return; } if (params.help()) { parser.printUsage(System.err); HeroicModules.printAllUsage(System.err, "-P"); System.exit(0); return; } try { final PrintWriter o = standaloneOutput(params, System.out); final ShellIO io = new DirectShellIO(o); try { task.run(io, params).get(); } catch (Exception e) { log.error("Failed to run task", e); } finally { o.flush(); } } finally { instance.shutdown().get(); } }