| author | Tomas Zeman <tzeman@volny.cz> |
| Tue, 11 Dec 2018 21:33:20 +0100 | |
| changeset 16 | 4556852613a9 |
| child 18 | 8cfd67425811 |
| permissions | -rw-r--r-- |
|
16
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
1 |
package sqwl |
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
2 |
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
3 |
import java.nio.file.Path |
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
4 |
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
5 |
import scala.io.Source |
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
6 |
import scala.util.{Failure, Success, Try}
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
7 |
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
8 |
package object cms {
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
9 |
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
10 |
def readFile(f: Path, enc: String = "UTF-8"): Try[String] = {
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
11 |
val src = Source.fromFile(f.toFile, enc) |
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
12 |
try {
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
13 |
Success(src.getLines.mkString) |
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
14 |
} catch {
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
15 |
case t: Throwable => Failure(t) |
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
16 |
} finally {
|
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
17 |
src.close() |
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
18 |
} |
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
19 |
} |
|
4556852613a9
Scalatex based article implementation
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
20 |
} |