public static Map getInterfaceHashes(Class intf) {
// Create method hashes
Method[] methods = intf.getMethods();
HashMap map = new HashMap();
for (int i = 0; i < methods.length; i++)
{
Method method = methods[i];
Class[] parameterTypes = method.getParameterTypes();
String methodDesc = method.getName()+"(";
for(int j = 0; j < parameterTypes.length; j++)
{
methodDesc += getTypeString(parameterTypes[j]);
}
methodDesc += ")"+getTypeString(method.getReturnType());
try
{
long hash = 0;
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(512);
MessageDigest messagedigest = MessageDigest.getInstance("SHA");
DataOutputStream dataoutputstream = new DataOutputStream(new DigestOutputStream(bytearrayoutputstream, messagedigest));
dataoutputstream.writeUTF(methodDesc);
dataoutputstream.flush();
byte abyte0[] = messagedigest.digest();
for(int j = 0; j < Math.min(8, abyte0.length); j++)
hash += (long)(abyte0[j] & 0xff) < < j * 8;
map.put(method.toString(), new Long(hash));
}
catch (Exception e)
{
e.printStackTrace();
}
}
return map;
}
Calculate method hashes. This algo is taken from RMI. |