Merge branch 'master' of git@github.com:jclouds/jclouds

* 'master' of git@github.com:jclouds/jclouds:
  blobstore/download-blob should .writeTo instead of c.c.io/copy.
This commit is contained in:
Adrian Cole 2010-06-11 10:19:47 -07:00
commit d7e366f390
1 changed files with 5 additions and 4 deletions

View File

@ -45,6 +45,7 @@ See http://code.google.com/p/jclouds for details."
options.ListContainerOptions] options.ListContainerOptions]
[org.jclouds.encryption.internal JCEEncryptionService] [org.jclouds.encryption.internal JCEEncryptionService]
[java.util Arrays] [java.util Arrays]
[java.security DigestOutputStream MessageDigest]
[com.google.common.collect ImmutableSet])) [com.google.common.collect ImmutableSet]))
(try (try
@ -293,10 +294,10 @@ container, name, string -> etag"
(defmethod download-blob OutputStream [container-name name target blobstore (defmethod download-blob OutputStream [container-name name target blobstore
& [retries]] & [retries]]
(let [blob (get-blob container-name name blobstore) (let [blob (get-blob container-name name blobstore)
digest-stream (.md5OutputStream ;; TODO: not all clouds use MD5 digest-stream (DigestOutputStream.
*encryption-service* target)] target (MessageDigest/getInstance "MD5"))]
(io/copy (.getContent blob) digest-stream) (.writeTo (.getPayload blob) digest-stream)
(let [digest (.getMD5 digest-stream) (let [digest (.digest (.getMessageDigest digest-stream))
metadata-digest (.getContentMD5 (.getMetadata blob))] metadata-digest (.getContentMD5 (.getMetadata blob))]
(when-not (Arrays/equals digest metadata-digest) (when-not (Arrays/equals digest metadata-digest)
(if (<= (or retries 0) *max-retries*) (if (<= (or retries 0) *max-retries*)