// in case of an unused entry, this entry is from now used
if (metadata.isUnused() && !markAsUnused) {
metadata.markAsUsed();
putMetadata(metadataKey, metadata);
}
return new StoredBinaryValue(this, binaryKey, metadata.getLength());
}
logger.debug("Store binary value into chunks.");
// store the chunks based referenced to SHA1-key
// we do store outside of transaction to prevent problems with
// large content and transaction timeouts
final String dataKey = dataKeyFrom(binaryKey);
final long lastModified = tmpFile.lastModified();
final long fileLength = tmpFile.length();
int bufferSize = bestBufferSize(fileLength);
ChunkOutputStream chunkOutputStream = new ChunkOutputStream(blobCache, dataKey, chunkSize);
IoUtil.write(new FileInputStream(tmpFile), chunkOutputStream, bufferSize);
Lock lock = lockFactory.writeLock(lockKeyFrom(binaryKey));
try {
// now store metadata
metadata = new Metadata(lastModified, fileLength, chunkOutputStream.chunksCount(), chunkSize);
if (markAsUnused) {
metadata.markAsUnusedSince(System.currentTimeMillis());
}
putMetadata(metadataKey, metadata);
return new StoredBinaryValue(this, binaryKey, fileLength);
} finally {
lock.unlock();
}
} catch (IOException e) {
throw new BinaryStoreException(e);