Examples of HashingInputStream


Examples of com.google.common.hash.HashingInputStream

   @Override
   public String putBlob(final String containerName, final Blob blob) throws IOException {
      byte[] payload;
      HashCode actualHashCode;
      HashingInputStream input = new HashingInputStream(Hashing.md5(), blob.getPayload().openStream());
      try {
         payload = ByteStreams.toByteArray(input);
         actualHashCode = input.hash();
         HashCode expectedHashCode = blob.getPayload().getContentMetadata().getContentMD5AsHashCode();
         if (expectedHashCode != null && !actualHashCode.equals(expectedHashCode)) {
            throw new IOException("MD5 hash code mismatch, actual: " + actualHashCode +
                  " expected: " + expectedHashCode);
         }
View Full Code Here

Examples of com.google.common.hash.HashingInputStream

         }
      }));
   }

   private static HashCode buildHashedPayload(HttpRequest request) {
      HashingInputStream his = null;
      try {
         his = new HashingInputStream(Hashing.sha256(),
               request.getPayload() == null ? ByteSource.empty().openStream() : request.getPayload().openStream());
         ByteStreams.copy(his, ByteStreams.nullOutputStream());
         return his.hash();
      } catch (IOException e) {
         throw new HttpException("Error signing request", e);
      } finally {
         Closeables.closeQuietly(his);
      }
View Full Code Here

Examples of com.google.common.hash.HashingInputStream

   public static TreeHash buildTreeHashFromPayload(Payload payload) throws IOException {
      InputStream is = null;
      try {
         is = checkNotNull(payload, "payload").openStream();
         Builder<HashCode> list = ImmutableList.builder();
         HashingInputStream linearHis = new HashingInputStream(Hashing.sha256(), is);
         while (true) {
             HashingInputStream chunkedHis = new HashingInputStream(
                     Hashing.sha256(), ByteStreams.limit(linearHis, CHUNK_SIZE));
             long count = ByteStreams.copy(chunkedHis, ByteStreams.nullOutputStream());
             if (count == 0) {
                 break;
             }
             list.add(chunkedHis.hash());
         }
         //The result list contains exactly one element now.
         return new TreeHash(hashList(list.build()), linearHis.hash());
      } finally {
         Closeables.closeQuietly(is);
View Full Code Here

Examples of com.google.common.hash.HashingInputStream

      String blobKey = blob.getMetadata().getName();
      Payload payload = blob.getPayload();
      filesystemContainerNameValidator.validate(containerName);
      filesystemBlobKeyValidator.validate(blobKey);
      File outputFile = getFileForBlobKey(containerName, blobKey);
      HashingInputStream his = null;
      try {
         Files.createParentDirs(outputFile);
         his = new HashingInputStream(Hashing.md5(), payload.openStream());
         Files.asByteSink(outputFile).writeFrom(his);
         HashCode actualHashCode = his.hash();
         HashCode expectedHashCode = payload.getContentMetadata().getContentMD5AsHashCode();
         if (expectedHashCode != null && !actualHashCode.equals(expectedHashCode)) {
            throw new IOException("MD5 hash code mismatch, actual: " + actualHashCode +
                  " expected: " + expectedHashCode);
         }
View Full Code Here

Examples of com.google.common.hash.HashingInputStream

public class ByteStreams2 {
   public static HashCode hashAndClose(InputStream input, HashFunction hashFunction) throws IOException {
      checkNotNull(input, "input");
      checkNotNull(hashFunction, "hashFunction");
      try {
         HashingInputStream his = new HashingInputStream(hashFunction, input);
         ByteStreams.copy(his, ByteStreams.nullOutputStream());
         return his.hash();
      } finally {
         Closeables.closeQuietly(input);
      }
   }
View Full Code Here

Examples of com.google.common.hash.HashingInputStream

      ContentMetadata metadata = payload.getContentMetadata();
      filesystemContainerNameValidator.validate(containerName);
      filesystemBlobKeyValidator.validate(blobKey);
      File outputFile = getFileForBlobKey(containerName, blobKey);
      Path outputPath = outputFile.toPath();
      HashingInputStream his = null;
      try {
         Files.createParentDirs(outputFile);
         his = new HashingInputStream(Hashing.md5(), payload.openStream());
         outputFile.delete();
         Files.asByteSink(outputFile).writeFrom(his);
         HashCode actualHashCode = his.hash();
         HashCode expectedHashCode = payload.getContentMetadata().getContentMD5AsHashCode();
         if (expectedHashCode != null && !actualHashCode.equals(expectedHashCode)) {
            throw new IOException("MD5 hash code mismatch, actual: " + actualHashCode +
                  " expected: " + expectedHashCode);
         }
View Full Code Here

Examples of com.google.common.hash.HashingInputStream

public class ByteStreams2 {
   public static HashCode hashAndClose(InputStream input, HashFunction hashFunction) throws IOException {
      checkNotNull(input, "input");
      checkNotNull(hashFunction, "hashFunction");
      try {
         HashingInputStream his = new HashingInputStream(hashFunction, input);
         ByteStreams.copy(his, ByteStreams.nullOutputStream());
         return his.hash();
      } finally {
         closeQuietly(input);
      }
   }
View Full Code Here

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

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

        }

        // 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
Copyright © 2018 www.massapi.com. 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.