summaryrefslogtreecommitdiff
path: root/src/main/scala/hbt/ReadWrite.scala
blob: 962c0ea438deba3f0246f5bf2126464f394362d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package hbt
import java.nio.{file => jnio}

trait ReadWrite[T] {
  def write(t: T, p: jnio.Path): Unit
  def read(p: jnio.Path): T
}

object ReadWrite{
  implicit object String extends ReadWrite[java.lang.String]{
    def write(t: String, p: jnio.Path) = {
      jnio.Files.createDirectories(p.getParent)
      jnio.Files.deleteIfExists(p)
      jnio.Files.write(p, t.getBytes)
    }
    def read(p: jnio.Path) = {
      new String(jnio.Files.readAllBytes(p))
    }
  }
}