Skip to content

Commit

Permalink
bump to v1.3, load resource as stream (not file!), make filenames const
Browse files Browse the repository at this point in the history
  • Loading branch information
James authored and James committed May 5, 2019
1 parent f2f2612 commit b124d16
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'org.idiosapps'
version '1.2'
version '1.3'

repositories {
mavenCentral()
Expand Down
20 changes: 10 additions & 10 deletions src/main/kotlin/org/idiosapps/Filenames.kt
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
19 changes: 9 additions & 10 deletions src/main/kotlin/org/idiosapps/TexUtils.kt
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit b124d16

Please sign in to comment.