public BinaryValue storeValue( InputStream stream, boolean markAsUnused ) throws BinaryStoreException {
File tmpFile = null;
BinaryValue value = null;
try {
// Write the contents to a temporary file, and while we do grab the SHA-1 hash and the length ...
HashingInputStream hashingStream = SecureHash.createHashingStream(Algorithm.SHA_1, stream);
tmpFile = File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
IoUtil.write(hashingStream, new BufferedOutputStream(new FileOutputStream(tmpFile)),
AbstractBinaryStore.MEDIUM_BUFFER_SIZE);
hashingStream.close();
byte[] sha1 = hashingStream.getHash();
BinaryKey key = new BinaryKey(sha1);
final long numberOfBytes = tmpFile.length();
if (numberOfBytes < getMinimumBinarySizeInBytes()) {
// The content is small enough to just store in-memory ...