FileDocCategorySizeDatePackage
Util.javaAPI DocphoneME MR2 API (J2ME)4900Wed May 02 18:00:14 BST 2007com.sun.midp.io

Util

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.

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

        return getDelimSeparatedValues(input, ',");
    
public static java.util.VectorgetDelimSeparatedValues(java.lang.String input, char delim)
Create a vector of values from a string containing delimiter separated values. The values cannot contain the delimiter. The output values will be trimmed of whitespace. The vector may contain zero length strings where there are 2 delimiters in a row or a comma at the end of the input string.

param
input input string of delimiter separated values
param
delim the delimiter separating values
return
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(delim, start);
            if (end == -1) {
                break;
            }

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

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

        return output;
    
public static java.lang.StringgetHttpMediaType(java.lang.String contentType)
Parses out the media-type from the given HTTP content-type field and converts it to lower case. The media-type everything for the ';' that marks the parameters.

param
contentType value of the content-type field
return
media-type in lower case

        int semiColon;

        if (contentType == null) {
            return null;
        }

        semiColon = contentType.indexOf(';");
        if (semiColon < 0) {
            return contentType.toLowerCase();
        }

        return contentType.substring(0, semiColon).toLowerCase();
    
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).

param
string the string to convert
return
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).

param
cString the byte array to convert
return
string with contents of the byte array
exception
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 (java.io.UnsupportedEncodingException e) {
            return null;
        }