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:freeipa.client.JSONRequestServlet.java

private void testRequest(final String jsonRequest, final PrintWriter writer) {

    writer.print(jsonRequest);
    writer.println("'</p>");
    URL ipaUrl;/*from   w  ww  .  j  a  v  a2 s.com*/
    byte[] token = new byte[0];
    Subject subject = new Subject();
    try {
        ipaUrl = new URL("https://vm-144.idm.lab.eng.brq.redhat.com/ipa/json");

        KerberosHttpClient ipaClient = new KerberosHttpClient(token, subject);
        String response = ipaClient.makeRequest(ipaUrl, httpClient, jsonRequest);
        writer.println(response);
    } catch (Exception e) {
        writer.println("<h5>Failed!</h5>");
        writer.print("<p>");
        writer.print(e.getClass().getName());
        writer.print(" - ");
        writer.print(e.getMessage());
        writer.println("</p>");

        log.error("testDomain Failed", e);
    }

}

From source file:net.psexton.authzwriter.Main.java

/**
 * Given a String body and a file path, writes fileBody to filePath
 * @param fileBody/*from w w w.  j  a v  a  2 s .  c o m*/
 * @param filePath 
 */
private void writeToFile(String fileBody, String filePath) {
    File file = new File(filePath);
    try {
        PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
        writer.print(fileBody);
        writer.flush();
        writer.close();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:cat.calidos.morfeu.webapp.GenericHttpServlet.java

protected void writeTo(String content, String contentType, HttpServletResponse resp) throws IOException {

    // to simulate slowness
    //   try {//from  w  w w.  j a  v a 2 s  .c o m
    //      Thread.sleep(20000);
    //   } catch (InterruptedException e) {
    //      // TODO Auto-generated catch block
    //      e.printStackTrace();
    //   }
    resp.setContentType(contentType);
    PrintWriter out = resp.getWriter();
    out.print(content);
    out.close();

}

From source file:com.diversityarrays.dalclient.DalUtil.java

public static void showXmlResult(String xml, Writer w) {
    if (looksLikeDoctype(xml)) {
        // just print it!
        PrintWriter pw = new PrintWriter(w);
        pw.print(xml);
        pw.close();/*from   www .j a va 2  s. c om*/
    } else {
        try {
            writeXmlResult(xml, w);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.webguitoolkit.ui.controls.chart.Chart.java

/**
 * only generating the HTML to hold the picture and the image map
 *//*from  w w w. ja  va2 s  .  c o m*/
protected void endHTML(PrintWriter out) {
    out.print("<DIV " + JSUtil.atId(id4Map()) + ">");
    out.print("</DIV>");
    // here goes the picture, src will be set later
    // MH 06.05.2009: do not leave src empty
    // empty src caused problems in SupplyCare and double initial load
    out.print("<IMG " + JSUtil.atId(id4Img()) + " src='images/1.gif' border=\"0\" />");

}

From source file:com.ettrema.http.caldav.demo.TFolderResource.java

@Override
public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType)
        throws IOException, NotAuthorizedException, BadRequestException {
    PrintWriter pw = new PrintWriter(out);
    pw.print("<html><body>");
    pw.print("<h1>" + this.getName() + "</h1>");
    pw.print("<p>" + this.getClass().getCanonicalName() + "</p>");
    doBody(pw);/*from   w  w w . j a va2s.  c o  m*/
    pw.print("</body>");
    pw.print("</html>");
    pw.flush();
}

From source file:bookUtilities.PopulateMyBooksServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request servlet request/*from ww  w .  j av a2  s .co  m*/
 * @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 {
    response.setContentType("text/html;charset=UTF-8");
    String email;
    email = (String) request.getSession().getAttribute("email");
    JSONArray fileTypes = new JSONArray();
    JSONArray userBooks = getUserBooks(email, fileTypes);
    JSONArray infoToPush = new JSONArray();
    infoToPush.add(userBooks);
    infoToPush.add(fileTypes);
    PrintWriter printout = response.getWriter();
    printout.print(infoToPush);
    printout.flush();
}

From source file:fr.natoine.servletTag.ServletTag.java

private void toDo(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getParameter("type") != null) {
        String type = request.getParameter("type");
        List<Tag> tags = null;
        if (type.equalsIgnoreCase("tag"))
            tags = daoTag.retrieveAllTag();
        else if (type.equalsIgnoreCase("judgment"))
            tags = daoTag.retrieveAllJudgment();
        else if (type.equalsIgnoreCase("mood"))
            tags = daoTag.retrieveAllMood();
        else if (type.equalsIgnoreCase("domain"))
            tags = daoTag.retrieveAllDomain();
        if (tags != null && tags.size() > 0) {
            JSONArray jsonarray = new JSONArray();
            for (Tag tag : tags) {
                JSONObject jsonobj = new JSONObject();
                try {
                    jsonobj.put("id", tag.getId());
                    jsonobj.put("label", tag.getLabel());
                    jsonarray.put(jsonobj);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }/*from ww w.  jav a2  s .  com*/
            }
            //String liste = jsonarray.toString();
            JSONObject list_obj = new JSONObject();
            try {
                list_obj.put("liste", jsonarray);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //response.setContentType("text");
            response.setContentType("application/json");
            String liste = list_obj.toString();
            //liste = liste.replaceAll("'", "\'");
            //liste = liste.replaceAll("\"", "\\\\\"");
            //liste = liste.replaceAll("\"", "");
            PrintWriter out = response.getWriter();
            out.print(liste);
            //request.setAttribute("liste", liste);
        }
    }
    //response.setContentType("text/html");
    //RequestDispatcher _srd = this.getServletContext().getRequestDispatcher(response.encodeURL("/WEB-INF/jsp/servletTag/tagsList.jsp"));
    //_srd.include(request, response);
}

From source file:eu.vital.maps.server.servlets.KmlGenerator.java

/**
 * render some XML as a page//  www .j  a va2s .  co m
 * @param request
 * @param response
 * @throws IOException
 */
private void drawHtml(HttpServletRequest request, HttpServletResponse response) throws IOException {

    String xml = getKml(request);

    // write the html to page
    response.setContentType("text/xml");
    PrintWriter out = response.getWriter();
    out.print(xml);
}

From source file:ai.susi.server.api.aaa.AccessServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Query post = RemoteAccess.evaluate(request);
    if (post.isDoS_servicereduction() || post.isDoS_blackout()) {
        response.sendError(503, "your request frequency is too high");
        return;/*from w ww . j a  v a2 s  .  co  m*/
    } // DoS protection

    boolean anonymize = !post.isLocalhostAccess();

    String callback = post.get("callback", "");
    boolean jsonp = callback != null && callback.length() > 0;

    post.setResponse(response, "application/javascript");
    Collection<Track> tracks = DAO.access.getTracks();

    // generate json
    JSONObject json = new JSONObject(true);
    JSONArray access = new JSONArray();
    json.put("access", access);
    int maxcount = anonymize ? 100 : 1000;
    for (Track track : tracks) {
        if (anonymize && !track.get("class").equals("SearchServlet"))
            continue;
        JSONObject a = new JSONObject(true);
        for (String key : track.keySet()) {
            Object value = track.get(key);
            if (anonymize && "host".equals(key)) {
                a.put("host-anonymized", Integer.toHexString(Math.abs(value.hashCode())));
            } else {
                a.put(key, value);
            }
        }
        access.put(a);
        if (maxcount-- <= 0)
            break;
    }

    // write json
    PrintWriter sos = response.getWriter();
    if (jsonp)
        sos.print(callback + "(");
    sos.print(json.toString(2));
    if (jsonp)
        sos.println(");");
    sos.println();
    post.finalize();
}