Skip to content

Commit

Permalink
#9: File.resource util
Browse files Browse the repository at this point in the history
  • Loading branch information
pathikrit committed Feb 14, 2017
1 parent 8754b8b commit ffda06b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/better/files/File.scala
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,8 @@ class File private(val path: Path) {
object File {
implicit val defaultCharset: Charset = Charset.defaultCharset()

def charset(name: String): Charset =
Charset.forName(name)
def resource(name: String): File =
File(Thread.currentThread().getContextClassLoader.getResource(name))

def newTemporaryDirectory(prefix: String = "", parent: Option[File] = None)(implicit attributes: Attributes = Attributes.default): File = {
parent match {
Expand Down
4 changes: 1 addition & 3 deletions core/src/test/scala/better/files/FileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class FileSpec extends FlatSpec with BeforeAndAfterEach with Matchers {
case _ => false
}

def resource(name: String) = File(Thread.currentThread().getContextClassLoader.getResource(name))

def sleep(t: FiniteDuration = 2 second) = Thread.sleep(t.toMillis)

var testRoot: File = _ //TODO: Get rid of mutable test vars
Expand Down Expand Up @@ -498,7 +496,7 @@ class FileSpec extends FlatSpec with BeforeAndAfterEach with Matchers {
}

it should "handle BOM" in {
val file = resource("file_with_bom.txt")
val file = File.resource("file_with_bom.txt")
val expectedContent = "I contain an offending UTF-8 BOM\n"
file.contentAsString should not equal expectedContent
file.contentAsString(charset = UnicodeDecoder("UTF-8")) shouldEqual expectedContent
Expand Down

0 comments on commit ffda06b

Please sign in to comment.