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:tomekkup.helenos.security.web.authentication.AbstractJsonAuthenticationHandler.java

protected final void writeResult(HttpServletResponse response, Authentication authentication)
        throws IOException {
    response.setHeader("Content-Type", "application/json");
    PrintWriter writer = response.getWriter();
    objectMapper.writeValue(writer, (authentication != null ? authentication.getAuthorities() : null));
    writer.flush();
}

From source file:com.googlecode.android_scripting.jsonrpc.JsonRpcServer.java

private void send(PrintWriter writer, JSONObject result) {
    writer.write(result + "\n");
    writer.flush();
    Log.v("Sent: " + result);
}

From source file:com.openedit.OpenEditException.java

/**
 * DOCUMENT ME!// ww w .ja  va  2s.com
 *
 * @return
 */
public String toStackTrace() {
    StringWriter out = new StringWriter();
    PrintWriter writer = new PrintWriter(out);
    printStackTrace(writer);
    writer.flush();

    return out.toString();
}

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

@RequestMapping(value = "/seller/addAd", method = RequestMethod.POST)
public void getItems(HttpServletRequest request, HttpServletResponse response)
        throws ParseException, IOException {

    String name = request.getParameter("adName");
    String itemId = request.getParameter("itemId");
    String startDate = request.getParameter("start");
    String endDate = request.getParameter("end");
    String weight = request.getParameter("weight");
    String description = request.getParameter("description");
    String picUrl = request.getParameter("pic-url");

    System.out.println(/*from w ww .  j ava2  s .c  om*/
            name + ": " + itemId + ";" + startDate + ";" + endDate + "; " + weight + ";" + description);

    PsItem $ = psItemDao.findById(Integer.parseInt(itemId));
    SimpleDateFormat FMT = new SimpleDateFormat("yyyy-MM-dd");

    PsPromotItem pi = new PsPromotItem();
    pi.setPsItem($);
    pi.setDescription(description);
    pi.setTimeCreated(new Timestamp(System.currentTimeMillis()));
    pi.setPicUrl(picUrl);
    psPromotItemDAO.save(pi);

    PsAdItem ad = new PsAdItem();
    ad.setIdPromot(pi.getId());
    ad.setTimeStart(new Timestamp(FMT.parse(startDate).getTime()));
    ad.setTimeEnd(new Timestamp(FMT.parse(endDate).getTime()));
    ad.setWeight(Double.parseDouble(weight));

    psAdItemDAO.save(ad);

    PrintWriter out = response.getWriter();
    out.write("success");
    out.flush();
    out.close();
}

From source file:cn.vlabs.umt.ui.servlet.PublicKeyServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String keyString = request.getParameter("keyid");
    if (keyString == null) {
        wrongParameter(response);//from  www.j  a  v a  2 s  .  c  om
        return;
    }
    try {
        AppService service = (AppService) factory.getBean("ApplicationService");
        int keyid = -1;
        String content;
        if ("umt".equals(keyString)) {
            Application app = service.getApplication("umt");
            keyid = app.getKeyid();
            content = app.getPublicKey();
        } else {
            keyid = Integer.parseInt(keyString);
            content = service.getPublicKey(keyid);
        }
        if (content != null) {
            response.setContentType("text/plain");
            response.setHeader("keyid", Integer.toString(keyid));
            PrintWriter out = response.getWriter();
            out.write(content);
            out.flush();
            out.close();
        } else {
            notFound(response);
        }
    } catch (NumberFormatException e) {
        wrongParameter(response);
        return;
    }
}

From source file:clientpaxos.ClientPaxos.java

public static void sendToServer(String msg) throws Exception {
    //create output stream attached to socket
    PrintWriter outToServer = new PrintWriter(new OutputStreamWriter(tcpSocket.getOutputStream()));
    //send msg to server
    outToServer.print(msg + '\n');
    outToServer.flush();
}

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

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

    final HttpSession session = request.getSession();
    final List<String> events = new LinkedList<String>();
    JSONObject jresponse = new JSONObject();
    try {//from   ww w. jav a  2 s  .  c om
        if (session.getAttribute("subscriptionId") != null) {
            throw new RESTException("You must first delete your existing subscription.");
        }
        if (request.getParameter("subscriptionText") != null) {
            events.add("TEXT");
        }
        if (request.getParameter("subscriptionMms") != null) {
            events.add("MMS");
        }
        if (events.size() == 0) {
            throw new RESTException("You must select at least one of Text or MMS.");
        }
        final OAuthToken token = (OAuthToken) session.getAttribute("token");
        final String fqdn = appConfig.getApiFQDN();
        final WebhooksService srvc = new WebhooksService(fqdn, token);
        final String channelId = appConfig.getProperty("channelId");
        final Integer expiresIn = Integer.valueOf(appConfig.getProperty("expiresIn"));
        final String callbackData = request.getParameter("callbackData");
        final CreateSubscriptionArgs args = new CreateSubscriptionArgs(channelId,
                events.toArray(new String[events.size()]), callbackData, expiresIn);
        final CreateSubscriptionResponse createResponse = srvc.createNotificationSubscription(args);
        session.setAttribute("subscriptionId", createResponse.getSubscription().getSubscriptionId());
        session.setAttribute("subscriptionExpiry",
                DateUtil.xtimestamp() + createResponse.getSubscription().getExpiresIn());
        jresponse.put("success", true).put("text", "Subscription created.");
    } 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.att.api.immn.controller.GetDeltaController.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 msgState = request.getParameter("msgState");

    JSONObject jresponse = new JSONObject();
    try {//  w  ww  .  ja  v a  2  s  .  c o m
        final DeltaResponse deltaResponse = srvc.getDelta(msgState);
        final JSONArray tables = new JSONArray();
        for (final Delta delta : deltaResponse.getDeltas()) {
            final JSONArray values = new JSONArray();
            for (final DeltaChange dc : delta.getAdds()) {
                values.put(new JSONArray().put("Add").put(dc.getMessageId()).put(dc.isFavorite())
                        .put(dc.isUnread()));
            }
            for (final DeltaChange dc : delta.getDeletes()) {
                values.put(new JSONArray().put("Delete").put(dc.getMessageId()).put(dc.isFavorite())
                        .put(dc.isUnread()));
            }
            for (final DeltaChange dc : delta.getUpdates()) {
                values.put(new JSONArray().put("Update").put(dc.getMessageId()).put(dc.isFavorite())
                        .put(dc.isUnread()));
            }
            tables.put(new JSONObject()
                    .put("caption", "Delta Type: " + delta.getType()).put("headers", new JSONArray()
                            .put("Delta Operation").put("MessageId").put("Favorite").put("Unread"))
                    .put("values", 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.att.api.immn.controller.UpdateSubscriptionController.java

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

    final HttpSession session = request.getSession();
    final List<String> events = new LinkedList<String>();
    JSONObject jresponse = new JSONObject();
    try {//from   w  w w .  j a v a  2 s  . c om
        if (session.getAttribute("subscriptionId") == null) {
            throw new RESTException("You must first create a subscription.");
        }
        if (request.getParameter("updateSubscriptionText") != null) {
            events.add("TEXT");
        }
        if (request.getParameter("updateSubscriptionMms") != null) {
            events.add("MMS");
        }
        if (events.size() == 0) {
            throw new RESTException("You must select at least one of Text or MMS.");
        }
        final OAuthToken token = (OAuthToken) session.getAttribute("token");
        final String subscriptionId = (String) session.getAttribute("subscriptionId");
        final String fqdn = appConfig.getApiFQDN();
        final WebhooksService srvc = new WebhooksService(fqdn, token);
        final String channelId = appConfig.getProperty("channelId");
        final Integer expiresIn = Integer.valueOf(appConfig.getProperty("expiresIn"));
        final String callbackData = request.getParameter("callbackData");
        final UpdateSubscriptionArgs args = new UpdateSubscriptionArgs(channelId, subscriptionId,
                events.toArray(new String[events.size()]), callbackData, expiresIn);
        final UpdateSubscriptionResponse updateResponse = srvc.updateNotificationSubscription(args);
        session.setAttribute("subscriptionExpiry",
                DateUtil.xtimestamp() + updateResponse.getSubscription().getExpiresIn());
        jresponse.put("success", true).put("text", "Subscription 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:gwtupload.server.UploadServlet.java

/**
 * Writes a response to the client./*from   w w  w.  j a v  a2s. c  om*/
 */
protected static void renderMessage(HttpServletResponse response, String message, String contentType)
        throws IOException {
    response.addHeader("Cache-Control", "no-cache");
    response.setContentType(contentType + "; charset=UTF-8");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    out.print(message);
    out.flush();
    out.close();
}