From b124d164af7a7e6d6199eedbbc12d5dd39e89a46 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 5 May 2019 19:01:12 +0100 Subject: [PATCH] bump to v1.3, load resource as stream (not file!), make filenames const --- build.gradle | 2 +- src/main/kotlin/org/idiosapps/Filenames.kt | 20 ++++++++++---------- src/main/kotlin/org/idiosapps/TexUtils.kt | 19 +++++++++---------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index ea8cc53..1c9bfe0 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { } group 'org.idiosapps' -version '1.2' +version '1.3' repositories { mavenCentral() diff --git a/src/main/kotlin/org/idiosapps/Filenames.kt b/src/main/kotlin/org/idiosapps/Filenames.kt index 34cfa7d..b31975e 100644 --- a/src/main/kotlin/org/idiosapps/Filenames.kt +++ b/src/main/kotlin/org/idiosapps/Filenames.kt @@ -1,22 +1,22 @@ package org.idiosapps import java.io.File -import java.net.URL class Filenames { companion object { - val inputPrefix: String = "./input/" - val outputPrefix: String = "./output/" + private const val inputPrefix: String = "./input/" + private const val outputPrefix: String = "./output/" - val inputHeaderResource: URL = this::class.java.classLoader.getResource("org.idiosapps/texHeader") - val inputTitleFilename: String = inputPrefix + "title" - val inputStoryFilename: String = inputPrefix + "story" + val inputHeaderResource = this::class.java.classLoader.getResourceAsStream("org.idiosapps/texHeader") - val inputVocabFilename: String = inputPrefix + "vocab" - val inputKeyNamesFilename: String = inputPrefix + "names" + const val inputTitleFilename: String = inputPrefix + "title" + const val inputStoryFilename: String = inputPrefix + "story" - val outputTexFilename: String = outputPrefix + "outputStory.tex" - val outputPDFFilename: String = outputPrefix + "outputStory.pdf" + const val inputVocabFilename: String = inputPrefix + "vocab" + const val inputKeyNamesFilename: String = inputPrefix + "names" + + const val outputTexFilename: String = outputPrefix + "outputStory.tex" + const val outputPDFFilename: String = outputPrefix + "outputStory.pdf" fun checkInputs() { val inputArray = arrayListOf( diff --git a/src/main/kotlin/org/idiosapps/TexUtils.kt b/src/main/kotlin/org/idiosapps/TexUtils.kt index abba6ac..ab4b611 100644 --- a/src/main/kotlin/org/idiosapps/TexUtils.kt +++ b/src/main/kotlin/org/idiosapps/TexUtils.kt @@ -1,8 +1,7 @@ package org.idiosapps -import java.io.File -import java.io.PrintWriter -import java.net.URL +import java.io.* +import java.nio.charset.StandardCharsets import java.util.* class TexUtils { @@ -49,13 +48,13 @@ class TexUtils { scanner.close() } - fun copyToTex(outputStoryWriter: PrintWriter, inputResource: URL) { - val resourceFile = File(inputResource.toURI()) - - Scanner(resourceFile, "UTF-8").use { scanner -> - while (scanner.hasNextLine()) { - outputStoryWriter.println(scanner.nextLine()) - } + // can't load resource as file, so we have to read from a stream of the resource + fun copyToTex(outputStoryWriter: PrintWriter, resourceStream: InputStream) { + val reader = InputStreamReader(resourceStream, StandardCharsets.UTF_8) + val bufferedReader = BufferedReader(reader) + val lines = bufferedReader.lines() + lines.forEach { line -> + outputStoryWriter.println(line) } } }