Created
June 9, 2016 13:18
-
-
Save igor-vovk/ae643501bc103a3a8ed599ed4188fe2c to your computer and use it in GitHub Desktop.
ficus read file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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