Skip to content

Instantly share code, notes, and snippets.

@igor-vovk
Created June 9, 2016 13:18
Show Gist options
  • Save igor-vovk/ae643501bc103a3a8ed599ed4188fe2c to your computer and use it in GitHub Desktop.
Save igor-vovk/ae643501bc103a3a8ed599ed4188fe2c to your computer and use it in GitHub Desktop.
ficus read file
package com.x2sy.logserver
import java.io.File
import com.typesafe.config.Config
import com.typesafe.config.ConfigException.BadValue
import net.ceedubs.ficus.readers.ValueReader
trait FicusFileReader {
private val Resource = "resource\\((.*)\\)".r
private val File = "file\\((.*)\\)".r
implicit val fileValueReader: ValueReader[File] = new ValueReader[File] {
override def read(config: Config, path: String): File = {
val str = config.getString(path)
str match {
case Resource(name) => new File(classloader.getResource(name).getFile)
case File(name) => new File(name)
case _ => throw new BadValue(config.origin(), path,
s"Could not parse file path: resource(...) or file(...) is required, but \'$str\' is passed")
}
}
}
private def classloader = Thread.currentThread.getContextClassLoader
}
object FicusFileReader extends FicusFileReader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment