use of org.exist.util.crypto.digest.DigestInputStream in project exist by eXist-db.
the class BlobStoreImpl method stage.
/**
* Stages a BLOB file.
*
* Writes a BLOB to a file in the Blob Store staging area.
*
* @param is data stream for the BLOB.
* @return The file path, length and checksum of the staged BLOB
* @throws IOException if an error occurs whilst staging the BLOB.
*/
private Tuple3<Path, Long, MessageDigest> stage(final InputStream is) throws IOException {
final Path stageFile = stagingDir.resolve(UUIDGenerator.getUUIDversion4());
final CountingInputStream cis = new CountingInputStream(is);
final StreamableDigest streamableDigest = digestType.newStreamableDigest();
final DigestInputStream dis = new DigestInputStream(cis, streamableDigest);
Files.copy(dis, stageFile);
return Tuple(stageFile, cis.getByteCount(), streamableDigest.copyMessageDigest());
}
use of org.exist.util.crypto.digest.DigestInputStream in project exist by eXist-db.
the class BlobStoreImplTest method readAll.
private Tuple2<byte[], MessageDigest> readAll(InputStream is) throws IOException {
final StreamableDigest streamableDigest = DIGEST_TYPE.newStreamableDigest();
is = new DigestInputStream(is, streamableDigest);
try (final UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
os.write(is);
return Tuple(os.toByteArray(), streamableDigest.copyMessageDigest());
}
}
use of org.exist.util.crypto.digest.DigestInputStream in project exist by eXist-db.
the class BlobStoreRecoveryTest method readAll.
private Tuple2<byte[], MessageDigest> readAll(InputStream is) throws IOException {
final StreamableDigest streamableDigest = DIGEST_TYPE.newStreamableDigest();
is = new DigestInputStream(is, streamableDigest);
try (final UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
os.write(is);
return Tuple(os.toByteArray(), streamableDigest.copyMessageDigest());
}
}
Aggregations