@Override
public String write(InputStream in) throws MicroKernelException {
try {
final Hasher hasher = Hashing.sha256().newHasher();
Blob blob = store.createBlob(
new CheckedInputStream(in, new Checksum() {
@Override
public void update(byte[] b, int off, int len) {
hasher.putBytes(b, off, len);
}
@Override
public void update(int b) {
hasher.putByte((byte) b);
}
@Override
public void reset() {
throw new UnsupportedOperationException();
}
@Override
public long getValue() {
throw new UnsupportedOperationException();
}
}));
HashCode hash = hasher.hash();
// wrap into AbstractBlob for the SHA-256 memorization feature
if (!(blob instanceof AbstractBlob)) {
final Blob b = blob;
blob = new AbstractBlob(hash) {
@Override
public long length() {
return b.length();
}
@Override
public InputStream getNewStream() {
return b.getNewStream();
}
};
}
String id = hash.toString();