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:forge.util.FileUtil.java

public static void writeFile(File file, String text) {
    try {// ww  w .  j a  v a 2  s . com
        PrintWriter p = new PrintWriter(file);
        p.print(text);
        p.close();
    } catch (final Exception ex) {
        throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex);
    }
}

From source file:Main.java

public static void hexaDumpHangul(OutputStream outStream, byte[] data, int len, String desc) {

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

    PrintWriter out = new PrintWriter(outStream, true);
    int index = 0;

    out.println("[[LEN=" + len + "]/[" + desc + "][" + getTime() + "]]");
    for (int i = 0; i < len; i++) {

        index = (i + 1) % 16;// w  ww . jav a2s .  c  o m

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

        if (index == 0) {
            out.println("          " + new String(data, (i + 1) - 16, 16));
        }

    }

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

From source file:net.panthema.BispanningGame.GraphString.java

public static String write_graph(MyGraph g, Transformer<Integer, Point2D> gl) {
    ByteArrayOutputStream ba = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(ba);

    // print the vertex list

    pw.print('V');
    pw.print(g.getVertexCount());//from   ww  w .  ja v  a 2s  . c  om
    pw.print(':');

    Collection<Integer> vcoll = g.getVertices();
    ArrayList<Integer> vlist = new ArrayList<Integer>(vcoll);
    Collections.sort(vlist, new Comparator<Integer>() {
        public int compare(Integer arg0, Integer arg1) {
            return arg0 - arg1;
        }
    });

    for (Integer v : vlist) {
        pw.print('i');
        pw.print(v);

        Point2D pos = gl.transform(v);
        pw.print('x');
        pw.print((int) pos.getX());
        pw.print('y');
        pw.print((int) pos.getY());

        pw.print('/');
    }
    pw.print(';');

    // print the edge list

    pw.print('E');
    pw.print(g.getEdgeCount());
    pw.print(':');

    Collection<MyEdge> ecoll = g.getEdges();
    ArrayList<MyEdge> elist = new ArrayList<MyEdge>(ecoll);
    Collections.sort(elist, new Comparator<MyEdge>() {
        public int compare(MyEdge arg0, MyEdge arg1) {
            return arg0.id - arg1.id;
        }
    });

    for (MyEdge e : elist) {
        Integer e_x = g.getEndpoints(e).getFirst();
        Integer e_y = g.getEndpoints(e).getSecond();

        pw.print('i');
        pw.print(e.id);

        pw.print('t');
        pw.print(e_x);
        pw.print('h');
        pw.print(e_y);

        pw.print('c');
        pw.print(e.color);

        pw.print('/');
    }
    pw.print(';');

    pw.flush();

    return ba.toString();
}

From source file:de.instantouch.model.io.SnakeJSONWriter.java

private static String printtabs(PrintWriter beautyPrinter, int tabs) {
    String tabStr = "";
    for (int i = 0; i < tabs; i++) {
        beautyPrinter.print("   ");
    }//from   ww  w  .  j ava2  s .c o  m
    return tabStr;
}

From source file:com.sunway.cbm.util.ServletUtils.java

/**
 * ?xml?//from ww w . ja v a2 s . c  o m
 * 
 * @param response
 * @param object
 */
public static void responseXml(HttpServletResponse response, String xml) {
    try {
        //         response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");
        logger.debug(xml);
        //         response.getWriter().write(xml);
        //         response.getWriter().flush();
        //         response.getWriter().close();
        PrintWriter out = response.getWriter();
        out.print(xml);
        out.close();
    } catch (IOException e) {
        logger.debug(e.toString());
    }
}

From source file:Main.java

/**
 * Encode a String for XML output, displaying it to a PrintWriter.
 * The String to be encoded is displayed, except that
 * special characters are converted into entities.
 * @param input a String to convert.//from ww  w  .  ja  v a  2  s .c o  m
 * @param out a PrintWriter to which to write the results.
 */
public static void stringEncodeXML(String input, PrintWriter out) {
    for (int i = 0; i < input.length(); i++) {
        char c = input.charAt(i);
        switch (c) {
        case '<':
        case '>':
        case '"':
        case '\'':
        case '&':
        case '\t':
        case '\n':
        case '\r':
            out.print("&#" + (int) c + ";");
            break;
        default:
            out.print(c);
        }
    }
}

From source file:org.apache.asterix.api.http.server.ResultUtil.java

protected static void printFieldInternal(PrintWriter pw, String name, String value, boolean comma) {
    pw.print("\t\"");
    pw.print(name);/*from   w ww. j a  va 2s  .  com*/
    pw.print("\": ");
    pw.print(value);
    if (comma) {
        pw.print(',');
    }
    pw.print('\n');
}

From source file:com.atlassian.clover.reporters.console.ConsoleReporter.java

private static void printPcBar(PrintWriter out, String summary, float amt) {

    // pad out to 32 spaces from the left.
    int padLen = 32 - summary.length();
    out.print(String.format("%" + (padLen) + "s", " "));

    final int len = 80;
    final int pc = (int) (amt * len);
    for (int i = 0; i <= len; i++) {
        if (i < pc) {
            out.print(Color.make(" ").bg().green());
        } else {/*from  ww  w  .j  a v  a2  s.  c  o  m*/
            out.print(Color.make(" ").bg().red());
        }
    }
    out.println();
}

From source file:com.ibm.zurich.Main.java

private static void writeToFile(String s, String fileName) throws FileNotFoundException {
    PrintWriter writer = null;
    try {/*from w  ww.  j  a v a2 s  .c  o m*/
        writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8),
                true);
        writer.print(s);
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}

From source file:com.espertech.esper.epl.parse.ASTUtil.java

private static void renderNode(char[] ident, Tree node, PrintWriter printer) {
    printer.print(ident);
    if (node == null) {
        printer.print("NULL NODE");
    } else {/*from   w  ww. j  a  va  2 s  .  c om*/
        if (node instanceof ParserRuleContext) {
            ParserRuleContext ctx = (ParserRuleContext) node;
            int ruleIndex = ctx.getRuleIndex();
            String ruleName = EsperEPL2GrammarParser.ruleNames[ruleIndex];
            printer.print(ruleName);
        } else {
            TerminalNode terminal = (TerminalNode) node;
            printer.print(terminal.getSymbol().getText());
            printer.print(" [");
            printer.print(terminal.getSymbol().getType());
            printer.print("]");
        }

        if (node instanceof ParseTree) {
            ParseTree parseTree = (ParseTree) node;
            if (parseTree.getText() == null) {
                printer.print(" (null value in text)");
            } else if (parseTree.getText().contains("\\")) {
                int count = 0;
                for (int i = 0; i < parseTree.getText().length(); i++) {
                    if (parseTree.getText().charAt(i) == '\\') {
                        count++;
                    }
                }
                printer.print(" (" + count + " backlashes)");
            }
        }
    }
    printer.println();
}