Java BigInteger Calculate writeField(String tagName, BigInteger value, PrintWriter writer, int indent)

Here you can find the source of writeField(String tagName, BigInteger value, PrintWriter writer, int indent)

Description

adds a child to the element with the given name and the given value. If value is null, nothing is done

License

BSD License

Parameter

Parameter Description
elem a parameter
tagName a parameter
value -- non-null value

Declaration

public static void writeField(String tagName, BigInteger value, PrintWriter writer, int indent) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import java.io.PrintWriter;
import java.math.BigInteger;

public class Main {
    /**//from   w  w w  . ja v  a2  s .  c  om
     * adds a child to the element with the given name and the given value. If
     * value is null, nothing is done
     * @param elem
     * @param tagName
     * @param value -- non-null value
     */
    public static void writeField(String tagName, BigInteger value, PrintWriter writer, int indent) {
        if (value == null)
            return;
        writeField(tagName, value.toString(), writer, indent);
    }

    /**
     * adds a child to the element with the given name and the given value. If
     * value is null, nothing is done
     * @param elem
     * @param tagName
     * @param value
     */
    public static void writeField(String tagName, Boolean value, PrintWriter writer, int indent) {
        if (value == null)
            return;
        writeField(tagName, value.toString(), writer, indent);
    }

    /**
     * adds a child to the element with the given name and the given value. If
     * value is null, nothing is done
     * @param elem
     * @param tagName
     * @param value
     */
    public static void writeField(String tagName, Double value, PrintWriter writer, int indent) {
        if (value == null)
            return;
        writeField(tagName, value.toString(), writer, indent);
    }

    /**
     * adds a child to the element with the given name and the given value. If
     * value is null, nothing is done
     * @param elem
     * @param tagName
     * @param value
     */
    public static void writeField(String tagName, Integer value, PrintWriter writer, int indent) {
        if (value == null)
            return;
        writeField(tagName, value.toString(), writer, indent);
    }

    /**
     * adds a child to the element with the given name and the given value. If
     * value is null, nothing is done
     * @param elem
     * @param tagName
     * @param value
     */
    public static void writeField(String tagName, String value, PrintWriter writer, int indent) {
        if (value == null)
            return;
        writeIndent(writer, indent);
        writeStartTag(tagName, writer, indent, false);
        writer.print(normalizeTextToHTML(value));
        writeEndTag(tagName, writer, -1, true);
    }

    static public void writeIndent(PrintWriter writer, int indent) {
        if (true)
            return;
        for (int i = 0; i < indent; i++) {
            writer.print("\t");
        }
    }

    static public void writeStartTag(String tag, String attributes, PrintWriter writer, int indent) {
        writeIndent(writer, indent);
        writer.print("<" + tag);
        if (attributes != null) {
            writer.print(" " + attributes);
        }
        writer.println(" >");
    }

    static public void writeStartTag(String tag, PrintWriter writer, int indent) {
        writeStartTag(tag, writer, indent, true);
    }

    static public void writeStartTag(String tag, PrintWriter writer, int indent, boolean newLine) {
        writeIndent(writer, indent);
        writer.print("<" + tag + ">");
        if (newLine) {
            writer.println();
        }
    }

    /** replace &, <, > and ", \t, \n for &amp;, &lt; &gt;, &guot; &amp;#52;t, &amp;#52;t**/
    public static String normalizeTextToHTML(String text) {
        if (text == null) {
            return text;
        } else {
            return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"",
                    "&quot;");
            //.replaceAll("\t","&amp;#52;t")
            //.replaceAll("\n","&amp;#52;n");
        }
    }

    static public void writeEndTag(String tag, PrintWriter writer, int indent) {
        writeEndTag(tag, writer, indent, true);
    }

    static public void writeEndTag(String tag, PrintWriter writer, int indent, boolean newLine) {
        writeIndent(writer, indent);
        writer.print("</" + tag + ">");
        if (newLine) {
            writer.println();
        }
    }
}

Related

  1. writeBigInteger(BigInteger integer, DataOutputStream out)
  2. writeBigInteger(BigInteger m, int n, OutputStream os)
  3. writeBigInteger(ByteArrayOutputStream baos, BigInteger bi)
  4. writeBigInteger(ByteArrayOutputStream stream, BigInteger num)
  5. writeBigInteger(OutputStream output, BigInteger value)
  6. writeLuposBigInteger(final BigInteger value, final int numberOfBits, final OutputStream os)
  7. writeMPI(BigInteger num, OutputStream out)