aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchuyler Eldridge2019-08-05 18:12:58 -0400
committerSchuyler Eldridge2019-08-05 18:12:58 -0400
commit19f7a42c0809074aebcbc8a341f8c8ccda812799 (patch)
tree47840db23216ea53a10031346763cd244427d9df /src
parentac42287bc47fb8bc6695ae0aaf8f4fee61e129e5 (diff)
Iterate 1x in FileUtils.getText, DRY out getText
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/FileUtils.scala20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/main/scala/firrtl/FileUtils.scala b/src/main/scala/firrtl/FileUtils.scala
index 1007eb2a..8e73b4f9 100644
--- a/src/main/scala/firrtl/FileUtils.scala
+++ b/src/main/scala/firrtl/FileUtils.scala
@@ -97,12 +97,7 @@ object FileUtils {
*
* @param fileName The file to read
*/
- def getLines(fileName: String): Seq[String] = {
- val source = scala.io.Source.fromFile(fileName)
- val lines = source.getLines()
- source.close()
- lines.toSeq
- }
+ def getLines(fileName: String): Seq[String] = getLines(new File(fileName))
/** Read a text file and return it as a Seq of strings
* Closes the file after read to avoid dangling file handles
@@ -111,9 +106,9 @@ object FileUtils {
*/
def getLines(file: File): Seq[String] = {
val source = scala.io.Source.fromFile(file)
- val lines = source.getLines()
+ val lines = source.getLines().toList
source.close()
- lines.toSeq
+ lines
}
/** Read a text file and return it as a single string
@@ -121,12 +116,7 @@ object FileUtils {
*
* @param fileName The file to read
*/
- def getText(fileName: String): String = {
- val source = scala.io.Source.fromFile(fileName)
- val text = source.mkString
- source.close()
- text
- }
+ def getText(fileName: String): String = getText(new File(fileName))
/** Read a text file and return it as a single string
* Closes the file after read to avoid dangling file handles
@@ -167,4 +157,4 @@ object FileUtils {
inputStream.close()
text
}
-} \ No newline at end of file
+}