Search in sources :

Example 1 with DigestInputStream

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());
}
Also used : Path(java.nio.file.Path) DigestInputStream(org.exist.util.crypto.digest.DigestInputStream) StreamableDigest(org.exist.util.crypto.digest.StreamableDigest) CountingInputStream(org.apache.commons.io.input.CountingInputStream)

Example 2 with DigestInputStream

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());
    }
}
Also used : DigestInputStream(org.exist.util.crypto.digest.DigestInputStream) StreamableDigest(org.exist.util.crypto.digest.StreamableDigest) UnsynchronizedByteArrayOutputStream(org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream)

Example 3 with DigestInputStream

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());
    }
}
Also used : DigestInputStream(org.exist.util.crypto.digest.DigestInputStream) StreamableDigest(org.exist.util.crypto.digest.StreamableDigest) UnsynchronizedByteArrayOutputStream(org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream)

Aggregations

DigestInputStream (org.exist.util.crypto.digest.DigestInputStream)3 StreamableDigest (org.exist.util.crypto.digest.StreamableDigest)3 UnsynchronizedByteArrayOutputStream (org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream)2 Path (java.nio.file.Path)1 CountingInputStream (org.apache.commons.io.input.CountingInputStream)1