added get-blob-stream helper and corresponding test

This commit is contained in:
Adrian Cole 2010-08-10 10:37:17 -07:00
parent a58ab85b7e
commit 25bc2c0691
2 changed files with 16 additions and 2 deletions

View File

@ -237,6 +237,13 @@ Options can also be specified for extension modules
([container-name path #^BlobStore blobstore] ([container-name path #^BlobStore blobstore]
(.getBlob blobstore container-name path))) (.getBlob blobstore container-name path)))
(defn get-blob-stream
"Get an inputstream from the blob at a given path"
([container-name path]
(get-blob-stream container-name path *blobstore*))
([container-name path #^BlobStore blobstore]
(.getInput(.getPayload(.getBlob blobstore container-name path)))))
(defn remove-blob (defn remove-blob
"Remove blob from given path" "Remove blob from given path"
([container-name path] ([container-name path]
@ -311,7 +318,7 @@ container, name, string -> etag"
& [retries]] & [retries]]
(let [blob (get-blob container-name name blobstore) (let [blob (get-blob container-name name blobstore)
digest-stream (DigestOutputStream. digest-stream (DigestOutputStream.
target (MessageDigest/getInstance "MD5"))] target (.md5(.crypto (.utils (blobstore-context blobstore)))))]
(.writeTo (.getPayload blob) digest-stream) (.writeTo (.getPayload blob) digest-stream)
(let [digest (.digest (.getMessageDigest digest-stream)) (let [digest (.digest (.getMessageDigest digest-stream))
metadata-digest (.getContentMD5 (.getPayload blob))] metadata-digest (.getContentMD5 (.getPayload blob))]

View File

@ -20,7 +20,8 @@
(:use [org.jclouds.blobstore] :reload-all) (:use [org.jclouds.blobstore] :reload-all)
(:use [clojure.test]) (:use [clojure.test])
(:import [org.jclouds.blobstore BlobStoreContextFactory] (:import [org.jclouds.blobstore BlobStoreContextFactory]
[java.io ByteArrayOutputStream])) [java.io ByteArrayOutputStream]
[org.jclouds.util Utils]))
(defn clean-stub-fixture (defn clean-stub-fixture
"This should allow basic tests to easily be run with another service." "This should allow basic tests to easily be run with another service."
@ -73,6 +74,12 @@
(is (= 3 (count (list-container "container" :with-details true)))) (is (= 3 (count (list-container "container" :with-details true))))
(is (= 1 (count (list-container "container" :in-directory "dir"))))) (is (= 1 (count (list-container "container" :in-directory "dir")))))
(deftest get-blob-test
(is (create-container "blob"))
(is (upload-blob "blob" "blob1" "blob1"))
(is (upload-blob "blob" "blob2" "blob2"))
(is (= "blob2" (Utils/toStringAndClose (get-blob-stream "blob" "blob2")))))
(deftest download-blob-test (deftest download-blob-test
(let [name "test" (let [name "test"
container-name "test-container" container-name "test-container"