* href="http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmi-stubs24.html">Method
* hashing of RMI</a>
*/
public static long hashMethod(final String methodName, final String methodDescriptor) {
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("Algorithm SHA-1 is not available", e);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DigestOutputStream dos = new DigestOutputStream(baos, md);
DataOutputStream das = new DataOutputStream(dos);
StringBuilder sb = new StringBuilder();
sb.append(methodName);
sb.append(methodDescriptor);
try {
das.writeUTF(sb.toString());
} catch (IOException e) {
throw new IllegalStateException("Cannot write data for method '" + methodName + "'.", e);
}
try {
das.flush();
} catch (IOException e) {
logger.warn("Cannot flush the stream", e);
}
try {
das.close();
} catch (IOException e) {
logger.warn("Cannot flush the stream", e);
}
byte[] digest = md.digest();
long hash = 0;
int size = Math.min(digest.length, BYTES_LENGTH);
for (int i = 0; i < size; i++) {
hash += (long) (digest[i] & BYTE_MASK) << (BYTES_LENGTH * i);
}