Example usage for java.io PrintWriter print

List of usage examples for java.io PrintWriter print

Introduction

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

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:com.qperior.gsa.oneboxprovider.QPOneBoxProviderServlet.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String resString = "Method 'doPost' is not supported!";
    this.log.warn(resString);

    // Defines response MIME type
    response.setContentType("text/xml");
    // Wirte response back as XML string
    PrintWriter out = response.getWriter();
    out.print(resString);
    out.close();//from w w w  .  j av a2 s.  c o  m
}

From source file:com.ss.Controller.T4uGetAllScheduleServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w  w w. j ava 2 s . c om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    int scheduleId = Integer.parseInt(request.getParameter("scheduleId"));
    T4uSchedule t4uSchedule = null;
    t4uSchedule = T4uScheduleDAO.getScheduleById(scheduleId);
    JSONObject jsonObjectMary = new JSONObject(t4uSchedule);
    response.setContentType("application/json");
    // Get the printwriter object from response to write the required json object to the output stream      
    PrintWriter out = response.getWriter();
    // Assuming your json object is **jsonObject**, perform the following, it will return your json object  
    out.print(jsonObjectMary);
    out.flush();
}

From source file:org.freelectron.leobel.testlwa.models.AlertsFileDataStore.java

@Override
public synchronized void writeToDisk(final List<Alert> alerts, final ResultListener listener) {
    sExecutor.execute(new Runnable() {
        @Override/*from ww w .j  a va2s  . c  o  m*/
        public void run() {
            ObjectWriter writer = ObjectMapperFactory.getObjectWriter();
            PrintWriter out = null;
            try {
                out = new PrintWriter(ALARM_FILE);
                out.print(writer.writeValueAsString(alerts));
                out.flush();
                listener.onSuccess();
            } catch (IOException e) {
                Log.d("Failed to write to disk", e.getMessage(), e);
                listener.onFailure();
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    });
}

From source file:eu.stratosphere.client.web.PactJobJSONServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("application/json");

    String jobName = req.getParameter(JOB_PARAM_NAME);
    if (jobName == null) {
        LOG.warn("Received request without job parameter name.");
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;/*from   w w  w.  j a v  a  2  s  . c  om*/
    }

    // check, if the jar exists
    File jarFile = new File(jobStoreDirectory, jobName);
    if (!jarFile.exists()) {
        LOG.warn("Received request for non-existing jar file.");
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    // create the pact plan
    PackagedProgram pactProgram;
    try {
        pactProgram = new PackagedProgram(jarFile, new String[0]);
    } catch (Throwable t) {
        LOG.info("Instantiating the PactProgram for '" + jarFile.getName() + "' failed.", t);
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        resp.getWriter().print(t.getMessage());
        return;
    }

    String jsonPlan = null;
    String programDescription = null;

    try {
        jsonPlan = pactProgram.getPreviewPlan();
    } catch (Throwable t) {
        LOG.error("Failed to create json dump of pact program.", t);
    }

    try {
        programDescription = pactProgram.getDescription();
    } catch (Throwable t) {
        LOG.error("Failed to create description of pact program.", t);
    }

    if (jsonPlan == null && programDescription == null) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;
    } else {
        resp.setStatus(HttpServletResponse.SC_OK);
        PrintWriter wrt = resp.getWriter();
        wrt.print("{ \"jobname\": \"");
        wrt.print(jobName);
        if (jsonPlan != null) {
            wrt.print("\", \"plan\": ");
            wrt.println(jsonPlan);
        }
        if (programDescription != null) {
            wrt.print(", \"description\": \"");
            wrt.print(escapeString(programDescription));
            wrt.print("\"");
        }

        wrt.println("}");
    }
}

From source file:DataTextWriter.java

/**
 * This method creates a flat file containing the data added to this DataTextWriter.
 * @param sFilename The name of flat file to create.
 *//*from  www.java 2 s .  c om*/
public void writeFile(String sFilename) throws Exception {
    try {
        FileOutputStream fos = new FileOutputStream(sFilename);
        PrintWriter pw = new PrintWriter(fos);
        pw.print(getText());
        pw.close();
        fos.close();
    } catch (Exception e) {
        throw new Exception(e.getMessage());
    }
}

From source file:com.amazon.alexa.avs.AlertsFileDataStore.java

@Override
public synchronized void writeToDisk(List<Alert> alerts, final ResultListener listener) {
    sExecutor.execute(new Runnable() {
        @Override//from  www  .  jav a  2s .  c  o  m
        public void run() {
            ObjectWriter writer = ObjectMapperFactory.getObjectWriter();
            PrintWriter out = null;
            try {
                out = new PrintWriter(ALARM_FILE);
                out.print(writer.writeValueAsString(alerts));
                out.flush();
                listener.onSuccess();
            } catch (IOException e) {
                log.error("Failed to write to disk", e);
                listener.onFailure();
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    });
}

From source file:com.doculibre.constellio.feedprotocol.FeedServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = null;
    try {//from  w  w  w.j av a  2  s .c o  m
        out = response.getWriter();
        out.print(ONLINE);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

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

public void saveAndReturnUrlToClient(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    // Parse the request
    try {//from   ww  w  . j a  v  a  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:org.emr.controller.ApplicationController.java

@RequestMapping(value = "/do")
public ModelAndView getTest(HttpServletRequest request, HttpServletResponse response)
        throws JSONException, IOException {
    System.out.println("ApplicationController : do.htm x`");
    JSONObject requestParamMap = null;// w  w w. j  a  v  a 2  s  .  co  m
    /*
     * get parameters from request 
     */
    requestParamMap = getRequestParamMap(request);
    if (requestParamMap != null) {
        if (requestParamMap.has("REQID")) {
            System.out.println("req param map : " + requestParamMap.getString("REQID"));
            if (requestParamMap.getString("REQID").equals("1")) {
                System.out.println("ApplicationController : json not null : ");
                PrintWriter printWriter = response.getWriter();
                printWriter.print(((LoginBean) request.getSession().getAttribute("loginBean")).getUsername());
                printWriter.close();
                System.out.println("ApplicationController : return model and view ");
                return null;
            }
        }
    }
    System.out.println("request for test.htm ");
    ModelAndView mv = new ModelAndView();
    mv.setViewName("index.html");
    return mv;
}

From source file:ch.cyberduck.cli.Console.java

public void printf(final String format, Object... args) {
    if (StringUtils.isEmpty(format)) {
        return;//from  w  w  w .jav a  2s  . c o m
    }
    try {
        lock.acquire();
        if (console != null) {
            final PrintWriter writer = console.writer();
            if (Arrays.asList(args).isEmpty()) {
                writer.print(format);
            } else {
                writer.printf(format, args);
            }
            writer.flush();
        } else {
            if (Arrays.asList(args).isEmpty()) {
                out.printf(format);
            } else {
                out.printf(format, args);
            }
            out.flush();
        }
    } catch (InterruptedException e) {
        //
    } finally {
        lock.release();
    }
}