Skip to content

Commit

Permalink
Merge pull request #87 from scalableminds/scala213
Browse files Browse the repository at this point in the history
Scala 2.13
  • Loading branch information
fm3 authored Sep 19, 2023
2 parents ca1cefc + ea41a85 commit d3ae27e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
15 changes: 7 additions & 8 deletions scala/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "webknossos-wrap"

scalaVersion := "2.12.7"
scalaVersion := "2.13.11"

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

Expand Down Expand Up @@ -55,13 +55,12 @@ pomExtra := (
)

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

releasePublishArtifactsAction := PgpKeys.publishSigned.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.nio.channels.FileChannel
import java.nio.file.{Files, Paths, StandardCopyOption}

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

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

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

import net.liftweb.common.{Box, Failure}
import net.liftweb.common.Box
import net.liftweb.common.{Failure => BoxFailure}
import net.liftweb.util.Helpers.tryo
import resource._

import scala.util.Using.Releasable
import scala.util.{Success, Using, Failure => TryFailure}


object ResourceBox {
def apply[R : Resource](resource: => R): Box[R] = {
def apply[R : Releasable](resource: => R): Box[R] = {
tryo(resource) ~> "Exception during resource creation"
}

def manage[R : Resource, T](resource: => R)(f: R => Box[T]): Box[T] = {
def manage[R : Releasable, T](resource: => R)(f: R => Box[T]): Box[T] = {
for {
r <- ResourceBox(resource)
result <- managed(r).map(f).either.either match {
case Left(ex) =>
Failure(s"Exception during resource management: ${ex.toString}")
case Right(result) =>
result
}
} yield {
result
}
result <- Using.Manager { use =>
f(use(r))
} match {
case TryFailure(ex) =>
BoxFailure(s"Exception during resource management: ${ex.toString}")
case Success(result) =>
result
}
} yield result
}
}
2 changes: 1 addition & 1 deletion scala/version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "1.1.16-SNAPSHOT"
version in ThisBuild := "1.1.24-SNAPSHOT"

0 comments on commit d3ae27e

Please sign in to comment.