package es.usj.svit.util import java.io.BufferedWriter import java.io.File import java.net.URI import java.nio.file.Files import java.nio.file.Paths object IO { fun getResourcePath(name: String): URI { return Thread.currentThread().contextClassLoader.getResource(name)?.toURI()!! } fun getConfiguration(name: String): Array { val content = mutableListOf() Files.lines(Paths.get(getResourcePath(name))).use { stream -> stream.forEach { line -> content.add(line) } } return content.toTypedArray() } fun mkdirsIfNotExist(path: String): File { val file = File(path) val parent = file.parentFile check(!(parent != null && !parent.exists() && !parent.mkdirs())) { "Couldn't create dir: $parent" } return file } fun writeToFile(path: String, content: Array) { mkdirsIfNotExist(path).bufferedWriter().use { out -> content.forEach { line -> out.writeLn(line) } } } } fun BufferedWriter.writeLn(str: String) { this.write(str) this.newLine() }