Skip to content

Commit f3fc7af

Browse files
committed
BUG in ByteBuffer clear (java 8)
1 parent 3b165a7 commit f3fc7af

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ notifications:
1616
1717
jdk:
1818
- openjdk11
19+
- oraclejdk8
20+

src/main/scala/com/sfxcode/nosql/mongo/gridfs/GridFSStreamObserver.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package com.sfxcode.nosql.mongo.gridfs
22

33
import java.io.OutputStream
4-
import java.nio.ByteBuffer
4+
import java.nio.{ Buffer, ByteBuffer }
55
import java.util.concurrent.atomic.{ AtomicBoolean, AtomicInteger, AtomicLong }
66

77
import com.typesafe.scalalogging.LazyLogging
88
import org.mongodb.scala.Observer
99

1010
case class GridFSStreamObserver(outputStream: OutputStream) extends Observer[ByteBuffer] with LazyLogging {
11-
val completed = new AtomicBoolean(false)
11+
val completed = new AtomicBoolean(false)
1212
val resultLength = new AtomicLong(0)
1313

1414
override def onNext(buffer: ByteBuffer): Unit = {
1515
val bytes = new Array[Byte](buffer.remaining())
1616
resultLength.set(resultLength.get() + bytes.length)
1717
buffer.get(bytes, 0, bytes.length)
18-
buffer.clear()
18+
buffer.asInstanceOf[Buffer].clear()
1919
outputStream.write(bytes)
2020
}
2121

src/test/scala/com/sfxcode/nosql/mongo/gridfs/GridfsDatabaseFunctions.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff 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: Long = 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)

0 commit comments

Comments
 (0)