Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.PrintWriter;

public class Main {
    /**
     * Write characters. Character data is properly escaped.
     * 
     * @param out
     *            The writer.
     * @param value
     *            The text as a strng.
     */
    public static void writeCharacters(PrintWriter out, String value) {
        writeCharacters(out, value.toCharArray(), 0, value.length());
    }

    /**
     * Write characters. Character data is properly escaped.
     * 
     * @param out
     *            The writer.
     * @param ch
     *            The character array.
     * @param start
     *            Start position.
     * @param length
     *            Substring length.
     */
    public static void writeCharacters(PrintWriter out, char[] ch, int start, int length) {
        for (int j = start; j < start + length; j++) {
            char c = ch[j];
            if (c == '&') {
                out.print("&amp;");
            } else if (c == '"') {
                out.print("&quot;");
            } else if (c == '<') {
                out.print("&lt;");
            } else if (c == '>') {
                out.print("&gt;");
            } else if (c == '\'') {
                out.print("&apos;");
            } else {
                out.print(c);
            }
        }
    }
}