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:cn.vlabs.umt.ui.servlet.UMTPublicKeyServiceServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    UMTCredential cred = (UMTCredential) factory.getBean("UMTCredUtil");
    PublicKeyEnvelope opublickey = new PublicKeyEnvelope();
    opublickey.setAppId(cred.getUMTId());
    Date month = DateUtils.addMonths(new Date(cred.getCreateTime()), 1);
    opublickey.setValidTime(DateFormatUtils.format(month, "yyyy-MM-dd hh:mm:ss"));
    opublickey.setPublicKey(HexUtil.toHexString(cred.getUMTKey().getRSAPublic().getEncoded()));
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    out.write(opublickey.toXML());//  w w  w  . j  a v  a 2 s .c  o m
    out.flush();
    out.close();

}

From source file:com.att.api.immn.controller.CreateIndexController.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);

    JSONObject jresponse = new JSONObject();
    try {/*  ww  w.  ja va2s .com*/
        srvc.createMessageIndex();
        jresponse.put("success", true).put("text", "Message index 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.msco.mil.client.com.sencha.gxt.examples.resources.server.JsonTreeServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {//www  .ja  va 2 s  . c o m
        String id = req.getParameter("id");

        Folder folder = Folder.findFolder(id == null ? 1 : Integer.valueOf(id));

        String xml = generateJson(folder);

        resp.setContentType("application/json");
        PrintWriter out = resp.getWriter();
        out.println(xml);
        out.flush();
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.sentinel.rest.handlers.AuthSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    LOG.trace("Method: onAuthenticationSuccess called.");

    response.setStatus(HttpServletResponse.SC_OK);
    UserDetails userdetails = (UserDetails) authentication.getPrincipal();

    LOG.info(userdetails.getUsername() + " got is connected ");

    PrintWriter writer = response.getWriter();
    mapper.writeValue(writer, null);/*from   w w w.  j  a v  a 2 s  .  co m*/
    writer.flush();
    LOG.trace("Method: onAuthenticationSuccess finished.");
}

From source file:com.att.api.sms.controller.LoadController.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final HttpSession session = request.getSession();

    JSONObject jresponse = new JSONObject().put("authenticated", true).put("server_time", DateUtil.getTime())
            .put("download", this.appConfig.getProperty("linkDownload"))
            .put("github", this.appConfig.getProperty("linkGithub"))
            .put("short_code_check", this.appConfig.getProperty("getMsgsShortCode"))
            .put("short_code_received", this.appConfig.getProperty("receiveMsgsShortCode"));

    final String savedData = (String) session.getAttribute("savedData");
    if (savedData != null) {
        final JSONObject jsavedData = new JSONObject(savedData);
        jresponse.put("savedData", jsavedData);
    }/*from  w ww.  jav  a  2s .co m*/

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

From source file:com.microsoft.tfs.core.checkinpolicies.PolicyEvaluator.java

/**
 * Returns a text error message (with newlines) suitable for printing in a
 * console window, log file, or other text area that describes a problem
 * loading a check-in policy implementation so the user can fix the problem.
 * Things like policy type ID, installation instructions, and sometimes
 * stack traces are formatted into the message.
 *
 * @param throwable//from w  w w .j av a2s  .  co m
 *        the problem that caused the load failure, usually these are
 *        {@link PolicyLoaderException}, but they can be any kind of
 *        {@link Throwable} and the error message will be as descriptive as
 *        possible (must not be <code>null</code>)
 * @return the formatted error text.
 */
public static String makeTextErrorForLoadException(final Throwable throwable) {
    Check.notNull(throwable, "throwable"); //$NON-NLS-1$

    final StringBuffer sb = new StringBuffer();

    if (throwable instanceof PolicyLoaderException
            && ((PolicyLoaderException) throwable).getPolicyType() != null) {
        /*
         * Additional details for policy loader exceptions with policy type
         * information.
         */

        sb.append(Messages.getString("PolicyEvaluator.RequiredCheckinPolicyFailedToLoad")); //$NON-NLS-1$

        final PolicyLoaderException ple = (PolicyLoaderException) throwable;
        sb.append(Messages.getString("PolicyEvaluator.NameColon") + ple.getPolicyType().getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
        sb.append(Messages.getString("PolicyEvaluator.IDColon") + ple.getPolicyType().getID() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
        sb.append(Messages.getString("PolicyEvaluator.InstallationInstructionsColon") //$NON-NLS-1$
                + ple.getPolicyType().getInstallationInstructions() + "\n"); //$NON-NLS-1$

        sb.append(Messages.getString("PolicyEvaluator.ErrorColon") + throwable.getLocalizedMessage() + "\n\n"); //$NON-NLS-1$ //$NON-NLS-2$
    } else {
        /*
         * Run-time errors and other problems not handled during policy
         * loading are wrapped in TECoreException, but some other exception
         * types may come through (very rare).
         */

        sb.append(Messages.getString("PolicyEvaluator.AnErrorOccurredInThePolicyFramework")); //$NON-NLS-1$

        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        throwable.printStackTrace(pw);
        pw.flush();
        sw.flush();

        sb.append(Messages.getString("PolicyEvaluator.ErrorColon") + sw.toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    sb.append(Messages.getString("PolicyEvaluator.MoreDetailsMayBeAvailableInPlatformLogs")); //$NON-NLS-1$

    return sb.toString();
}

From source file:com.fengduo.bee.commons.exception.SystemExceptionResolver.java

/**
 * Response  responseText/*from  w ww. j av a  2  s. co m*/
 * 
 * @param response
 * @param errorMsg
 */
private void printJSON(HttpServletResponse response, String errorMsg) {
    response.setCharacterEncoding("UTF-8");
    try {
        PrintWriter out = response.getWriter();
        out.println(errorMsg);
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:marytts.tools.dbselection.DatabaseSelector.java

/**
 * Print the list of selected files//from ww  w.  java  2s . co  m
 * 
 * @param filename the file to print to
 * @param selected the list of files
 */
private static void storeResult(String filename, Set<Integer> selected) {

    PrintWriter out;
    try {
        out = new PrintWriter(new FileWriter(new File(filename)));
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("Error storing result");
    }
    for (int sel : selected) {
        out.println(sel);
    }
    out.flush();
    out.close();
}

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

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

    final HttpSession session = request.getSession();
    JSONObject jresponse = new JSONObject();
    try {//from  w  ww  .  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 = this.getFileToken("notificationScope");
        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);
        srvc.deleteNotificationSubscription(channelId, subscriptionId);
        session.removeAttribute("subscriptionId");
        jresponse.put("success", true).put("text", "Subscription deleted.");
    } 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.DelMsgController.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 msgIdStr = request.getParameter("deleteMsgId");
    final String[] msgIds = msgIdStr.split(",");

    JSONObject jresponse = new JSONObject();
    try {/*from   www . j a  v a 2s  .co m*/
        if (msgIds.length > 1) {
            srvc.deleteMessages(msgIds);
        } else {
            final String msgId = msgIds[0];
            srvc.deleteMessage(msgId);
        }
        jresponse.put("success", true).put("text", "Message(s) deleted.");
    } catch (RESTException re) {
        jresponse.put("success", false).put("text", re.getMessage());
    }

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