Skip to content
Snippets Groups Projects
Commit d340fe60 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Etienne Kneuss
Browse files

Minor style improvements in FilesWatcher

parent 2456f05f
No related branches found
No related tags found
No related merge requests found
/* Copyright 2009-2014 EPFL, Lausanne */ /* Copyright 2009-2014 EPFL, Lausanne */
package leon package leon
package utils
import leon.utils._
import solvers.SolverFactory
import java.io.File import java.io.File
import java.nio.file._ import java.nio.file._
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
...@@ -15,16 +14,15 @@ case class FilesWatcher(ctx: LeonContext, files: Seq[File]) { ...@@ -15,16 +14,15 @@ case class FilesWatcher(ctx: LeonContext, files: Seq[File]) {
val dirs = toWatch.map(_.getParentFile) val dirs = toWatch.map(_.getParentFile)
def onChange(body: => Unit): Unit = { def onChange(body: => Unit): Unit = {
val watcher = FileSystems.getDefault().newWatchService() val watcher = FileSystems.getDefault.newWatchService()
val paths = dirs.map(_.toPath.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY)) dirs foreach (_.toPath.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY))
var lastHashes = toWatch.map(md5file) var lastHashes = toWatch.map(md5file)
body body
ctx.reporter.info("Waiting for source changes...") ctx.reporter.info("Waiting for source changes...")
while (true) { while (true) {
var key = watcher.take() val key = watcher.take()
val events = key.pollEvents() val events = key.pollEvents()
...@@ -47,20 +45,20 @@ case class FilesWatcher(ctx: LeonContext, files: Seq[File]) { ...@@ -47,20 +45,20 @@ case class FilesWatcher(ctx: LeonContext, files: Seq[File]) {
} }
def md5file(f: File): String = { def md5file(f: File): String = {
var buffer = new Array[Byte](1024) val buffer = new Array[Byte](1024)
val md = MessageDigest.getInstance("MD5"); val md = MessageDigest.getInstance("MD5")
try { try {
val is = Files.newInputStream(f.toPath) val is = Files.newInputStream(f.toPath)
var read = 0; var read = 0
do { do {
read = is.read(buffer); read = is.read(buffer)
if (read > 0) { if (read > 0) {
md.update(buffer, 0, read) md.update(buffer, 0, read)
} }
} while (read != -1); } while (read != -1)
is.close() is.close()
val bytes = md.digest(); val bytes = md.digest()
("%0" + (bytes.length << 1) + "X").format(new BigInteger(1, bytes)); ("%0" + (bytes.length << 1) + "X").format(new BigInteger(1, bytes));
} catch { } catch {
case _: RuntimeException => case _: RuntimeException =>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment