Skip to content

Commit

Permalink
Misc.java: stop using ThreadLocal for message digest instance - closes
Browse files Browse the repository at this point in the history
  • Loading branch information
edrdo committed Sep 15, 2017
1 parent 73cb841 commit 2d07a7e
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/main/java/org/jdbdt/Misc.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ static byte[] fromHexString(String str) {
return data;
}

/** Thread-local handle for checksum handle. */
private static final ThreadLocal<MessageDigest> SHA1_DIGEST_TL = new ThreadLocal<>();

/** SHA-1 digest constant. */
private static final String SHA1_DIGEST = "SHA-1";

Expand All @@ -70,12 +67,7 @@ static byte[] fromHexString(String str) {
*/
static byte[] sha1(InputStream in) {
try {
MessageDigest md = SHA1_DIGEST_TL.get();
if (md == null) {
md = MessageDigest.getInstance(SHA1_DIGEST);
SHA1_DIGEST_TL.set(md);
}
md.reset();
MessageDigest md = MessageDigest.getInstance(SHA1_DIGEST);
byte[] buffer = new byte[4096];
int bytes;
while ( (bytes = in.read(buffer)) > 0) {
Expand Down

0 comments on commit 2d07a7e

Please sign in to comment.