equal
deleted
inserted
replaced
5 import scala.io.Source |
5 import scala.io.Source |
6 import scala.util.{Failure, Success, Try} |
6 import scala.util.{Failure, Success, Try} |
7 |
7 |
8 package object cms { |
8 package object cms { |
9 |
9 |
10 def readFile(f: Path, enc: String = "UTF-8"): Try[String] = { |
10 def readSourceFull(src: Source): Try[String] = { |
11 val src = Source.fromFile(f.toFile, enc) |
|
12 try { |
11 try { |
13 Success(src.getLines.mkString) |
12 Success(src.getLines.mkString) |
14 } catch { |
13 } catch { |
15 case t: Throwable => Failure(t) |
14 case t: Throwable => Failure(t) |
16 } finally { |
15 } finally { |
17 src.close() |
16 src.close() |
18 } |
17 } |
19 } |
18 } |
|
19 |
|
20 def readFile(f: Path, enc: String = "UTF-8"): Try[String] = |
|
21 readSourceFull(Source.fromFile(f.toFile, enc)) |
|
22 |
|
23 def readFile(f: String): String = |
|
24 readSourceFull(Source.fromFile(f, "UTF-8")) getOrElse "" |
|
25 |
20 } |
26 } |