try {
final String metadataKey = metadataKeyFrom(key);
final Metadata metadata = metadataCache.get(metadataKey);
if (metadata == null) {
String msg = JcrI18n.unableToFindBinaryValueInCache.text(key, metadataCache.getName());
throw new BinaryStoreException(JcrI18n.errorStoringMimeType.text(msg));
}
// Note that it's okay if another process intercedes at this point, because it should be idempotent ...
final String textKey = textKeyFrom(key);
ChunkOutputStream chunkOutputStream = null;
try {
chunkOutputStream = new ChunkOutputStream(blobCache, textKey, chunkSize);
chunkOutputStream.write(extractedText.getBytes("UTF-8"));
} finally {
IoUtil.closeQuietly(chunkOutputStream);
}
putMetadata(metadataKey, metadata.withNumberOfTextChunks(chunkOutputStream.chunksCount()));
} catch (IOException ex) {
logger.debug(ex, "Error during store of extracted text for {0}", key);
throw new BinaryStoreException(JcrI18n.errorStoringExtractedText.text(ex.getCause().getMessage()));
} finally {
lock.unlock();
}
}