Example usage for java.io PrintWriter write

List of usage examples for java.io PrintWriter write

Introduction

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

Prototype

public void write(String s) 

Source Link

Document

Writes a string.

Usage

From source file:be.iminds.aiolos.ui.DemoServlet.java

private void startComponent(PrintWriter writer, String componentId, String version, String nodeId) {

    JSONObject result = new JSONObject();
    PlatformManager platform = platformTracker.getService();
    if (platform != null) {
        try {//ww  w .  j  av  a 2  s. com
            platform.startComponent(componentId, version, nodeId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    writer.write(result.toJSONString());
}

From source file:org.kite9.diagram.server.AbstractKite9Controller.java

public void sendErrorEmail(Throwable t, String xml, String url) {
    try {/*from w w w . ja v a 2 s .  co  m*/
        Properties props = new Properties();
        props.put("mail.smtp.host", "server.kite9.org");
        Session session = Session.getInstance(props);
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress("servicetest@kite9.com"));
        msg.setRecipient(RecipientType.TO, new InternetAddress("rob@kite9.com"));
        String name = ctx.getServletContextName();
        boolean local = isLocal();
        msg.setSubject("Failure in " + (local ? "TEST" : name) + " Service: " + this.getClass().getName());
        StringWriter sw = new StringWriter(10000);
        PrintWriter pw = new PrintWriter(sw);
        pw.write("URL: " + url + "\n");

        t.printStackTrace(pw);

        if (xml != null) {
            pw.println();
            pw.print(xml);
        }

        pw.close();
        msg.setText(sw.toString());
        Transport.send(msg);
    } catch (Exception e) {
    } finally {
        t.printStackTrace();
    }
}

From source file:net.openkoncept.vroom.VroomController.java

private void processRequestJSGenerate(HttpServletRequest request, HttpServletResponse response,
        String contextPath, String servletPath, String sessionId, String uri) throws IOException {
    StringBuffer sbScript = new StringBuffer();
    VroomScriptGenerator sg = new VroomScriptGenerator(VroomConfig.getInstance(), contextPath, servletPath,
            sessionId, uri);// w  w w. j  a v  a 2s.c  o m
    sbScript.append(sg.generateScript());
    String encoding = request.getHeader("response-encoding");
    if (encoding == null || encoding.trim().length() == 0) {
        encoding = request.getCharacterEncoding();
    }
    response.setContentType(JS_MIME_TYPE);
    if (encoding != null) {
        VroomUtilities.safeCall(response, "setCharacterEncoding", new Class[] { String.class },
                new Object[] { encoding });
        //            response.setCharacterEncoding(encoding);
    }
    PrintWriter out = null;
    try {
        out = response.getWriter();
        out.write(sbScript.toString());
    } finally {
        if (out != null) {
            out.close();
        }
    }

}

From source file:be.iminds.aiolos.ui.DemoServlet.java

private void stopComponent(PrintWriter writer, String componentId, String version, String nodeId) {

    JSONObject result = new JSONObject();
    PlatformManager platform = platformTracker.getService();
    if (platform != null) {
        try {//from  w  w  w. jav  a2s. com
            platform.stopComponent(new ComponentInfo(componentId, version, nodeId));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    writer.write(result.toJSONString());
}

From source file:org.kite9.diagram.server.AbstractKite9Controller.java

protected void storeDiagramDetails(Project p, User u, String fileName, long currentTime, boolean failed,
        DiagramSize mva, Action a, String xml) {
    try {/*from  w  ww  .ja  va  2 s.  co  m*/
        String stamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
        PrintWriter pw = new PrintWriter(new FileWriter(getDiagramLog(), true), false);
        pw.write(u + "," + p + "," + currentTime + "," + (failed ? "FAIL" : "GOOD") + "," + mva + ","
                + a.toString() + "," + fileName + "," + stamp + "\n");
        pw.close();
    } catch (Exception e) {
        sendErrorEmail(e, xml, null);
    }
}

From source file:bolts.AppLinkTest.java

private Uri getURLForData(String data) throws IOException {
    File result = File.createTempFile("temp", ".html", getInstrumentation().getTargetContext().getCacheDir());
    PrintWriter writer = new PrintWriter(result);
    writer.write(data);
    writer.close();/*w w  w . ja  v  a 2  s . c om*/
    result.deleteOnExit();
    return Uri.parse(result.toURI().toString());
}

From source file:com.ephesoft.gxt.admin.server.ImportTableUploadServlet.java

/**
 * This API is used to process attach file.
 * // w  w  w  .  ja  va2 s .  c  om
 * @param req {@link HttpServletRequest}.
 * @param resp {@link HttpServletResponse}.
 * @param bSService {@link BatchSchemaService}.
 * @return
 */
private void attachFile(final HttpServletRequest req, final HttpServletResponse resp,
        final BatchSchemaService bSService) throws IOException {

    final PrintWriter printWriter = resp.getWriter();
    String tempFile = null;

    if (ServletFileUpload.isMultipartContent(req)) {
        final String testTableDirPath = EphesoftStringUtil.concatenate(bSService.getBaseFolderLocation(),
                File.separator, req.getParameter("batchClassIdentifier"), File.separator,
                bSService.getTestTableFolderName());
        final ServletFileUpload upload = getUploadedFile(testTableDirPath);

        tempFile = processUploadedFile(upload, req, printWriter, testTableDirPath);
        printWriter.write(tempFile);

    } else {
        log.error("Request contents type is not supported.");
        printWriter.write("Request contents type is not supported.");
    }

    printWriter.flush();
}

From source file:be.iminds.aiolos.ui.DemoServlet.java

private void migrateComponent(PrintWriter writer, String componentId, String version, String from, String to) {

    JSONObject result = new JSONObject();
    PlatformManager platform = platformTracker.getService();
    if (platform != null) {
        try {/*w w  w .java  2  s  . c  o m*/
            platform.migrateComponent(new ComponentInfo(componentId, version, from), to);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    writer.write(result.toJSONString());
}

From source file:msec.org.FileUploadServlet.java

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

    Map<String, String> fields = new HashMap<String, String>();
    List<String> fileNames = new ArrayList<String>();

    request.setCharacterEncoding("UTF-8");

    String result = FileUpload(fields, fileNames, request, response);

    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html; charset=utf-8");
    PrintWriter out = response.getWriter();

    if (result == null || !result.equals("success")) {
        out.printf("{\"status\":100, \"message\":\"%s\"}", result == null ? "" : result);
        return;//w w w  .  j a v a 2  s. com
    }
    String handleClass = fields.get("handleClass");
    if (handleClass != null && handleClass.equals("beans.service.LibraryFileUpload")) {
        //out.write(new LibraryFileUpload().run(fields, fileNames));
        return;
    }
    if (handleClass != null && handleClass.equals("beans.service.SharedobjectUpload")) {
        //  out.write(new SharedobjectUpload().run(fields, fileNames));
        return;

    }
    out.write("{\"status\":100, \"message\":\"unkown handle class\"}");
    return;

}

From source file:net.openkoncept.vroom.VroomController.java

private void processRequestJSFile(HttpServletRequest request, HttpServletResponse response, String contextPath,
        String servletPath, String sessionId, String requestPath) throws IOException {
    String src = request.getParameter(FILE_SRC);
    if (src != null) {
        String realPath = getServletContext().getRealPath(src);
        BufferedReader reader = new BufferedReader(new FileReader(realPath));
        StringBuffer sbOutput = new StringBuffer();
        String line = reader.readLine();
        while (line != null) {
            sbOutput.append(line);/*from  www. jav a2  s  .com*/
            sbOutput.append("\n");
            line = reader.readLine();
        }
        reader.close();

        VroomHtmlProcessor.replace(sbOutput, $CONTEXT_PATH$, contextPath);
        VroomHtmlProcessor.replace(sbOutput, $SERVLET_PATH$, servletPath);
        VroomHtmlProcessor.replace(sbOutput, $SESSION_ID$, sessionId);
        VroomHtmlProcessor.replace(sbOutput, $REQUEST_PATH$, requestPath);
        String encoding = request.getHeader("response-encoding");
        if (encoding == null || encoding.trim().length() == 0) {
            encoding = request.getCharacterEncoding();
        }
        response.setContentType(JS_MIME_TYPE);
        if (encoding != null) {
            VroomUtilities.safeCall(response, "setCharacterEncoding", new Class[] { String.class },
                    new Object[] { encoding });
            //                response.setCharacterEncoding(encoding);
        }
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.write(sbOutput.toString());
        } finally {
            if (out != null) {
                out.close();
            }
        }

    }
}