From f5c9a72243057c5fa46fdc2972ca25191a81b9e8 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 19 Feb 2014 11:37:46 -0800 Subject: [PATCH] Add ByteSource Payload support for Clojure --- .../src/main/clojure/org/jclouds/blobstore2.clj | 5 ++++- .../test/clojure/org/jclouds/blobstore2_test.clj | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/blobstore/src/main/clojure/org/jclouds/blobstore2.clj b/blobstore/src/main/clojure/org/jclouds/blobstore2.clj index 6e3146be96..ee10af3d1b 100644 --- a/blobstore/src/main/clojure/org/jclouds/blobstore2.clj +++ b/blobstore/src/main/clojure/org/jclouds/blobstore2.clj @@ -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. diff --git a/blobstore/src/test/clojure/org/jclouds/blobstore2_test.clj b/blobstore/src/test/clojure/org/jclouds/blobstore2_test.clj index 2e1fdf4c89..aa0517a9ab 100644 --- a/blobstore/src/test/clojure/org/jclouds/blobstore2_test.clj +++ b/blobstore/src/test/clojure/org/jclouds/blobstore2_test.clj @@ -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