Skip to content

Commit d3ae27e

Browse files
authored
Merge pull request #87 from scalableminds/scala213
Scala 2.13
2 parents ca1cefc + ea41a85 commit d3ae27e

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

scala/build.sbt

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "webknossos-wrap"
22

3-
scalaVersion := "2.12.7"
3+
scalaVersion := "2.13.11"
44

55
javaOptions in test ++= Seq("-Xmx512m")
66

@@ -55,13 +55,12 @@ pomExtra := (
5555
)
5656

5757
libraryDependencies ++= Seq(
58-
"com.google.guava" % "guava" % "21.0",
59-
"com.jsuereth" %% "scala-arm" % "2.0",
60-
"net.jpountz.lz4" % "lz4" % "1.3.0",
61-
"net.liftweb" % "lift-common_2.10" % "2.6-M3",
62-
"net.liftweb" % "lift-util_2.10" % "3.0-M1",
63-
"org.apache.commons" % "commons-lang3" % "3.1",
64-
"commons-io" % "commons-io" % "2.9.0",
58+
"com.google.guava" % "guava" % "23.0",
59+
"org.lz4" % "lz4-java" % "1.8.0",
60+
"net.liftweb" %% "lift-common" % "3.5.0",
61+
"net.liftweb" %% "lift-util" % "3.5.0",
62+
"org.apache.commons" % "commons-lang3" % "3.13.0",
63+
"commons-io" % "commons-io" % "2.13.0",
6564
)
6665

6766
releasePublishArtifactsAction := PgpKeys.publishSigned.value

scala/src/main/scala/com/scalableminds/webknossos/wrap/WKWFile.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.nio.channels.FileChannel
55
import java.nio.file.{Files, Paths, StandardCopyOption}
66

77
import org.apache.commons.io.IOUtils
8-
import com.google.common.io.{LittleEndianDataInputStream => DataInputStream}
8+
import com.google.common.io.LittleEndianDataInputStream
99
import com.scalableminds.webknossos.wrap.util.ExtendedMappedByteBuffer
1010
import com.scalableminds.webknossos.wrap.util.{BoxImplicits, ResourceBox}
1111
import net.jpountz.lz4.LZ4Factory
@@ -207,7 +207,7 @@ class WKWFile(val header: WKWHeader, fileMode: FileMode.Value, underlyingFile: R
207207
val sourceBlockLengths = if (header.isCompressed) {
208208
header.jumpTable.sliding(2).map(a => (a(1) - a(0)).toInt)
209209
} else {
210-
Array.fill(header.numBlocksPerCube)(header.numBytesPerBlock).toIterator
210+
Array.fill(header.numBlocksPerCube)(header.numBytesPerBlock).iterator
211211
}
212212

213213
val targetBlockLengths = sourceBlockLengths.foldLeft[Box[Seq[Int]]](Full(Seq.empty)) {
@@ -279,7 +279,7 @@ object WKWFile extends WKWCompressionHelper {
279279
}
280280

281281
def read[T](is: InputStream)(f: (WKWHeader, Iterator[Array[Byte]]) => T): Box[T] = {
282-
ResourceBox.manage(new DataInputStream(is)) { dataStream =>
282+
ResourceBox.manage(new LittleEndianDataInputStream(is)) { dataStream =>
283283
for {
284284
header <- WKWHeader(dataStream, readJumpTable = true)
285285
} yield {
@@ -297,7 +297,7 @@ object WKWFile extends WKWCompressionHelper {
297297
(0 until header.numBlocksPerCube).foldLeft[Box[Array[Int]]](Full(Array.emptyIntArray)) {
298298
case (Full(blockLengths), _) =>
299299
if (blocks.hasNext) {
300-
val data = blocks.next
300+
val data = blocks.next()
301301
for {
302302
_ <- (data.length == header.numBytesPerBlock) ?~! error("Unexpected block size", header.numBytesPerBlock, data.length)
303303
compressedBlock <- if (header.isCompressed) compressBlock(header.blockType)(data) else Full(data)
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
package com.scalableminds.webknossos.wrap.util
22

3-
import net.liftweb.common.{Box, Failure}
3+
import net.liftweb.common.Box
4+
import net.liftweb.common.{Failure => BoxFailure}
45
import net.liftweb.util.Helpers.tryo
5-
import resource._
6+
7+
import scala.util.Using.Releasable
8+
import scala.util.{Success, Using, Failure => TryFailure}
9+
610

711
object ResourceBox {
8-
def apply[R : Resource](resource: => R): Box[R] = {
12+
def apply[R : Releasable](resource: => R): Box[R] = {
913
tryo(resource) ~> "Exception during resource creation"
1014
}
1115

12-
def manage[R : Resource, T](resource: => R)(f: R => Box[T]): Box[T] = {
16+
def manage[R : Releasable, T](resource: => R)(f: R => Box[T]): Box[T] = {
1317
for {
1418
r <- ResourceBox(resource)
15-
result <- managed(r).map(f).either.either match {
16-
case Left(ex) =>
17-
Failure(s"Exception during resource management: ${ex.toString}")
18-
case Right(result) =>
19-
result
20-
}
21-
} yield {
22-
result
23-
}
19+
result <- Using.Manager { use =>
20+
f(use(r))
21+
} match {
22+
case TryFailure(ex) =>
23+
BoxFailure(s"Exception during resource management: ${ex.toString}")
24+
case Success(result) =>
25+
result
26+
}
27+
} yield result
2428
}
2529
}

scala/version.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "1.1.16-SNAPSHOT"
1+
version in ThisBuild := "1.1.24-SNAPSHOT"

0 commit comments

Comments
 (0)