Created
July 28, 2017 06:59
-
-
Save slezhnin/47843dcdb424f6a0f7461d077fd42b3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
public abstract class Digest { | |
private Map<byte[], byte[]> cache = new HashMap<byte[], byte[]>(); | |
public byte[] digest(byte[] input) { | |
byte[] result = cache.get(input); | |
if (result == null) { | |
synchronized (cache) { | |
result = cache.get(input); | |
if (result == null) { | |
result = doDigest(input); | |
cache.put(input, result); | |
} | |
} | |
} | |
return result; | |
} | |
protected abstract byte[] doDigest(byte[] input); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment