Skip to content

Commit

Permalink
FileOps: read/write using nio.Path
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 6, 2021
1 parent 51ae77f commit 82c42bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ object FileOps {
if (filename matches "https?://.*") {
scala.io.Source.fromURL(filename)("UTF-8").getLines().mkString("\n")
} else {
readFile(new File(filename))
readFile(Paths.get(filename))
}
}

def readFile(file: AbsoluteFile)(implicit codec: Codec): String = {
readFile(file.jfile)
readFile(file.asPath)
}

def readFile(file: File)(implicit codec: Codec): String = {
new String(Files.readAllBytes(file.toPath), codec.charSet)
def readFile(file: Path)(implicit codec: Codec): String = {
new String(Files.readAllBytes(file), codec.charSet)
}

def getFile(path: String*): File = {
Expand All @@ -69,11 +69,7 @@ object FileOps {
def writeFile(file: AbsoluteFile, content: String)(implicit
codec: Codec
): Unit = {
writeFile(file.jfile, content)
}

def writeFile(file: File, content: String)(implicit codec: Codec): Unit = {
writeFile(file.toPath, content)
writeFile(file.asPath, content)
}

def writeFile(path: Path, content: String)(implicit codec: Codec): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object FileTestOps {
row.stripPrefix("\n").split("\n", 2).toList
val file = new File(root, path)
file.getParentFile.mkdirs()
FileOps.writeFile(file, contents)
FileOps.writeFile(file.toPath, contents)
}
AbsoluteFile.fromPath(root.getAbsolutePath).get
}
Expand Down

0 comments on commit 82c42bb

Please sign in to comment.