Skip to content

Commit

Permalink
patch for problem with digest
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6031 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Jun 6, 2009
1 parent 3029ef6 commit a704d82
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions source/de/anomic/kelondro/order/Digest.java
Expand Up @@ -44,6 +44,8 @@
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;

import de.anomic.kelondro.util.Log;


public class Digest {

Expand Down Expand Up @@ -109,23 +111,36 @@ public static String encodeMD5Hex(final byte[] b) {
}

public static byte[] encodeMD5Raw(final String key) {
MessageDigest digest = null;
boolean fromPool = true;
try {
final MessageDigest digest = digestPool.take();
byte[] keyBytes;
try {
keyBytes = key.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
keyBytes = key.getBytes();
}
digest.update(keyBytes);
byte[] result = digest.digest();
digest.reset();
digestPool.put(digest);
return result;
digest = digestPool.take();
} catch (InterruptedException e) {
System.out.println("Internal Error at md5:" + e.getMessage());
Log.logWarning("Digest", "using generic instead of pooled digest");
try {
digest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
}
digest.reset();
fromPool = false;
}
return null;
byte[] keyBytes;
try {
keyBytes = key.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
keyBytes = key.getBytes();
}
digest.update(keyBytes);
byte[] result = digest.digest();
digest.reset();
if (fromPool)
try {
digestPool.put(digest);
} catch (InterruptedException e) {
e.printStackTrace();
}
return result;
}

public static byte[] encodeMD5Raw(final File file) {
Expand Down

0 comments on commit a704d82

Please sign in to comment.