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:cn.vlabs.umt.ui.actions.ManageApplicationAction.java

public ActionForward loadApp(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    String idStr = request.getParameter("q");
    AppService service = getAppService();
    int appid = Integer.parseInt(idStr);
    Application app = service.getApplication(appid);
    String json = "";
    if (app != null) {
        json = "[{" + "appname:'" + escape(app.getName()) + "'" + ",url:'" + escape(app.getUrl()) + "'"
                + ",description:'" + escape(app.getDescription()) + "'" + ",serverType:'"
                + escape(app.getServerType()) + "'" + ",allowOperate:" + app.isAllowOperate() + "}]";
    }//from w w  w  .j ava  2 s. c o  m
    response.setCharacterEncoding("UTF-8");
    PrintWriter writer = response.getWriter();
    writer.write(json);
    writer.close();
    writer.flush();
    return null;
}

From source file:com.adobe.acs.livereload.impl.JavaScriptInjectionFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    if (!(servletRequest instanceof SlingHttpServletRequest)
            || !(servletResponse instanceof SlingHttpServletResponse)) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;//ww  w. j  ava  2 s .  c o m
    }

    final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) servletRequest;
    final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) servletResponse;

    if (!this.accepts(slingRequest)) {
        filterChain.doFilter(slingRequest, slingResponse);
        return;
    }

    final BufferingResponse capturedResponse = new BufferingResponse(slingResponse);

    filterChain.doFilter(slingRequest, capturedResponse);

    // Get contents
    final String contents = capturedResponse.getContents();

    if (contents != null) {
        if (StringUtils.contains(slingResponse.getContentType(), "html")) {

            final int bodyIndex = contents.indexOf("</body>");
            if (bodyIndex != -1) {

                final PrintWriter printWriter = slingResponse.getWriter();

                printWriter.write(contents.substring(0, bodyIndex));
                printWriter.write(String.format(
                        "<script type=\"text/javascript\" src=\"http://%s:%s/livereload.js\"></script>",
                        slingRequest.getServerName(), port));
                printWriter.write(contents.substring(bodyIndex));
                return;
            }
        }
    }

    if (contents != null) {
        slingResponse.getWriter().write(contents);
    }

}

From source file:com.soulgalore.velocity.MergeXMLWithVelocity.java

void create(String[] args) throws JDOMException, IOException {

    Set<String> xmls = new HashSet<String>();

    if (args.length > 4) {
        for (int i = 4; i < args.length; i++) {
            xmls.add(args[i]);/*  w  ww .ja v a2s  .  co  m*/
        }
    }

    String result = (args.length > 4) ? merge(args[0], args[1], xmls.toArray(new String[0]))
            : merge(args[0], args[1]);

    final PrintWriter out = new PrintWriter(new FileOutputStream(args[3]));
    out.write(result);
    out.close();

}

From source file:com.ctb.prism.report.api.ReportPageStatusServlet.java

protected void pageUpdate(HttpServletRequest request, HttpServletResponse response,
        WebReportContext webReportContext) throws JRException, IOException {
    JasperPrintAccessor jasperPrintAccessor = (JasperPrintAccessor) webReportContext
            .getParameterValue(WebReportContext.REPORT_CONTEXT_PARAMETER_JASPER_PRINT_ACCESSOR);
    if (jasperPrintAccessor == null) {
        throw new JRRuntimeException("Did not find the report on the session.");
    }//from w  w  w.  j a  va  2  s. co  m

    String pageIdxParam = request.getParameter(WebUtil.REQUEST_PARAMETER_PAGE);
    Integer pageIndex = pageIdxParam == null ? null : Integer.valueOf(pageIdxParam);
    String pageTimestampParam = request.getParameter(WebUtil.REQUEST_PARAMETER_PAGE_TIMESTAMP);
    Long pageTimestamp = pageTimestampParam == null ? null : Long.valueOf(pageTimestampParam);

    if (log.isDebugEnabled()) {
        log.debug("report page update check for pageIndex: " + pageIndex + ", pageTimestamp: " + pageTimestamp);
    }

    Map<String, Object> reportStatus = new LinkedHashMap<String, Object>();
    putReportStatusResult(response, jasperPrintAccessor, reportStatus);

    if (pageIndex != null && pageTimestamp != null) {
        ReportPageStatus pageStatus = jasperPrintAccessor.pageStatus(pageIndex, pageTimestamp);
        boolean modified = pageStatus.hasModified();
        reportStatus.put("pageModified", modified);
        reportStatus.put("pageFinal", pageStatus.isPageFinal());

        if (log.isDebugEnabled()) {
            log.debug("page " + pageIndex + " modified " + modified);
        }
    }

    Map<String, Object> result = new HashMap<String, Object>();
    result.put("result", reportStatus);

    String resultString = JacksonUtil.getInstance(getJasperReportsContext()).getJsonString(result);
    PrintWriter out = response.getWriter();
    out.write(resultString);
    out.flush();
}

From source file:com.indoqa.osgi.embedded.sample.webapp.SampleServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    PrintWriter writer = resp.getWriter();

    DateServiceProvider dateServiceProvider = this.applicationContext.getBean(DateServiceProvider.class);
    if (dateServiceProvider == null) {
        writer.write("\nCouldn't find bean of type " + DateService.class.getName());
    } else {//from  w  ww  .  j av  a  2 s  .  c  om
        DateService[] dateServices = dateServiceProvider.getDateServices();
        writer.write("\nFound " + dateServices.length + " date service instance(s).");

        for (DateService eachDateService : dateServices) {
            writer.write("\n* DateService output: " + eachDateService.getDate());
        }
    }
}

From source file:com.moss.appkeep.server.HttpPublisher.java

private void completeWithError(String message, int code, HttpServletResponse response) throws IOException {
    response.setStatus(code);/* w ww  .  ja v  a2s. c om*/
    PrintWriter w = response.getWriter();
    w.write(message);
    w.close();
}

From source file:com.comcast.video.dawg.show.TraceController.java

/**
 * Method to generate a trace log file//from   ww  w .  j  a  va2 s  .  c  om
 * @param trace trace log obtained from trace div
 * @param device device Id of the settop
 * @param response http response to get the trace file
 * @throws IOException Exception occurring while writing log.
 */
public void generateLogFile(String trace, String device, HttpServletRequest req, HttpServletResponse response)
        throws IOException {
    accessValidator.validateUserHasAccessToDevices(req, response, false, device);
    String timestamp = FILE_NAME_DATE_FORMATTER.format(new Date());
    response.setHeader("Content-Disposition",
            "attachment; filename=Settop_" + device + "_" + timestamp + ".log");

    PrintWriter writer = null;
    String log = StringEscapeUtils.unescapeHtml(trace.trim());
    try {
        writer = response.getWriter();
        writer.write(log);
    } catch (IOException ioe) {
        LOGGER.error("Exception while generating trace logs ", ioe);
        throw ioe;
    } finally {

        if (writer != null) {
            writer.flush();
            writer.close();
        }

        response.flushBuffer();
    }
}

From source file:de.undercouch.gradle.tasks.download.OnlyIfModifiedTest.java

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler lastModifiedHandler = new ContextHandler("/" + LAST_MODIFIED) {
        @Override/*from w ww .  jav  a 2s  .  c  o m*/
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            response.setStatus(200);
            if (lastModified != null) {
                response.setHeader("Last-Modified", lastModified);
            }
            PrintWriter rw = response.getWriter();
            rw.write("lm: " + String.valueOf(lastModified));
            rw.close();
        }
    };
    return new Handler[] { lastModifiedHandler };
}

From source file:com.cimpoint.mes.server.servlets.CustomCodeServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getParameter("action").equals("GetModule")) {
        PrintWriter out = response.getWriter();
        DynamicForm form = createTestForm();
        JavaScriptObject jsObj = form.getJsObj();
        String src = jsObj.toSource();
        out.write(src);
    }/*  w  w  w. ja  v  a  2  s . c  o m*/
}

From source file:io.neba.core.selftests.SelftestConsolePlugin.java

private void runAll(HttpServletResponse response) throws IOException {
    response.setContentType("application/xml;charset=UTF-8");
    PrintWriter writer = response.getWriter();

    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    writer.write("<tests>");
    for (SelftestReference ref : getSelftestReferences()) {
        String result = execute(ref);
        boolean failed = !isEmpty(result);

        writer.write("<test id=\"");
        writer.write(ref.getId());//from w ww .  j  a  v a 2s. c  o  m
        writer.write("\" ");
        writer.write("description=\"");
        writer.write(escapeXml(ref.getDescription()));
        writer.write("\" ");
        writer.write("successMessage=\"");
        writer.write(escapeXml(ref.getSuccess()));
        writer.write("\" ");
        writer.write("failureMessage=\"");
        writer.write(escapeXml(ref.getFailure()));
        writer.write("\" ");
        writer.write("failed=\"" + failed + "\">");
        if (failed) {
            writer.write("<![CDATA[");
            writer.write(result.replace("]]>", "]]]]><![CDATA[>"));
            writer.write("]]>");
        }
        writer.write("</test>");
    }
    writer.write("</tests>");
}