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:au.org.ala.delta.directives.DirectiveRegistry.java

public void dump(PrintWriter writer) {
    for (AbstractDirective<C> d : _list) {
        writer.write(String.format("%s\n", StringUtils.join(d.getControlWords(), " ")));
    }// w  w  w  .  java 2  s.c o  m
    writer.flush();
}

From source file:be.fgov.kszbcss.rhq.websphere.config.ConfigQueryServiceImpl.java

public synchronized String dumpLastException() {
    if (lastException == null) {
        return null;
    } else {/*from  ww w.java2  s  . c o m*/
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, false);
        lastException.printStackTrace(pw);
        pw.flush();
        return sw.toString();
    }
}

From source file:egovframework.com.utl.wed.filter.CkImageSaver.java

public void saveAndReturnUrlToClient(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    // Parse the request
    try {/* w w  w .  j  ava  2 s  .c  o m*/
        FileItemFactory factory = new DiskFileItemFactory();

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);

        List<FileItem> /* FileItem */ items = upload.parseRequest(request);
        // We upload just one file at the same time
        FileItem uplFile = items.get(0);

        String errorMessage = null;
        String relUrl = null;

        if (isAllowFileType(FilenameUtils.getName(uplFile.getName()))) {
            relUrl = fileSaveManager.saveFile(uplFile, imageBaseDir, imageDomain);

        } else {
            errorMessage = "Restricted Image Format";
        }

        StringBuffer sb = new StringBuffer();
        sb.append("<script type=\"text/javascript\">\n");
        // Compressed version of the document.domain automatic fix script.
        // The original script can be found at [fckeditor_dir]/_dev/domain_fix_template.js
        // sb.append("(function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();\n");
        sb.append("window.parent.CKEDITOR.tools.callFunction(").append(request.getParameter(FUNC_NO))
                .append(", '");
        sb.append(relUrl);
        if (errorMessage != null) {
            sb.append("', '").append(errorMessage);
        }
        sb.append("');\n </script>");

        response.setContentType("text/html");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter out = response.getWriter();

        out.print(sb.toString());
        out.flush();
        out.close();

    } catch (FileUploadException e) {
        log.error(e);
    }
}

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

@RequestMapping(value = "/seller/productList", method = RequestMethod.GET)
public void showProductList(HttpServletRequest request, HttpServletResponse response) throws IOException {

    //ModelAndView mav = new ModelAndView();

    PsSeller seller = (PsSeller) request.getSession().getAttribute("currentSeller");

    List<PsItem> items = psItemDao.findBySeller(seller.getId(), new FetchOption());

    //JSONObject jsonObject = JSONObject.fromObject(items);

    for (PsItem psItem : items) {
        System.out.println(psItem.getName());
        psItem.setUrlPicture(psItem.getUrlPicture().split(";")[0]);
    }//w ww. j  a v a  2s  . c o  m

    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setIgnoreDefaultExcludes(false);
    jsonConfig.setExcludes(new String[] { "customerFavouriteItems", "psPromotItems", "psComments", "psTags",
            "cartCustomerItems", "ROrderItems", "psShop", "psCategory" });

    JSONArray jsonArray = JSONArray.fromObject(items, jsonConfig);
    PrintWriter out = response.getWriter();
    out.write(jsonArray.toString());
    out.flush();
    out.close();
    //mav.setViewName("seller_list");
    //mav.addObject("productlist", items);
    //return mav;

}

From source file:de.knightsoftnet.validators.server.security.AuthSuccessHandler.java

@Override
public void onAuthenticationSuccess(final HttpServletRequest prequest, final HttpServletResponse presponse,
        final Authentication pauthentication) throws IOException, ServletException {
    this.csrfCookieHandler.setCookie(prequest, presponse);

    if (pauthentication.isAuthenticated()) {
        presponse.setStatus(HttpServletResponse.SC_OK);
        LOGGER.info("User is authenticated!");
        LOGGER.debug(pauthentication.toString());

        final PrintWriter writer = presponse.getWriter();
        this.mapper.writeValue(writer,
                this.userDetailsConverter.convert((UserDetails) pauthentication.getPrincipal()));
        writer.flush();
    } else {//from   w ww .j av  a 2  s .co m
        presponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    }
}

From source file:org.eurekastreams.server.service.servlets.GetThemeCssServlet.java

/**
 * Pump out an HTTP error./*  w w w  .  j  a  v  a2s. c o  m*/
 * 
 * @param statusCode
 *            the status code.
 * @param response
 *            the response.
 */
private void httpError(final int statusCode, final HttpServletResponse response) {
    try {
        response.setStatus(statusCode);
        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.append("<html><body><h1>Error Code: " + statusCode + "</h1><body></html>");
        writer.flush();
    } catch (IOException e) {
        log.error(e);
    }
}

From source file:es.itecban.deployment.executionmanager.web.view.ReportActivityView.java

public void render(Map model, HttpServletRequest req, HttpServletResponse resp) throws Exception {
    PrintWriter out = resp.getWriter();

    resp.setContentType("application/octet-stream");

    ActivityExecReportType report = (ActivityExecReportType) model.get("report");
    out.print(report.getTechnicalActivityExecReport());
    out.flush();
    out.close();//from   ww  w  .  j a v a  2  s  . co  m

}

From source file:net.sf.jasperreports.web.servlets.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(EXCEPTION_MESSAGE_KEY_REPORT_NOT_FOUND, (Object[]) null);
    }/*from  w ww .j a va 2s. c o  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:baggage.hypertoolkit.views.JSONResponse.java

public void render(OutputStream outputStream) throws IOException {
    PrintWriter pw = new PrintWriter(outputStream);
    if (o instanceof JSONObject) {
        pw.println(((JSONObject) o).toString(4));
    } else {//from  w  w  w  .  ja  v  a2 s . c om
        pw.println(o.toString());
    }
    pw.flush();
}

From source file:edu.lternet.pasta.portal.ReportViewerServlet.java

/**
 * The doPost method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to post.
 * //from w  ww  . j  a v a  2  s . c om
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession httpSession = request.getSession();
    String uid = (String) httpSession.getAttribute("uid");

    if (uid == null || uid.isEmpty())
        uid = "public";

    String packageId = request.getParameter("packageid");
    String encodedPath = request.getParameter("localPath");
    String scope = null;
    Integer identifier = null;
    String revision = null;
    String xml = null;
    String html = null;

    try {
        String[] tokens = packageId.split("\\.");

        if (tokens.length == 3) {
            scope = tokens[0];
            identifier = Integer.valueOf(tokens[1]);
            revision = tokens[2];
            /*
             * The quality report XML could be read either from a local file
             * or from PASTA via the DataPackageManagerClient.
             */
            if (encodedPath != null && encodedPath.length() > 0) {
                URLCodec urlCodec = new URLCodec();
                String localPath = urlCodec.decode(encodedPath);
                File xmlFile = new File(localPath);
                if (xmlFile != null && xmlFile.exists()) {
                    xml = FileUtils.readFileToString(xmlFile);
                }
            } else {
                DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid);
                xml = dpmClient.readDataPackageReport(scope, identifier, revision);
            }

            ReportUtility qrUtility = new ReportUtility(xml);
            html = HTMLHEAD + "<div class=\"qualityreport\">" + qrUtility.xmlToHtmlTable(cwd + xslpath)
                    + "</div>" + HTMLTAIL;
        } else {
            String msg = String.format(
                    "packageId '%s' is not in the correct form of 'scope.identifier.revision' (e.g., 'knb-lter-lno.1.1')",
                    packageId);
            throw new UserErrorException(msg);
        }
    } catch (Exception e) {
        handleDataPortalError(logger, e);
    }

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