Package com.google.common.hash

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


         }
      }));
   }

   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

   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

      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

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

      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

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

TOP

Related Classes of com.google.common.hash.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.