Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.io.*;

public class Main {
    private static String __htmlTextToPlainText(String text) {
        text = text.replace("<", "&lt;");
        text = text.replace(">", "&gt;");
        return text;
    }

    private static void __htmlTextToPlainText(String text, Writer writer) throws IOException {
        StringReader sr = new StringReader(text);
        char[] chunk = new char[1024 * 64];

        while (true) {
            int charsRead = sr.read(chunk, 0, chunk.length);
            if (charsRead <= 0)
                break;

            int lastPos = 0;
            for (int i = 0; i < chunk.length; i++) {
                if (chunk[i] == '<') {
                    writer.write(chunk, lastPos, i - lastPos);
                    writer.write("&lt;");
                    lastPos = i + 1;
                } else if (chunk[i] == '>') {
                    writer.write(chunk, lastPos, i - lastPos);
                    writer.write("&gt;");
                    lastPos = i + 1;
                }
            }
            if (lastPos < chunk.length) {
                writer.write(chunk, lastPos, chunk.length - lastPos);
            }
        }
    }
}