com.ossuminc.riddl.utils.OutputFile.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of riddl-utils_3 Show documentation
Show all versions of riddl-utils_3 Show documentation
Various utilities used throughout riddl libraries
/*
* Copyright 2019 Ossum, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
package com.ossuminc.riddl.utils
import java.io.PrintWriter
import java.nio.file.Path
trait OutputFile extends FileBuilder {
def filePath: Path
def write(writer: PrintWriter): Unit = {
try {
writer.write(sb.toString())
writer.flush()
} finally { writer.close() }
sb.clear() // release memory because content written to file
}
private def mkDirs(): Unit = {
val dirFile = filePath.getParent.toFile
if !dirFile.exists then { dirFile.mkdirs() }
}
def write(): Unit = {
mkDirs()
val writer = new PrintWriter(filePath.toFile)
write(writer)
}
}