final public HashKey writeData(HashKey oldValueHash,
Object value,
CacheSerializer serializer)
{
TempOutputStream os = null;
try {
os = new TempOutputStream();
Sha256OutputStream mOut = new Sha256OutputStream(os);
DeflaterOutputStream gzOut = new DeflaterOutputStream(mOut);
serializer.serialize(value, gzOut);
gzOut.finish();
mOut.close();
byte[] hash = mOut.getDigest();
HashKey valueHash = new HashKey(hash);
if (valueHash.equals(oldValueHash))
return valueHash;
int length = os.getLength();
StreamSource source = new StreamSource(os);
if (! getDataBacking().saveData(valueHash, source, length)) {
throw new IllegalStateException(L.l("Can't save the data '{0}'",
valueHash));
}
return valueHash;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (os != null)
os.close();
}
}