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:com.alibaba.webx.tutorial.app1.module.screen.simple.Download.java

public void execute(@Param("filename") String filename) throws Exception {
    // buffering????
    brc.setBuffering(false);/*from w ww.ja va2  s  .c o m*/

    // headers?????us-ascii????
    filename = defaultIfNull(trimToNull(filename), "image") + ".txt";
    filename = "\"" + escapeURL(filename) + "\"";

    response.setHeader("Content-disposition", "attachment; filename=" + filename);

    // ??content type?
    // HTML?JSON?JavaScript?JPG?PDF?EXCEL
    response.setContentType("text/plain");

    PrintWriter out = response.getWriter();

    for (int i = 0; i < 100; i++) {
        out.flush(); // ???

        for (int j = 0; j < 100000; j++) {
            out.print(i);
        }

        out.println();

        Thread.sleep(100); // ??
    }
}

From source file:com.taobao.lottery.web.app1.module.screen.simple.Download.java

public void execute(@Param("filename") String filename) throws Exception {
    // ,buffering,?,???
    brc.setBuffering(false);//  w ww  .  j  a v  a2 s .c  o  m

    // headers,?????us-ascii,????
    filename = defaultIfNull(trimToNull(filename), "image") + ".txt";
    filename = "\"" + escapeURL(filename) + "\"";

    response.setHeader("Content-disposition", "attachment; filename=" + filename);

    // ??content type,?
    // HTML?JSON?JavaScript?JPG?PDF?EXCEL
    response.setContentType("text/plain");

    PrintWriter out = response.getWriter();

    for (int i = 0; i < 100; i++) {
        out.flush(); // ???

        for (int j = 0; j < 100000; j++) {
            out.print(i);
        }

        out.println();

        Thread.sleep(100); // ?,?
    }
}

From source file:groovy.ui.InteractiveShell.java

/**
 * Process cli args when the shell is invoked via main().
 *
 * @noinspection AccessStaticViaInstance
 *///from   ww  w .  j  a  v  a2 s .c om
private static void processCommandLineArguments(final String[] args) throws Exception {
    assert args != null;

    //
    // TODO: Let this take a single, optional argument which is a file or URL to run?
    //

    Options options = new Options();

    options.addOption(OptionBuilder.withLongOpt("help")
            .withDescription(MESSAGES.getMessage("cli.option.help.description")).create('h'));

    options.addOption(OptionBuilder.withLongOpt("version")
            .withDescription(MESSAGES.getMessage("cli.option.version.description")).create('V'));

    //
    // TODO: Add more options, maybe even add an option to prime the buffer from a URL or File?
    //

    //
    // FIXME: This does not currently barf on unsupported options short options, though it does for long ones.
    //        Same problem with commons-cli 1.0 and 1.1
    //

    CommandLineParser parser = new PosixParser();
    CommandLine line = parser.parse(options, args, true);
    String[] lineargs = line.getArgs();

    // Puke if there were arguments, we don't support any right now
    if (lineargs.length != 0) {
        System.err.println(MESSAGES.format("cli.info.unexpected_args",
                new Object[] { DefaultGroovyMethods.join(lineargs, " ") }));
        System.exit(1);
    }

    PrintWriter writer = new PrintWriter(System.out);

    if (line.hasOption('h')) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(writer, 80, // width
                "groovysh [options]", "", options, 4, // left pad
                4, // desc pad
                "", false); // auto usage

        writer.flush();
        System.exit(0);
    }

    if (line.hasOption('V')) {
        writer.println(MESSAGES.format("cli.info.version", new Object[] { InvokerHelper.getVersion() }));
        writer.flush();
        System.exit(0);
    }
}

From source file:com.att.api.immn.controller.GetMsgController.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final HttpSession session = request.getSession();
    OAuthToken token = (OAuthToken) session.getAttribute("token");
    IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token);
    final String msgId = request.getParameter("getMsgId");

    /* TODO: convert nulls to the '-' character */
    JSONObject jresponse = new JSONObject();
    try {//from   w w  w.  j av a  2  s .c o m
        final Message msg = srvc.getMessage(msgId);
        final JSONArray tables = new JSONArray();
        final JSONArray values = new JSONArray().put(msg.getMessageId()).put(msg.getFrom())
                .put(msg.getRecipients()).put(msg.getText()).put(msg.getTimeStamp()).put(msg.isFavorite())
                .put(msg.isUnread()).put(msg.isIncoming()).put(msg.getType());
        tables.put(new JSONObject().put("caption", "Message:")
                .put("headers",
                        new JSONArray().put("Message ID").put("From").put("Recipients").put("Text")
                                .put("Timestamp").put("Favorite").put("Unread").put("Incoming").put("Type"))
                .put("values", new JSONArray().put(values)));
        jresponse.put("success", true).put("tables", tables);
    } catch (RESTException re) {
        jresponse.put("success", false).put("text", re.getMessage());
    }

    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.print(jresponse);
    writer.flush();
}

From source file:com.alibaba.webx.study.app1.module.screen.simple.Download.java

public void execute(@Param("filename") String filename) throws Exception {
    // buffering????
    brc.setBuffering(false);//from  w  w w . j  a v a 2  s.  c  om
    response.reset();

    // headers?????us-ascii????
    filename = defaultIfNull(trimToNull(filename), "image") + ".txt";
    filename = "\"" + escapeURL(filename) + "\"";

    response.setHeader("Content-disposition", "attachment; filename=" + filename);

    // ??content type?
    // HTML?JSON?JavaScript?JPG?PDF?EXCEL
    response.setContentType("text/plain");

    PrintWriter out = response.getWriter();

    for (int i = 0; i < 100; i++) {
        out.flush(); // ???

        for (int j = 0; j < 100000; j++) {
            out.print(i);
        }

        out.println();

        Thread.sleep(100); // ??
    }
}

From source file:com.rovemonteux.tormessenger.network.NetworkClient.java

public void write(String message) throws IOException {
    PrintWriter out = new PrintWriter(netSocket.getOutputStream(), true);
    out.println(message);/*  ww  w.ja va 2  s  .c om*/
    out.flush();
}

From source file:com.att.api.immn.controller.UpdateMsgController.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final HttpSession session = request.getSession();
    OAuthToken token = (OAuthToken) session.getAttribute("token");
    final String readflag = request.getParameter("updateStatus");
    final String msgIdStr = request.getParameter("updateMsgId");
    String[] msgIds = msgIdStr.split(",");
    final Boolean isUnread = readflag.equals("Read") ? false : true;
    IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token);
    JSONObject jresponse = new JSONObject();
    try {/*from www  .j a va2  s.  c o m*/
        if (msgIds.length > 1) {
            DeltaChange[] changes = new DeltaChange[msgIds.length];
            for (int i = 0; i < msgIds.length; ++i) {
                DeltaChange dc = new DeltaChange(msgIds[i], null, isUnread);
                changes[i] = dc;
            }
            srvc.updateMessages(changes);
        } else {
            srvc.updateMessage(msgIds[0], isUnread, null);
        }
        jresponse.put("success", true).put("text", "Message(s) Updated");
    } catch (RESTException re) {
        jresponse.put("success", false).put("text", re.getMessage());
    }

    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.print(jresponse);
    writer.flush();
}

From source file:$.Download.java

public void execute(@Param("filename") String filename) throws Exception {
        // buffering????
        brc.setBuffering(false);/* w ww.j a  va  2 s .  co  m*/

        // headers?????us-ascii????
        filename = defaultIfNull(trimToNull(filename), "image") + ".txt";
        filename = "\"" + escapeURL(filename) + "\"";

        response.setHeader("Content-disposition", "attachment; filename=" + filename);

        // ??content type?
        // HTML?JSON?JavaScript?JPG?PDF?EXCEL
        response.setContentType("text/plain");

        PrintWriter out = response.getWriter();

        for (int i = 0; i < 100; i++) {
            out.flush(); // ???

            for (int j = 0; j < 100000; j++) {
                out.print(i);
            }

            out.println();

            Thread.sleep(100); // ??
        }
    }

From source file:com.bitranger.parknshop.seller.controller.SellerManageItemCtrl.java

@RequestMapping(value = "/seller/deleteItem", method = RequestMethod.GET)
public void delete(HttpServletRequest request, HttpServletResponse response) throws IOException {

    String itemId = request.getParameter("id");

    psItemDAO.delete(psItemDAO.findById(Integer.parseInt(itemId)));

    PrintWriter out = response.getWriter();
    out.write("success");
    out.flush();
    out.close();// w ww .  j a  v a 2 s .com

}

From source file:com.att.api.immn.controller.GetSubscriptionController.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final HttpSession session = request.getSession();
    JSONObject jresponse = new JSONObject();
    try {//from   w w  w . j  a  v  a  2 s. co  m
        if (session.getAttribute("subscriptionId") == null) {
            throw new RESTException("You must first create a subscription.");
        }
        final OAuthToken token = (OAuthToken) session.getAttribute("token");
        final String channelId = appConfig.getProperty("channelId");
        final String subscriptionId = (String) session.getAttribute("subscriptionId");
        final String fqdn = appConfig.getApiFQDN();
        final WebhooksService srvc = new WebhooksService(fqdn, token);
        GetSubscriptionResponse getResponse = srvc.getNotificationSubscriptionDetails(channelId,
                subscriptionId);
        JSONArray jheaders = new JSONArray().put("Subscription Id").put("Expires In").put("Queues")
                .put("Callback Data");
        JSONArray jvalues = new JSONArray().put(getResponse.getSubscription().getSubscriptionId())
                .put(getResponse.getSubscription().getExpiresIn())
                .put(getResponse.getSubscription().getEvents())
                .put(getResponse.getSubscription().getCallbackData());
        JSONObject jtable = new JSONObject().put("caption", "Subscription Details").put("headers", jheaders)
                .put("values", new JSONArray().put(jvalues));
        JSONArray jtables = new JSONArray().put(jtable);
        jresponse.put("success", true).put("tables", jtables);
    } catch (RESTException re) {
        jresponse.put("success", false).put("text", re.getMessage());
    }

    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.print(jresponse);
    writer.flush();
}