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.discovery.darchrow.http.ResponseUtil.java

/**
 * ./*from w  w  w.j  av  a2s  .c  om*/
 *
 * @param response
 *            HttpServletResponse
 * @param content
 *            
 * @param contentType
 *            the content type
 * @param characterEncoding
 *            the character encoding
 * @throws UncheckedIOException
 *             the unchecked io exception
 * @see javax.servlet.ServletResponse#getWriter()
 * @see java.io.PrintWriter#print(Object)
 * @see java.io.PrintWriter#flush()
 * @since 1.0.9
 */
public static void write(HttpServletResponse response, Object content, String contentType,
        String characterEncoding) throws UncheckedIOException {
    try {
        //? ? getWriter?
        if (Validator.isNotNullOrEmpty(contentType)) {
            response.setContentType(contentType);
        }
        if (Validator.isNotNullOrEmpty(characterEncoding)) {
            response.setCharacterEncoding(characterEncoding);
        }

        PrintWriter printWriter = response.getWriter();
        printWriter.print(content);
        printWriter.flush();

        //http://www.iteye.com/problems/56543
        //tomcatjetty?? printWriter.close();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:com.zimbra.common.util.TemplateCompiler.java

private static void printDataLine(PrintWriter out, String s) {
    out.print("\tbuffer[_i++] = data");
    Matcher part = RE_PARAM_PART.matcher(s);
    while (part.find()) {
        String name = part.group(1);
        String args = part.group(2);

        out.print("[\"");
        out.print(name);//from  w  w  w .  ja  v a2s  .  co m
        out.print("\"]");
        if (args != null) {
            out.print(args);
        }
    }
    out.println(";");
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void eliminarConvocatoria(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.eliminarConvocatoria(Integer.parseInt(request.getParameter("1"))); // id

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);//from  w w  w . j  a va  2  s. c  o m
    } else
        Util.errordeRespuesta(r, out);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void eliminarTaller(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.eliminarTaller(Integer.parseInt(request.getParameter("1"))); // id

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);/*from w w  w . ja  v a  2s.c om*/
    } else
        Util.errordeRespuesta(r, out);
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.writers.HtmlWriter.java

public static List<String> renderDocumentToHtmlParagraphs(JCas jCas) {
    List<String> result = new ArrayList<>();

    // iterate over paragraphs
    for (Paragraph p : JCasUtil.select(jCas, Paragraph.class)) {
        StringWriter writer = new StringWriter();
        PrintWriter out = new PrintWriter(writer);
        // iterate over tokens
        for (Token t : JCasUtil.selectCovered(jCas, Token.class, p)) {
            // print token's preceding space if needed
            if (ArgumentPrinterUtils.hasSpaceBefore(t, jCas)) {
                out.print(" ");
            }/* ww  w.j a v  a  2 s.c  o  m*/

            // does an argument concept begin here?
            ArgumentComponent argumentConcept = ArgumentPrinterUtils.argAnnotationBegins(t, jCas);
            if (argumentConcept != null) {
                out.printf("<span class=\"component\">%s:</span> <span class=\"%s\">",
                        argumentConcept.getClass().getSimpleName().toLowerCase(),
                        argumentConcept.getClass().getSimpleName().toLowerCase());
            }

            Sentence sentence = ArgumentPrinterUtils.sentenceStartsOnToken(t);
            if (sentence != null) {
                out.printf("<span class=\"sentence\">S%d</span>",
                        ArgumentPrinterUtils.getSentenceNumber(sentence, jCas));
            }

            // print token
            out.print(t.getCoveredText());

            // does an argument concept end here?
            if (ArgumentPrinterUtils.argAnnotationEnds(t, jCas)) {
                out.print("</span>");
            }
        }

        result.add(writer.toString());
    }

    return result;
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void crearConvocatoria(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.crearConvocatoria(request.getParameter("1"), // nombre
            request.getParameter("2"), // descripcin
            request.getParameter("4"), // fin
            Integer.parseInt(request.getParameter("6")) // cupos
    );/*from w w  w  .j ava  2  s . c  om*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void actualizarConvocatoria(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.actualizarConvocatoria(Integer.parseInt(request.getParameter("0")), // id
            request.getParameter("1"), // nombre
            request.getParameter("2"), // descripcin
            request.getParameter("4"), // fin
            Integer.parseInt(request.getParameter("6")) // cupos
    );/* w w  w. j  av a2 s . co m*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:com.github.fcannizzaro.prefs.Prefs.java

/**
 * Write each change on the file//from  ww w  .  j  a  va 2s  .  c o  m
 */
private static void updateMemory() {
    try {
        PrintWriter output = new PrintWriter(new FileWriter("res/" + resource));
        output.print(json.toString());
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void crearTaller(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ArrayList r = CtrlAdmin.crearTaller(request.getParameter("1"), // nombre
            request.getParameter("2"), // descripcin
            request.getParameter("4"), // fin registro (Fecha hasta donde est permitido registrarse)
            request.getParameter("3"), // inicio del taller
            request.getParameter("4"), // fin del taller
            Integer.parseInt(request.getParameter("5")), // costo
            Integer.parseInt(request.getParameter("6")) // cupos
    );/* w ww. j  a v  a2 s.  c  o m*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void actualizarTaller(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.actualizarTaller(Integer.parseInt(request.getParameter("0")), // id
            request.getParameter("1"), // nombre
            request.getParameter("2"), // descripcin
            request.getParameter("3"), // fin registro (Fecha hasta donde est permitido registrarse)
            request.getParameter("4"), // inicio del taller
            Integer.parseInt(request.getParameter("5")), // costo
            Integer.parseInt(request.getParameter("6")) // cupos
    );/*from   w  w  w  . jav  a 2  s.  c o m*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}