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.uniquesoft.uidl.servlet.UploadServlet.java

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

    System.out.println("=======>" + message);
    out.flush();
    out.close();
}

From source file:com.att.api.immn.controller.GetMsgIndexInfoController.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 {//from  w  ww . j  a v  a  2  s . c  o  m
        final MessageIndexInfo info = srvc.getMessageIndexInfo();

        final JSONArray tables = new JSONArray();
        final JSONArray values = new JSONArray().put(info.getStatus()).put(info.getState())
                .put(info.getMessageCount());
        tables.put(new JSONObject().put("caption", "Message Index Info:")
                .put("headers", new JSONArray().put("Status").put("State").put("Message Count"))
                .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.dubbo.governance.web.home.module.screen.Status.java

public void execute(Map<String, Object> context) throws Exception {
    //FIXME cache ?
    Map<String, com.alibaba.dubbo.common.status.Status> statuses = StatusManager.getInstance()
            .getStatusList(new String[] { "cache" });
    com.alibaba.dubbo.common.status.Status status = StatusManager.getInstance().getStatusSummary(statuses);
    Level level = status.getLevel();
    if (!com.alibaba.dubbo.common.status.Status.Level.OK.equals(level)) {
        context.put("message", level + new SimpleDateFormat(" [yyyy-MM-dd HH:mm:ss] ").format(new Date())
                + filterOK(status.getMessage()));
    } else {//from   w ww  . j  a  va  2 s .c  o m
        context.put("message", level.toString());
    }
    PrintWriter writer = response.getWriter();
    writer.print(context.get("message").toString());
    writer.flush();
}

From source file:com.microsoftopentechnologies.intellij.helpers.AndroidStudioHelper.java

public static void newActivityTemplateManager() throws IOException, InterruptedException {
    String[] cmd = null;/* w  w  w  .  j  a v  a  2  s  .  co  m*/

    String templatePath = URLDecoder
            .decode(ApplicationComponent.class.getResource("").getPath().replace("file:/", ""), "UTF-8");
    templatePath = templatePath.replace("/", File.separator);
    templatePath = templatePath.substring(0, templatePath.indexOf(File.separator + "lib"));
    templatePath = templatePath + File.separator + "plugins" + File.separator + "android" + File.separator;
    templatePath = templatePath + "lib" + File.separator + "templates" + File.separator + "activities"
            + File.separator;

    String[] env = null;

    if (!new File(templatePath + mobileServicesTemplateName).exists()) {
        String tmpdir = getTempLocation();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(
                ServiceCodeReferenceHelper.getTemplateResource("ActivityTemplate.zip"));
        unZip(bufferedInputStream, tmpdir);

        if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
            try {
                copyFolder(new File(tmpdir + mobileServicesTemplateName),
                        new File(templatePath + mobileServicesTemplateName));
                copyFolder(new File(tmpdir + officeTemplateName), new File(templatePath + officeTemplateName));
            } catch (IOException ex) {
                PrintWriter printWriter = new PrintWriter(tmpdir + "\\script.bat");
                printWriter.println("@echo off");
                printWriter.println("md \"" + templatePath + mobileServicesTemplateName + "\"");
                printWriter.println("md \"" + templatePath + officeTemplateName + "\"");
                printWriter.println("xcopy \"" + tmpdir + mobileServicesTemplateName + "\" \"" + templatePath
                        + mobileServicesTemplateName + "\" /s /i /Y");
                printWriter.println("xcopy \"" + tmpdir + officeTemplateName + "\" \"" + templatePath
                        + officeTemplateName + "\" /s /i /Y");
                printWriter.flush();
                printWriter.close();

                String[] tmpcmd = { tmpdir + "\\elevate.exe", "script.bat", "1" };

                cmd = tmpcmd;

                ArrayList<String> tempenvlist = new ArrayList<String>();
                for (String envval : System.getenv().keySet())
                    tempenvlist.add(String.format("%s=%s", envval, System.getenv().get(envval)));

                tempenvlist.add("PRECOMPILE_STREAMLINE_FILES=1");
                env = new String[tempenvlist.size()];
                tempenvlist.toArray(env);

                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(cmd, env, new File(tmpdir));
                proc.waitFor();

                //wait for elevate command to finish
                Thread.sleep(3000);

                if (!new File(templatePath + mobileServicesTemplateName).exists())
                    UIHelper.showException(
                            "Error copying template files. Please refer to documentation to copy manually.",
                            new Exception());
            }
        } else {
            if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {

                String[] strings = { "osascript",
                        //        "-e",
                        //        "do shell script \"mkdir -p \\\"/" + templatePath + mobileServicesTemplateName + "\\\"\"",
                        //        "-e",
                        //        "do shell script \"mkdir -p \\\"/" + templatePath + officeTemplateName + "\\\"\"",
                        "-e",
                        "do shell script \"cp -Rp \\\"" + tmpdir + mobileServicesTemplateName + "\\\" \\\"/"
                                + templatePath + "\\\"\"",
                        "-e", "do shell script \"cp -Rp \\\"" + tmpdir + officeTemplateName + "\\\" \\\"/"
                                + templatePath + "\\\"\"" };

                exec(strings, tmpdir);
            } else {
                try {

                    copyFolder(new File(tmpdir + mobileServicesTemplateName),
                            new File(templatePath + mobileServicesTemplateName));
                    copyFolder(new File(tmpdir + officeTemplateName),
                            new File(templatePath + officeTemplateName));

                } catch (IOException ex) {

                    JPasswordField pf = new JPasswordField();
                    int okCxl = JOptionPane.showConfirmDialog(null, pf,
                            "To copy Microsoft Services templates, the plugin needs your password:",
                            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

                    if (okCxl == JOptionPane.OK_OPTION) {
                        String password = new String(pf.getPassword());

                        exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp",
                                tmpdir + mobileServicesTemplateName,
                                templatePath + mobileServicesTemplateName }, tmpdir);

                        exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp",
                                tmpdir + officeTemplateName, templatePath + officeTemplateName }, tmpdir);
                    }
                }
            }
        }
    }
}

From source file:TimeServer.java

public void run() {
    Socket client = null;//from  w  w w.j  a  v  a2  s  .  c om

    while (true) {
        if (sock == null)
            return;
        try {
            client = sock.accept();
            BufferedOutputStream bos = new BufferedOutputStream(client.getOutputStream());
            PrintWriter os = new PrintWriter(bos, false);
            String outLine;

            Date now = new Date();
            os.println(now);
            os.flush();

            os.close();
            client.close();
        } catch (IOException e) {
            System.out.println("Error: couldn't connect to client.");
            System.exit(1);
        }
    }
}

From source file:com.infinities.keystone4j.utils.Cms.java

public static byte[] DERtoPEM(byte[] bytes, String headfoot) {
    ByteArrayOutputStream pemStream = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(pemStream);

    byte[] stringBytes = BaseEncoding.base64().encode(bytes).getBytes();

    String encoded = new String(stringBytes);

    if (headfoot != null) {
        writer.print("-----BEGIN " + headfoot + "-----\n");
    }//w w w.  ja v  a 2 s.  c  o m

    // write 64 chars per line till done
    int i = 0;
    while ((i + 1) * 64 < encoded.length()) {
        writer.print(encoded.substring(i * 64, (i + 1) * 64));
        writer.print("\n");
        i++;
    }
    if (encoded.length() % 64 != 0) {
        writer.print(encoded.substring(i * 64)); // write remainder
        writer.print("\n");
    }
    if (headfoot != null) {
        writer.print("-----END " + headfoot + "-----\n");
    }
    writer.flush();
    return pemStream.toByteArray();
}

From source file:com.mattbertolini.statusboard.view.graph.AbstractGraphView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> stringObjectMap, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    if (this.objectMapper == null) {
        throw new IllegalStateException("Unable to render Status Board graph view. ObjectMapper is null.");
    }/*w  ww .ja v a  2  s  .com*/
    Graph graph = new Graph();
    this.buildGraph(stringObjectMap, graph);
    PrintWriter writer = response.getWriter();
    this.objectMapper.writeValue(writer, graph);
    writer.flush();
}

From source file:com.alibaba.dubbo.governance.web.home.module.screen.Shell.java

public void execute(Map<String, Object> context) throws Exception {
    if (context.get(WebConstants.CURRENT_USER_KEY) != null) {
        User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
        currentUser = user;/*w w  w  .ja va  2 s  .c o m*/
        operator = user.getUsername();
        role = user.getRole();
        context.put(WebConstants.CURRENT_USER_KEY, user);
    }
    operatorAddress = (String) context.get("request.remoteHost");
    context.put("operator", operator);
    context.put("operatorAddress", operatorAddress);
    try {
        String message = doExecute(context);
        context.put("message", "OK: " + filterERROR(message));
    } catch (Throwable t) {
        context.put("message", "ERROR: " + filterOK(t.getMessage()));
    }
    PrintWriter writer = response.getWriter();
    writer.print(context.get("message"));
    writer.flush();
}

From source file:org.craftercms.engine.freemarker.CrafterTemplateExceptionHandler.java

protected String getExceptionStackTrace(TemplateException te) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);

    te.printStackTrace(pw);/*from  ww w.j  ava2 s .  c  om*/
    pw.flush();

    return sw.toString();
}

From source file:com.nesscomputing.httpclient.testsupport.GenericWritingContentHandler.java

@Override
public void handle(final String target, final Request request, final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException, ServletException {
    method = request.getMethod();/*from  ww w .j a v a 2 s. c o m*/

    InputStream inputStream = request.getInputStream();

    postData = IOUtils.toString(inputStream);

    httpResponse.setContentType(contentType);
    httpResponse.setStatus(HttpServletResponse.SC_OK);

    request.setHandled(true);

    final PrintWriter writer = httpResponse.getWriter();
    writer.print(content);
    writer.flush();
}