Util.javaAPI DocJ2ME MIDP 2.02708Thu Nov 07 12:02:22 GMT


public abstract class Util extends Object
Contains static utility methods for IO protocol classes to use.

Fields Summary
Constructors Summary
Methods Summary
public static java.util.VectorgetCommaSeparatedValues(java.lang.String input)
Create a vector of values from a string containing comma separated values. The values cannot contain a comma. The output values will be trimmed of whitespace. The vector may contain zero length strings where there are 2 commas in a row or a comma at the end of the input string.

input input string of comma separated values
vector of string values.

        Vector output = new Vector(5, 5);
        int len;
        int start;
        int end;
        len = input.length();
        if (len == 0) {
            return output;

        for (start = 0; ; ) {
            end = input.indexOf(',", start);
            if (end == -1) {

            output.addElement(input.substring(start, end).trim());
            start = end + 1;

        end = len;
        output.addElement(input.substring(start, end).trim());

        return output;
public static byte[]toCString(java.lang.String string)
Converts string into a null terminated byte array. Expects the characters in string to be in th ASCII range (0-127 base 10).

string the string to convert
byte array with contents of string

        int length = string.length();
        byte[] cString = new byte[length + 1];

        for (int i = 0; i < length; i++) {
            cString[i] = (byte)string.charAt(i);

        return cString;
public static java.lang.StringtoJavaString(byte[] cString)
Converts an ASCII null terminated byte array in to a String. Expects the characters in byte array to be in th Ascii range (0-127 base 10).

cString the byte array to convert
string with contents of the byte array
ArrayIndexOutOfBounds if the C string does not end with 0

        int i;
        String jString;

        // find the string length
        for (i = 0; cString[i] != 0; i++);

        try {
            return new String(cString, 0, i, "ISO8859_1");
        } catch ( e) {
            return null;