FileDocCategorySizeDatePackage
Util.javaAPI DocJ2ME CLDC 1.15475Wed Feb 05 15:56:02 GMT 2003jcc

Util

public class Util extends Object

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringaccessToString(int access)

    String result = "";
        if ((access & Const.ACC_PUBLIC) != 0){
        result += "public ";
    }
    if ((access & Const.ACC_PRIVATE) != 0){
        result += "private ";
    }
    if ((access & Const.ACC_PROTECTED) != 0){
        result += "protected ";
    }
    if ((access & Const.ACC_STATIC) != 0){
        result += "static ";
    }
    if ((access & Const.ACC_TRANSIENT) != 0){
        result += "transient ";
    }
    if ((access & Const.ACC_SYNCHRONIZED) != 0){
        result += "synchronized ";
    }
    if ((access & Const.ACC_ABSTRACT) != 0){
        result += "abstract ";
    }
    if ((access & Const.ACC_NATIVE) != 0){
        result += "native ";
    }
    if ((access & Const.ACC_FINAL) != 0){
        result += "final ";
    }
    if ((access & Const.ACC_VOLATILE) != 0){
        result += "volatile ";
    }
    if ((access & Const.ACC_INTERFACE) != 0){
        result += "interface ";
    }
    return result;
    
public static intargsSize(java.lang.String sig)

    int argsSize = 0;

    for (int pos = 0; sig.charAt(pos) != Const.SIGC_ENDMETHOD; pos++) {
        switch (sig.charAt(pos)) {
          case Const.SIGC_BOOLEAN:
          case Const.SIGC_BYTE:
          case Const.SIGC_CHAR:
          case Const.SIGC_SHORT:
          case Const.SIGC_INT:
          case Const.SIGC_FLOAT:
        argsSize++;
        break;

          case Const.SIGC_LONG:
          case Const.SIGC_DOUBLE:
        argsSize += 2;
        break;

          case Const.SIGC_CLASS:
        argsSize++;
        while (sig.charAt(pos) != Const.SIGC_ENDCLASS) {
            pos++;
        }
        break;

          case Const.SIGC_ARRAY:
        argsSize++;
        while (sig.charAt(pos) == Const.SIGC_ARRAY) {
            pos++;
        }

        if (sig.charAt(pos) == Const.SIGC_CLASS) {
            while (sig.charAt(pos) != Const.SIGC_ENDCLASS) {
            pos++;
            }
        }
        break;

          case Const.SIGC_METHOD:
        break;

          default:
        System.err.println("Error: unparseable signature: " + sig);
        System.exit(3);
        }

    }

    return argsSize;
    
public static java.lang.StringconvertToClassName(java.lang.String name)

    char chars[] = name.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        switch (chars[i]){
        case '/":
        case '.":
        case '$":
        chars[i] = '_";
        }
    }

    return String.valueOf(chars);
    
public static java.lang.StringconvertToJNIName(java.lang.String classname, java.lang.String methodname, java.lang.String typename)

 
    StringBuffer result = new StringBuffer("Java_");
    stringToJNI(result, classname);
    result.append('_");
    stringToJNI(result, methodname);
    if (typename != null) {
        result.append("__");
        // Only include the stuff inside the parentheses.
        stringToJNI(result, typename.substring(1, typename.indexOf(')")));
    } 
    return result.toString();
    
private static voidstringToJNI(java.lang.StringBuffer result, java.lang.String name)

 
    int length = name.length();
    for (int i = 0; i < length; i++) { 
        char ch = name.charAt(i);
        if (ch <= 0x7f && Character.isLetterOrDigit(ch)) {
        result.append(ch);
        } else { 
        result.append('_");
        switch(ch) { 
           case '/":  break; // the _ is all we need
           case '_":  result.append('1"); break;
           case ';":  result.append('2"); break;
           case '[":  result.append('3"); break;
           default: { 
               // Adding 0x100000 to a 16-bit number forces 
               // toHexString to produce a string of the form "10xxxx".
               // Discard the initial "1" to get the right result.
               String t = Integer.toHexString(ch + 0x100000);
               result.append(t.substring(1));
           }
        }
        }
    }
    
public static java.lang.StringunicodeToUTF(java.lang.String in)

    int n = in.length();
    StringBuffer t = new StringBuffer( 3*n ); // conservative sizing.
    int nt = 0;
    for( int i = 0; i < n; i++ ){
        char c = in.charAt(i);
        if ( c == '\u0000" ){
        t.append('\u00c0");
        t.append('\u0080");
        nt+=2;
        } else if ( c <= '\u007f" ){
        t.append(c);
        nt+=1;
        } else if ( c <= '\u07ff" ){
        t.append((char)('\u00c0" | ( c>>6 )));
        t.append((char)('\u0080" | ( c&0x3f)));
        nt+=2;
        } else {
        t.append((char)('\u00e0" | ( c>>12 )) );
        t.append((char)('\u0080" | ( (c>>6)&0x3f)) );
        t.append((char)('\u0080" | ( c&0x3f)) );
        nt+=3;
        }
    }
    if ( nt == n ) return in;
    else return t.toString();