Example usage for java.io PrintWriter flush

List of usage examples for java.io PrintWriter flush

Introduction

In this page you can find the example usage for java.io PrintWriter flush.

Prototype

public void flush() 

Source Link

Document

Flushes the stream.

Usage

From source file:ie.wombat.rt.fireeagle.CookieConsumer.java

/**
 * Handle an exception that occurred while processing an HTTP request.
 * Depending on the exception, either send a response, redirect the client
 * or propagate an exception.//from  w  w  w.ja  v  a2s .c  om
 */
public static void handleException(Exception e, HttpServletRequest request, HttpServletResponse response,
        OAuthConsumer consumer) throws IOException, ServletException {
    if (e instanceof RedirectException) {
        RedirectException redirect = (RedirectException) e;
        String targetURL = redirect.getTargetURL();
        if (targetURL != null) {
            response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
            response.setHeader("Location", targetURL);
        }
    } else if (e instanceof OAuthProblemException) {
        OAuthProblemException p = (OAuthProblemException) e;
        String problem = p.getProblem();
        if (consumer != null && RECOVERABLE_PROBLEMS.contains(problem)) {
            try {
                CookieMap cookies = new CookieMap(request, response);
                OAuthAccessor accessor = newAccessor(consumer, cookies);
                getAccessToken(request, cookies, accessor);
                // getAccessToken(request, consumer,
                // new CookieMap(request, response));
            } catch (Exception e2) {
                handleException(e2, request, response, null);
            }
        } else {
            try {
                StringWriter s = new StringWriter();
                PrintWriter pw = new PrintWriter(s);
                e.printStackTrace(pw);
                pw.flush();
                p.setParameter("stack trace", s.toString());
            } catch (Exception rats) {
            }
            response.setStatus(p.getHttpStatusCode());
            response.resetBuffer();
            request.setAttribute("OAuthProblemException", p);
            request.getRequestDispatcher //
            ("/OAuthProblemException.jsp").forward(request, response);
        }
    } else if (e instanceof IOException) {
        throw (IOException) e;
    } else if (e instanceof ServletException) {
        throw (ServletException) e;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
    } else {
        throw new ServletException(e);
    }
}

From source file:io.github.azige.whitespace.Cli.java

static void printHelp(PrintStream out, Options options) {
    HelpFormatter hf = new HelpFormatter();
    PrintWriter pw = new PrintWriter(out);
    hf.printHelp(pw, hf.getWidth(), "whitespace [-c|-p] <source file>",
            "Whitespace??", options, hf.getLeftPadding(),
            hf.getDescPadding(), null);/*from  w  ww.  jav a 2 s. c om*/
    pw.flush();
}

From source file:com.yuga.common.web.Servlets.java

public static void print(HttpServletResponse resp, String msg) {
    PrintWriter pw;
    try {/*from w  w w .j a va  2 s. c  om*/
        pw = resp.getWriter();
        pw.write(msg);
        pw.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.momab.dstool.DSTool.java

static void printHelp(Options options, OutputStream out) {
    PrintWriter writer = new PrintWriter(out);
    writer.println(String.format("%s version %s, Copyright Jonas Andreasson under the MIT license.", TOOLNAME,
            getVersionString()));/*from  w  w w. j a v a  2  s  . co  m*/
    writer.println();
    writer.flush();
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(CMDLINE_SYNTAX, options, true);
    writer.flush();
}

From source file:Main.java

public static void response(OutputStream output, String contentType, String description, String responseText) {
    Log.d(">>>NativeH5",
            " xhr response return start time:" + System.currentTimeMillis() + " responseText:" + responseText);

    PrintWriter pw = new PrintWriter(output);
    pw.println("HTTP/1.1 " + description);
    pw.println("Content-Type: " + contentType);
    pw.println("Date: " + new Date());
    pw.println("Access-Control-Allow-Origin: *");
    pw.println("Content-Length: " + responseText.length());
    pw.println();/*  w  ww .ja va2 s  .c  om*/
    pw.println(responseText);
    pw.flush();
    try {
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.zimbra.cs.account.ldap.upgrade.LdapUpgrade.java

static void usage(ParseException e, UpgradeOp upgradeOp, String errMsg) {

    if (e != null) {
        printer.println("Error parsing command line arguments: " + e.getMessage());
    }//from  w w w .j  a  v  a2 s .  co m

    if (errMsg != null) {
        printer.println(errMsg);
        printer.println();
    }

    Options opts = getAllOptions();
    PrintWriter pw = printer.getPrintWriter();
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, formatter.getWidth(), getCommandUsage(), null, opts, formatter.getLeftPadding(),
            formatter.getDescPadding(), null);

    pw.flush();
    if (upgradeOp != null) {
        upgradeOp.usage(formatter);
    }
}

From source file:de.hasait.genesis.base.util.GenesisUtils.java

public static void printStackTrace(final Messager pMessager, final Element pElement, final Throwable pThrowable,
        final String pFormat, final Object... pArgs) {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    final String message = String.format(pFormat, pArgs);
    pw.println(message);//from w  ww  .  j a  v a  2  s  . c  o m
    pThrowable.printStackTrace(pw);
    pw.flush();
    pMessager.printMessage(Diagnostic.Kind.ERROR, sw.toString(), pElement);
}

From source file:cc.redpen.Main.java

private static void printHelp(Options opt) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(100);//  w  w  w .ja  v a  2s. c  om
    PrintWriter pw = new PrintWriter(System.err);
    formatter.printHelp(pw, 80, PROGRAM + " [Options] [<INPUT FILE>]", HELP_HEADER, opt, 1, 3, HELP_FOOTER);
    pw.flush();
}

From source file:Main.java

private static void printStackTrace(PrintWriter writer, Thread thread, StackTraceElement[] trace) {
    try {//from   www.ja  va 2s .  co m
        writer.println(thread.toString() + ":");
        for (int i = 0; i < trace.length; i++)
            writer.println("\tat " + trace[i]);
    } catch (Exception e) {
        writer.println("\t*** Exception printing stack trace: " + e);
    }
    writer.flush();
}

From source file:IORoutines.java

public static void saveStrings(File file, java.util.Collection list) throws IOException {
    BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(file));
    try {//from   ww  w .  j av  a 2  s . c o m
        PrintWriter writer = new PrintWriter(bout);
        java.util.Iterator i = list.iterator();
        while (i.hasNext()) {
            String text = (String) i.next();
            writer.println(text);
        }
        writer.flush();
    } finally {
        bout.close();
    }
}