⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objectstreamclassutil_1_3.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    byte hasharray[] = md.digest();	    for (int i = 0; i < Math.min(8, hasharray.length); i++) {		h += (long)(hasharray[i] & 255) << (i * 8);	    }	} catch (IOException ignore) {	    /* can't happen, but be deterministic anyway. */	    h = -1;	} catch (NoSuchAlgorithmException complain) {	    throw new SecurityException(complain.getMessage());	}	return h;    }    /*     * Comparator object for Classes and Interfaces     */    private static Comparator compareClassByName =    	new CompareClassByName();    private static class CompareClassByName implements Comparator {	public int compare(Object o1, Object o2) {	    Class c1 = (Class)o1;	    Class c2 = (Class)o2;	    return (c1.getName()).compareTo(c2.getName());	}    }    /*     * Comparator object for Members, Fields, and Methods     */    private static Comparator compareMemberByName =        new CompareMemberByName();    private static class CompareMemberByName implements Comparator {        public int compare(Object o1, Object o2) {            String s1 = ((Member)o1).getName();            String s2 = ((Member)o2).getName();            if (o1 instanceof Method) {                s1 += getSignature((Method)o1);                s2 += getSignature((Method)o2);            } else if (o1 instanceof Constructor) {                s1 += getSignature((Constructor)o1);                s2 += getSignature((Constructor)o2);            }            return s1.compareTo(s2);        }    }    /**     * Compute the JVM signature for the class.     */    private static String getSignature(Class clazz) {	String type = null;	if (clazz.isArray()) {	    Class cl = clazz;	    int dimensions = 0;	    while (cl.isArray()) {		dimensions++;		cl = cl.getComponentType();	    }	    StringBuffer sb = new StringBuffer();	    for (int i = 0; i < dimensions; i++) {		sb.append("[");	    }	    sb.append(getSignature(cl));	    type = sb.toString();	} else if (clazz.isPrimitive()) {	    if (clazz == Integer.TYPE) {		type = "I";	    } else if (clazz == Byte.TYPE) {		type = "B";	    } else if (clazz == Long.TYPE) {		type = "J";	    } else if (clazz == Float.TYPE) {		type = "F";	    } else if (clazz == Double.TYPE) {		type = "D";	    } else if (clazz == Short.TYPE) {		type = "S";	    } else if (clazz == Character.TYPE) {		type = "C";	    } else if (clazz == Boolean.TYPE) {		type = "Z";	    } else if (clazz == Void.TYPE) {		type = "V";	    }	} else {	    type = "L" + clazz.getName().replace('.', '/') + ";";	}	return type;    }    /*     * Compute the JVM method descriptor for the method.     */    private static String getSignature(Method meth) {	StringBuffer sb = new StringBuffer();	sb.append("(");	Class[] params = meth.getParameterTypes(); // avoid clone	for (int j = 0; j < params.length; j++) {	    sb.append(getSignature(params[j]));	}	sb.append(")");	sb.append(getSignature(meth.getReturnType()));	return sb.toString();    }    /*     * Compute the JVM constructor descriptor for the constructor.     */    private static String getSignature(Constructor cons) {	StringBuffer sb = new StringBuffer();	sb.append("(");	Class[] params = cons.getParameterTypes(); // avoid clone	for (int j = 0; j < params.length; j++) {	    sb.append(getSignature(params[j]));	}	sb.append(")V");	return sb.toString();    }    private static Field[] getDeclaredFields(final Class clz) {        return (Field[]) AccessController.doPrivileged(new PrivilegedAction() {            public Object run() {                return clz.getDeclaredFields();            }        });    }    private static class MethodSignature implements Comparator {	Member member;	String signature;      // cached parameter signature	/* Given an array of Method or Constructor members,	   return a sorted array of the non-private members.*/	/* A better implementation would be to implement the returned data	   structure as an insertion sorted link list.*/	static MethodSignature[] removePrivateAndSort(Member[] m) {	    int numNonPrivate = 0;	    for (int i = 0; i < m.length; i++) {		if (! Modifier.isPrivate(m[i].getModifiers())) {		    numNonPrivate++;		}	    }	    MethodSignature[] cm = new MethodSignature[numNonPrivate];	    int cmi = 0;	    for (int i = 0; i < m.length; i++) {		if (! Modifier.isPrivate(m[i].getModifiers())) {		    cm[cmi] = new MethodSignature(m[i]);		    cmi++;		}	    }	    if (cmi > 0)		Arrays.sort(cm, cm[0]);	    return cm;	}	/* Assumes that o1 and o2 are either both methods	   or both constructors.*/	public int compare(Object o1, Object o2) {	    /* Arrays.sort calls compare when o1 and o2 are equal.*/	    if (o1 == o2)		return 0;	    MethodSignature c1 = (MethodSignature)o1;	    MethodSignature c2 = (MethodSignature)o2;	    int result;	    if (isConstructor()) {		result = c1.signature.compareTo(c2.signature);	    } else { // is a Method.		result = c1.member.getName().compareTo(c2.member.getName());		if (result == 0)		    result = c1.signature.compareTo(c2.signature);	    }	    return result;	}	final private boolean isConstructor() {	    return member instanceof Constructor;	}	private MethodSignature(Member m) {	    member = m;	    if (isConstructor()) {		signature = ObjectStreamClassUtil_1_3.getSignature((Constructor)m);	    } else {		signature = ObjectStreamClassUtil_1_3.getSignature((Method)m);	    }	}    }    /* Find out if the class has a static class initializer <clinit> */    // use java.io.ObjectStream's hasStaticInitializer method    // private static native boolean hasStaticInitializer(Class cl);    private static Method hasStaticInitializerMethod = null;    /**     * Returns true if the given class defines a static initializer method,     * false otherwise.     */    private static boolean hasStaticInitializer(Class cl) {        if (hasStaticInitializerMethod == null) {            Class classWithThisMethod = null;                        try {                try {                    // When using rip-int with Merlin or when this is a Merlin                    // workspace, the method we want is in sun.misc.ClassReflector                    // and absent from java.io.ObjectStreamClass.                    //                    // When compiling rip-int with JDK 1.3.x, we have to get it                    // from java.io.ObjectStreamClass.                    classWithThisMethod = Class.forName("sun.misc.ClassReflector");                } catch (ClassNotFoundException cnfe) {                    // Do nothing.  This is either not a Merlin workspace,                    // or rip-int is being compiled with something other than                    // Merlin, probably JDK 1.3.  Fall back on java.io.ObjectStreaClass.                }                if (classWithThisMethod == null)                    classWithThisMethod = java.io.ObjectStreamClass.class;                                hasStaticInitializerMethod =                    classWithThisMethod.getDeclaredMethod("hasStaticInitializer",                                                          new Class[] { Class.class });            } catch (NoSuchMethodException ex) {            }                        if (hasStaticInitializerMethod == null) {                throw new InternalError("Can't find hasStaticInitializer method on "                                        + classWithThisMethod.getName());            }            hasStaticInitializerMethod.setAccessible(true);        }        try {            Boolean retval = (Boolean)                hasStaticInitializerMethod.invoke(null, new Object[] { cl });            return retval.booleanValue();        } catch (Exception ex) {            throw new InternalError("Error invoking hasStaticInitializer: "                                    + ex);        }    }    private static Method getDeclaredMethod(final Class cl, final String methodName, final Class[] args,                                     final int requiredModifierMask,                                     final int disallowedModifierMask) {        return (Method) AccessController.doPrivileged(new PrivilegedAction() {            public Object run() {                Method method = null;                try {                    method =                        cl.getDeclaredMethod(methodName, args);                        int mods = method.getModifiers();                        if ((mods & disallowedModifierMask) != 0 ||                            (mods & requiredModifierMask) != requiredModifierMask) {                            method = null;                        } 	                //if (!Modifier.isPrivate(mods) ||	                //    Modifier.isStatic(mods)) {	                //    method = null;	                //}                } catch (NoSuchMethodException e) {                // Since it is alright if methodName does not exist,                // no need to do anything special here.                }                return method;	    }	});    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -