File tree Expand file tree Collapse file tree 6 files changed +16
-15
lines changed
main/scala/com/sfxcode/nosql/mongo
test/scala/com/sfxcode/nosql/mongo/gridfs Expand file tree Collapse file tree 6 files changed +16
-15
lines changed Original file line number Diff line number Diff line change 22
33## Versions
44
5- ### 1.8.1
5+ ### 1.8.2
66
77* GridFSStreamObserver suports now completed and resultLength
8+ * implcit resultLength (in bytes) for GridFSStreamObserver
89
910### 1.8.0
1011
Original file line number Diff line number Diff line change @@ -34,14 +34,15 @@ abstract class Base extends LazyLogging {
3434
3535 def readConcern : ReadConcern = gridfsBucket.readConcern
3636
37- def upload (fileName : String ,
38- source : Observable [ByteBuffer ],
39- metadata : AnyRef = Document (),
40- chunkSizeBytes : Int = 1024 * 256 ): Observable [ObjectId ] = {
37+ def upload (
38+ fileName : String ,
39+ source : Observable [ByteBuffer ],
40+ metadata : AnyRef = Document (),
41+ chunkSizeBytes : Int = 1024 * 256 ): Observable [ObjectId ] = {
4142 val metadataDocument = {
4243 metadata match {
4344 case document : Document => document
44- case _ => Converter .toDocument(metadata)
45+ case _ => Converter .toDocument(metadata)
4546 }
4647 }
4748 val options : GridFSUploadOptions = new GridFSUploadOptions ()
@@ -55,7 +56,7 @@ abstract class Base extends LazyLogging {
5556
5657 def downloadToStream (oid : ObjectId , outputStream : OutputStream ): GridFSStreamObserver = {
5758 val observable : GridFSDownloadObservable = gridfsBucket.downloadToObservable(oid)
58- val observer = GridFSStreamObserver (outputStream)
59+ val observer = GridFSStreamObserver (outputStream)
5960 observable.subscribe(observer)
6061 observer
6162 }
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import org.mongodb.scala.Observer
99
1010case class GridFSStreamObserver (outputStream : OutputStream ) extends Observer [ByteBuffer ] with LazyLogging {
1111 val completed = new AtomicBoolean (false )
12- val resultLength = new AtomicInteger (0 )
12+ val resultLength = new AtomicLong (0 )
1313
1414 override def onNext (buffer : ByteBuffer ): Unit = {
1515 val bytes = new Array [Byte ](buffer.remaining())
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ package object mongo extends ObservableIncludes with ObservableImplicits {
7474
7575 implicit def gridFSFileToBSonIdValue (file : GridFSFile ): BsonValue = file.getId
7676
77- implicit def observerToResult (observer : GridFSStreamObserver ): Int = {
77+ implicit def observerToResultLength (observer : GridFSStreamObserver ): Long = {
7878 while (! observer.completed.get) {}
7979 observer.resultLength.get()
8080 }
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import com.sfxcode.nosql.mongo.GridFSDAO
55import com .sfxcode .nosql .mongo .database .DatabaseProvider
66
77/**
8- * GridFS Database Sample
9- */
8+ * GridFS Database Sample
9+ */
1010object GridfsDatabase {
1111 val SourcePath = " src/test/resources/images/"
1212 val TargetPath = " /tmp/_files/"
Original file line number Diff line number Diff line change @@ -29,14 +29,13 @@ trait GridfsDatabaseFunctions {
2929 }
3030
3131 def downloadImage (id : ObjectId , path : String ): Unit = {
32- val file = File (path)
33- val start = System .currentTimeMillis()
32+ val file = File (path)
33+ val start = System .currentTimeMillis()
3434 val size : Int = ImageFilesDAO .downloadToStream(id, file.newOutputStream)
3535
3636 println(
3737 " file: %s with size %s Bytes written in %s ms "
38- .format(file.pathAsString, size, System .currentTimeMillis() - start)
39- )
38+ .format(file.pathAsString, size, System .currentTimeMillis() - start))
4039 }
4140
4241 def findImage (id : ObjectId ): GridFSFile = ImageFilesDAO .findById(id)
You can’t perform that action at this time.
0 commit comments