Implement monger.gridfs.GridFSInputFileFactory for java.io.File instances
This commit is contained in:
parent
ced9b50153
commit
7da99d98a3
2 changed files with 14 additions and 2 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
(:use [monger.conversion])
|
(:use [monger.conversion])
|
||||||
(:import [com.mongodb DBObject]
|
(:import [com.mongodb DBObject]
|
||||||
[com.mongodb.gridfs GridFS GridFSInputFile]
|
[com.mongodb.gridfs GridFS GridFSInputFile]
|
||||||
[java.io InputStream]))
|
[java.io InputStream File]))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Implementation
|
;; Implementation
|
||||||
|
|
@ -56,6 +56,10 @@
|
||||||
(extend-protocol GridFSInputFileFactory
|
(extend-protocol GridFSInputFileFactory
|
||||||
String
|
String
|
||||||
(make-input-file [^String input]
|
(make-input-file [^String input]
|
||||||
|
(.createFile ^GridFS monger.core/*mongodb-gridfs* ^InputStream (io/make-input-stream input { :encoding "UTF-8" })))
|
||||||
|
|
||||||
|
File
|
||||||
|
(make-input-file [^File input]
|
||||||
(.createFile ^GridFS monger.core/*mongodb-gridfs* ^InputStream (io/make-input-stream input { :encoding "UTF-8" }))))
|
(.createFile ^GridFS monger.core/*mongodb-gridfs* ^InputStream (io/make-input-stream input { :encoding "UTF-8" }))))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,18 @@
|
||||||
(is (= 1 (count (gridfs/all-files))))))
|
(is (= 1 (count (gridfs/all-files))))))
|
||||||
|
|
||||||
|
|
||||||
|
(deftest test-storing-files-to-gridfs-using-file-instances
|
||||||
|
(let [input (io/as-file "./test/resources/mongo/js/mapfun1.js")]
|
||||||
|
(is (= 0 (count (gridfs/all-files))))
|
||||||
|
(gridfs/store (gridfs/make-input-file input)
|
||||||
|
(.setFilename "monger.test.gridfs.file2")
|
||||||
|
(.setContentType "application/octet-stream"))
|
||||||
|
(is (= 1 (count (gridfs/all-files))))))
|
||||||
|
|
||||||
(deftest test-storing-bytes-to-gridfs
|
(deftest test-storing-bytes-to-gridfs
|
||||||
(let [input (.getBytes "A string")]
|
(let [input (.getBytes "A string")]
|
||||||
(is (= 0 (count (gridfs/all-files))))
|
(is (= 0 (count (gridfs/all-files))))
|
||||||
(store (make-input-file input)
|
(store (make-input-file input)
|
||||||
(.setFilename "monger.test.gridfs.file2")
|
(.setFilename "monger.test.gridfs.file3")
|
||||||
(.setContentType "application/octet-stream"))
|
(.setContentType "application/octet-stream"))
|
||||||
(is (= 1 (count (gridfs/all-files))))))
|
(is (= 1 (count (gridfs/all-files))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue