Package org.modeshape.common.util.SecureHash

Examples of org.modeshape.common.util.SecureHash.HashingInputStream


    public BinaryValue storeValue( InputStream stream, boolean markAsUnused ) throws BinaryStoreException {
        File tmpFile = null;
        BinaryValue value = null;
        try {
            // Write the contents to a temporary file, and while we do grab the SHA-1 hash and the length ...
            HashingInputStream hashingStream = SecureHash.createHashingStream(Algorithm.SHA_1, stream);
            tmpFile = File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
            IoUtil.write(hashingStream, new BufferedOutputStream(new FileOutputStream(tmpFile)),
                         AbstractBinaryStore.MEDIUM_BUFFER_SIZE);
            hashingStream.close();
            byte[] sha1 = hashingStream.getHash();
            BinaryKey key = new BinaryKey(sha1);

            final long numberOfBytes = tmpFile.length();
            if (numberOfBytes < getMinimumBinarySizeInBytes()) {
                // The content is small enough to just store in-memory ...
View Full Code Here


        }

        // Now try reading the stream using a hash stream ...
        stream = getClass().getResourceAsStream(resourceName);
        assertThat(stream, is(notNullValue()));
        HashingInputStream hashingStream = SecureHash.createHashingStream(algorithm, stream);
        byte[] bytesThruHashingStream = IoUtil.readBytes(hashingStream); // closes stream
        byte[] hashThruHashingStream = hashingStream.getHash();

        // The content should be the same ..
        assertThat(bytesThruHashingStream, is(bytesThruStream));

        // The hash should also be the same ...
View Full Code Here

TOP

Related Classes of org.modeshape.common.util.SecureHash.HashingInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.