Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

public class Main {
    private static final int QUOTE = 127;

    protected static byte[] parseWapTextString(ByteArrayInputStream bais) {
        assert (null != bais);

        bais.mark(1);

        int temp = bais.read();
        assert (-1 != temp);

        if (temp == QUOTE) {
            bais.mark(1);
        }

        return getWapTextString(bais);
    }

    protected static byte[] getWapTextString(ByteArrayInputStream bais) {
        assert (null != bais);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        int temp = bais.read();
        assert (-1 != temp);

        while ((-1 != temp) && ('\0' != temp)) {
            if (isText(temp)) {
                bos.write(temp);
            }
            temp = bais.read();
            assert (-1 != temp);
        }

        if (bos.size() > 0) {
            return bos.toByteArray();
        }

        return null;
    }

    protected static boolean isText(int ch) {
        return (((ch >= 32) && (ch <= 126)) || ((ch >= 128) && (ch <= 255)) || ch == '\t' || ch == '\n'
                || ch == '\r');
    }
}