Add ByteSource Payload support for Clojure

This commit is contained in:
Andrew Gaul 2014-02-19 11:37:46 -08:00
parent c035bcd6b2
commit f5c9a72243
2 changed files with 16 additions and 3 deletions

View File

@ -52,7 +52,8 @@ See http://code.google.com/p/jclouds for details."
[org.jclouds.io Payload Payloads payloads.StreamingPayload]
java.util.Arrays
[java.security DigestOutputStream MessageDigest]
com.google.common.collect.ImmutableSet))
com.google.common.collect.ImmutableSet
com.google.common.io.ByteSource))
;;
;; Payload support for creating Blobs.
@ -72,6 +73,8 @@ See http://code.google.com/p/jclouds for details."
(payload [s] (Payloads/newStringPayload s))
java.io.File
(payload [f] (Payloads/newFilePayload f))
ByteSource
(payload [bs] (Payloads/newByteSourcePayload bs))
clojure.lang.IFn
;; This will let you pass a closure to payload that takes an OutputStream
;; as argument and writes to it when called from a StreamingPayload.

View File

@ -20,7 +20,8 @@
(:use [clojure.test])
(:import [java.io ByteArrayInputStream ByteArrayOutputStream
StringBufferInputStream]
[org.jclouds.util Strings2]))
[org.jclouds.util Strings2]
com.google.common.io.ByteSource))
(defn clean-stub-fixture
"This should allow basic tests to easily be run with another service."
@ -180,12 +181,21 @@
:payload (.getBytes "blob3")))
(Strings2/toStringAndClose (get-blob-stream blobstore-stub
"container" "blob3")))))
(is (= "blob4"
(do
(put-blob blobstore-stub "container"
(blob "blob4"
:payload #(.write % (.getBytes "blob4"))))
(Strings2/toStringAndClose (get-blob-stream blobstore-stub
"container" "blob4"))))))
"container" "blob4")))))
(is (= "blob5"
(do
(put-blob blobstore-stub "container"
(blob "blob5"
:payload (ByteSource/wrap (.getBytes "blob5"))))
(Strings2/toStringAndClose (get-blob-stream blobstore-stub
"container" "blob5"))))))
;; TODO: more tests involving blob-specific functions