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:com.bitranger.parknshop.seller.controller.SellerShowCtrl.java

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

    String recordId = request.getParameter("id");

    PsOrder psOrder = psOrderDao.findByOrderId(Integer.parseInt(recordId));

    psOrder.setStatus(OrderStatus.DELIVERING);

    psOrderDao.update(psOrder);/*w w w.j a  va 2s.c om*/

    PsNoticeCustomer n = new PsNoticeCustomer(psOrder.getPsCustomer(),
            new Timestamp(System.currentTimeMillis()), psOrder.getPsShop().getName(),
            "Order[" + psOrder.getId() + "] delivered", (short) 1);
    psNoticeCustomerDAO.save(n);

    try {
        PrintWriter out = response.getWriter();
        out.write("success");
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

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  a2  s  . co  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:javax.portlet.tck.portlets.AddlRequestTests_SPEC2_11_ResourceReq.java

@Override
public void render(RenderRequest portletReq, RenderResponse portletResp) throws PortletException, IOException {

    long tid = Thread.currentThread().getId();
    portletReq.setAttribute(THREADID_ATTR, tid);

    PrintWriter writer = portletResp.getWriter();

    writer.write("<div id=\"AddlRequestTests_SPEC2_11_ResourceReq\">no resource output.</div>\n");
    ResourceURL resurl = portletResp.createResourceURL();
    resurl.setCacheability(PAGE);/*from w  w  w .j a va  2 s  .  c o m*/
    writer.write("<script>\n");
    writer.write("(function () {\n");
    writer.write("   var xhr = new XMLHttpRequest();\n");
    writer.write("   xhr.onreadystatechange=function() {\n");
    writer.write("      if (xhr.readyState==4 && xhr.status==200) {\n");
    writer.write(
            "         document.getElementById(\"AddlRequestTests_SPEC2_11_ResourceReq\").innerHTML=xhr.responseText;\n");
    writer.write("      }\n");
    writer.write("   };\n");
    writer.write("   xhr.open(\"GET\",\"" + resurl.toString() + "\",true);\n");
    writer.write("   xhr.send();\n");
    writer.write("})();\n");
    writer.write("</script>\n");
}

From source file:de.xwic.appkit.core.remote.server.RemoteFileAccessHandler.java

/**
 * @param pp/*from w  w w . j a  v a2  s . com*/
 * @param resp
 * @return
 * @throws TransportException
 */
void upload(final IParameterProvider pp, final HttpServletResponse resp) throws TransportException {
    Map<String, UploadFile> files = pp.getFiles();
    UploadFile uploadFile = files.get(PARAM_FH_STREAM);
    if (files.size() != 1 || uploadFile == null) {
        throw new InvalidRequestException();
    }
    String name = uploadFile.getName();
    InputStream in = null;
    OutputStream out = null;
    File file = null;
    try {
        String newFilePath = getNewFilePath(pp, name);
        file = new File(newFilePath);
        in = uploadFile.getInputStream();
        File parent = file.getParentFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }
        out = new FileOutputStream(file);
        IOUtils.copy(in, out);
        int storeFile = DAOSystem.getFileHandler().storeFile(newFilePath);
        PrintWriter pwOut = resp.getWriter();
        pwOut.write(String.valueOf(storeFile));
        pwOut.close();
    } catch (IOException e) {
        throw new InvalidRequestException(e);
    } finally {
        UStream.close(in, out);
        uploadFile.destroy();
        if (file != null && file.exists()) {
            file.delete();
        }
    }
}

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

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

    // get the categoryId
    String categoryId = request.getParameter("id");

    List<PsTag> tags = tagDAO.selectTopTags(Integer.parseInt(categoryId.trim()), 20);

    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setIgnoreDefaultExcludes(false);
    jsonConfig.setExcludes(new String[] { "psItems" });

    JSONArray jsonArray = JSONArray.fromObject(tags, jsonConfig);

    PrintWriter out = response.getWriter();

    out.write(jsonArray.toString());
    out.flush();/* w  w  w .j av a 2  s.c om*/
    out.close();

}

From source file:com.meltmedia.cadmium.servlets.guice.CadmiumListener.java

public final static Injector graphGood(File file, Injector inj) {
    try {/* ww  w  .ja v a  2s.  c om*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintWriter out = new PrintWriter(baos);

        Injector injector = Guice.createInjector(new GrapherModule(), new GraphvizModule());
        GraphvizRenderer renderer = injector.getInstance(GraphvizRenderer.class);
        renderer.setOut(out).setRankdir("TB");

        injector.getInstance(InjectorGrapher.class).of(inj).graph();

        out = new PrintWriter(file, "UTF-8");
        String s = baos.toString("UTF-8");
        s = fixGrapherBug(s);
        s = hideClassPaths(s);
        out.write(s);
        out.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return inj;
}

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  w  w . j  a v  a  2 s.  c om*/

    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.st.qunar.order.web.order.OrderController.java

@RequestMapping(value = "export")
public void mockQnOrderExportServer(HttpServletResponse resp) throws IOException {
    resp.setCharacterEncoding("UTF-8");
    PrintWriter pw = resp.getWriter();
    String xml = FileUtils.readFileToString(new File("qn?50?.xml"));
    System.out.println("getFile:" + xml);
    pw.write(xml);
    pw.close();// w  w w.ja va  2  s.  c  o  m
}

From source file:edu.vt.vbi.patric.portlets.DataLanding.java

protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {

    response.setContentType("text/html");
    String windowID = request.getWindowID();
    PortletRequestDispatcher prd;//ww  w .  jav  a2  s.  c o  m

    if (windowID.indexOf("Genomes") >= 1) {
        JSONObject jsonData = readJsonData(request, JsonDataRoot + "genomes.json");
        request.setAttribute("jsonData", jsonData);
        request.setAttribute("ftpUrl", ftpUrl);

        response.setTitle("Genomes");
        prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/Genomes.jsp");
        prd.include(request, response);
    } else if (windowID.indexOf("GenomicFeatures") >= 1) {
        JSONObject jsonData = readJsonData(request, JsonDataRoot + "features.json");
        request.setAttribute("jsonData", jsonData);
        request.setAttribute("ftpUrl", ftpUrl);

        response.setTitle("Features");
        prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/GenomicFeatures.jsp");
        prd.include(request, response);
    } else if (windowID.indexOf("SpecialtyGenes") >= 1) {
        JSONObject jsonData = readJsonData(request, JsonDataRoot + "specialtygenes.json");
        request.setAttribute("jsonData", jsonData);

        response.setTitle("Specialty Genes");
        prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/SpecialtyGenes.jsp");
        prd.include(request, response);
    } else if (windowID.indexOf("AntibioticResistance") >= 1) {
        JSONObject jsonData = readJsonData(request, JsonDataRoot + "antibioticresistance.json");
        request.setAttribute("jsonData", jsonData);

        response.setTitle("Antibiotic Resistance");
        prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/AntibioticResistance.jsp");
        prd.include(request, response);
    } else if (windowID.indexOf("ProteinFamilies") >= 1) {
        JSONObject jsonData = readJsonData(request, JsonDataRoot + "proteinfamilies.json");
        request.setAttribute("jsonData", jsonData);
        request.setAttribute("ftpUrl", ftpUrl);

        response.setTitle("Protein Families");
        prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/ProteinFamilies.jsp");
        prd.include(request, response);
    } else if (windowID.indexOf("Transcriptomics") >= 1) {
        JSONObject jsonData = readJsonData(request, JsonDataRoot + "transcriptomics.json");
        request.setAttribute("jsonData", jsonData);

        response.setTitle("Transcriptomics");
        prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/Transcriptomics.jsp");
        prd.include(request, response);
    } else if (windowID.indexOf("Proteomics") >= 1) {
        JSONObject jsonData = readJsonData(request, JsonDataRoot + "proteomics.json");
        request.setAttribute("jsonData", jsonData);

        response.setTitle("Proteomics");
        prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/Proteomics.jsp");
        prd.include(request, response);
    } else if (windowID.indexOf("PPInteractions") >= 1) {
        JSONObject jsonData = readJsonData(request, JsonDataRoot + "ppinteractions.json");
        request.setAttribute("jsonData", jsonData);

        response.setTitle("Protein Protein Interactions");
        prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/PPInteractions.jsp");
        prd.include(request, response);
    } else if (windowID.indexOf("Pathways") >= 1) {
        JSONObject jsonData = readJsonData(request, JsonDataRoot + "pathways.json");
        request.setAttribute("jsonData", jsonData);
        request.setAttribute("ftpUrl", ftpUrl);

        response.setTitle("Pathways");
        prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/data_landing/Pathways.jsp");
        prd.include(request, response);
    } else {
        PrintWriter writer = response.getWriter();
        writer.write(" ");
        writer.close();
    }
}

From source file:eu.smeny.jpapercut.smtp.MailServer.java

private void refuseConnection(Socket client) {
    try {//from w  w w .  ja  v  a  2s.  c  o m
        OutputStream output = client.getOutputStream();
        PrintWriter writer = new PrintWriter(output);
        String hostname = retrieveHostname();
        writer.write("421 " + hostname + " Service not available, too much connections");
        writer.flush();
        client.close();
    } catch (IOException ioe) {
        logger.error("IO Error while refusing connection", ioe);
    }
}