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:net.sourceforge.fenixedu.presentationTier.servlets.filters.JerseyOAuth2Filter.java

private static boolean sendError(final HttpServletResponse response, String error, String errorDescription)
        throws IOException, ServletException {
    OAuthResponse errorResponse;/*from   w  w w . j av  a 2 s  .c  om*/
    try {
        errorResponse = new OAuthErrorResponseBuilder(401).setError(error).setErrorDescription(errorDescription)
                .buildJSONMessage();
        response.setContentType("application/json; charset=UTF-8");
        response.setStatus(errorResponse.getResponseStatus());
        PrintWriter pw = response.getWriter();
        pw.print(errorResponse.getBody());
        return false;
    } catch (OAuthSystemException e) {
        throw new ServletException(e);
    }
}

From source file:Main.java

public static int outputNode(Node outputNode, PrintWriter outputWriter, int curPos) {
    NodeList nodes = outputNode.getChildNodes();
    int curNodeNum;
    if (outputNode.getNodeType() == Node.TEXT_NODE) {
        outputWriter.print(outputNode.getNodeValue());
    } else {//from   ww w  .ja  v  a2s.co  m
        if (outputNode.getNodeName().equals("p")) {
            outputWriter.println();
        }

        for (curNodeNum = 0; curNodeNum < nodes.getLength(); curNodeNum++) {
            Node curNode = nodes.item(curNodeNum);
            curPos = outputNode(curNode, outputWriter, curPos);
        }

    }
    return (curPos);
}

From source file:com.google.walkaround.wave.server.servlet.ServletUtil.java

/**
 * Writes the string to the print writer according to the protocol the client
 * expects./*from  w ww.  ja  v a  2 s .  com*/
 *
 * @param w
 * @param str must be valid JSON
 */
public static void writeJsonResult(PrintWriter w, String str) {
    try {
        assert new JSONObject(str) != null;
    } catch (JSONException e) {
        throw new IllegalArgumentException("Bad JSON: " + str, e);
    }

    w.print(SharedConstants.XSSI_PREFIX + "(" + str + ")");
}

From source file:app.NotificationJSONizer.java

public static void jsonize(ArrayList<backend.Notification> notis, PrintWriter out) {
    JSONArray a = new JSONArray();
    notis.stream().forEach((noti) -> {
        JSONObject o = noti.jsonize();//from   w w w.  j  a  v a2s.  c  o m
        o.put("type", noti.get_type().toString());
        a.add(o);
    });

    out.print(a.toString());
}

From source file:Main.java

/** 
 * Write the <code>Document</code> in memory out to a standard XML file.
 * @param  doc  the <code>Document</code> object for the XML file to list
 * @param  strFilePath  the XML file to write to
 * @throws custom custom exception if file is not writeable
 * @throws ioe IOException if an error occurs on file creation
 * @throws fnfe FileNotFoundException if PrintWriter constructor fails
 *///  www .  j  a va 2 s.  co  m
public static void WriteXMLFile2(Document doc, String strFilePath) throws Exception {
    // open file for writing
    File file = new File(strFilePath);

    // ensure that file is writeable
    try {
        file.createNewFile();
        if (!file.canWrite()) {
            throw new Exception("FileNotWriteable");
        }
    } catch (IOException ioe) {
        throw ioe;
    }

    // create a PrintWriter to write the XML file to
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(file);
    } catch (FileNotFoundException fnfe) {
        throw fnfe;
    }

    // write out the serialized form
    pw.print(getXMLListing(doc));
    pw.close();
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.Util.java

public static void errordeRespuesta(ArrayList r, PrintWriter out) {
    System.err.print(/*from   w  ww . ja v  a 2  s . c o m*/
            "Respuesta inesperada del control !! r.size:" + r.size() + "|r0:" + r.get(0) + "|r1:" + r.get(1));
    JSONObject obj = new JSONObject();
    obj.put("isError", true);
    obj.put("errorDescrip", "Error inesperado");
    out.print(obj);
}

From source file:Main.java

public static void hexaDump(OutputStream outStream, byte[] data, int len) {

    //if (desc.compareToIgnoreCase("outflow")==0) return ;

    PrintWriter out = new PrintWriter(outStream, true);
    char[] tmpStrBuf = new char[16];
    int index = 0;

    for (int i = 0; i < len; i++) {

        index = (i + 1) % 16;//  ww w . ja v a 2  s  . co m

        out.print(byteToHexa(data[i]) + " ");

        if ((data[i] >= ' ') && (data[i] <= 'z'))
            tmpStrBuf[i % 16] = (char) data[i];
        else
            tmpStrBuf[i % 16] = '.';

        if (index == 0) {
            out.println("          " + new String(tmpStrBuf, 0, 16));
            for (int j = 0; j < 16; j++)
                tmpStrBuf[j] = (char) 0x00;
        }

    }

    if (index != 0) {
        for (int i = 0; i < 16 - index; i++)
            out.print("  " + " ");
        out.println("          " + new String(tmpStrBuf, 0, index));
    }
}

From source file:eu.pawelsz.apache.beam.coders.TupleCoderGenerator.java

private static void writeRegistration(PrintWriter w) {
    w.print(HEADER);

    w.println("package " + PACKAGE + ";");
    w.println("");
    w.println("import org.apache.beam.sdk.Pipeline;");
    w.println("import org.apache.beam.sdk.coders.CoderRegistry;");
    for (int i = FIRST; i < LAST; i++) {
        w.println("import org.apache.flink.api.java.tuple.Tuple" + i + ";");
    }/*from  w w  w  .j  a  va2 s .c o m*/
    w.println("");
    w.println("public class RegisterTupleCoders {");
    w.println("    public static void run(Pipeline p) {");
    w.println("        CoderRegistry cr = p.getCoderRegistry();");
    for (int i = FIRST; i < LAST; i++) {
        w.println("        cr.registerCoder(Tuple" + i + ".class, Tuple" + i + "Coder.class);");
    }
    w.println("    }");
    w.println("}");
    w.println("");
}

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

protected static void obtenerTotalUsuarios(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    int numC = CtrlAdmin.obtenerTotalUsuarios();
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    obj.put("total", numC);
    out.print(obj);
}

From source file:com.ikanow.aleph2.data_model.utils.ProcessUtils.java

/**
 * Writes pid=date out to /app/aleph2/pid_manager/bucket._id/application_name
 * /*from   ww w  .  ja  va  2  s .  c  o m*/
 * @param application_name
 * @param bucket
 * @param aleph_root_path
 * @param pid
 * @param date
 * @throws IOException 
 */
private static void storePid(final String application_name, final DataBucketBean bucket,
        final String aleph_root_path, final String pid, final long date) throws IOException {
    final File file = new File(
            aleph_root_path + PID_MANAGER_DIR_NAME + bucket._id() + File.separator + application_name);
    file.getParentFile().mkdirs();
    if (file.exists())
        file.delete();
    file.createNewFile();
    final PrintWriter pw = new PrintWriter(file);
    pw.print(pid + "=" + date);
    pw.close();
}