diff --git a/CHANGES.txt b/CHANGES.txt index 78f40c82e5..f2616e5db3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -152,6 +152,9 @@ Trunk (unreleased changes) HADOOP-7010. Typo in FileSystem.java. (Jingguo Yao via eli) + HADOOP-7009. MD5Hash provides a public factory method that creates an + instance of thread local MessageDigest. (hairong) + OPTIMIZATIONS HADOOP-6884. Add LOG.isDebugEnabled() guard for each LOG.debug(..). diff --git a/src/java/org/apache/hadoop/io/MD5Hash.java b/src/java/org/apache/hadoop/io/MD5Hash.java index 4e358fd9bb..f19f8db12c 100644 --- a/src/java/org/apache/hadoop/io/MD5Hash.java +++ b/src/java/org/apache/hadoop/io/MD5Hash.java @@ -94,11 +94,18 @@ public static MD5Hash digest(byte[] data) { return digest(data, 0, data.length); } + /** + * Create a thread local MD5 digester + */ + public static MessageDigest getDigester() { + return DIGESTER_FACTORY.get(); + } + /** Construct a hash value for the content from the InputStream. */ public static MD5Hash digest(InputStream in) throws IOException { final byte[] buffer = new byte[4*1024]; - final MessageDigest digester = DIGESTER_FACTORY.get(); + final MessageDigest digester = getDigester(); for(int n; (n = in.read(buffer)) != -1; ) { digester.update(buffer, 0, n); } @@ -109,7 +116,7 @@ public static MD5Hash digest(InputStream in) throws IOException { /** Construct a hash value for a byte array. */ public static MD5Hash digest(byte[] data, int start, int len) { byte[] digest; - MessageDigest digester = DIGESTER_FACTORY.get(); + MessageDigest digester = getDigester(); digester.update(data, start, len); digest = digester.digest(); return new MD5Hash(digest);