-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix resource loading when run from a JAR
- Loading branch information
Anael Ollier
committed
Jun 4, 2018
1 parent
aa6b92d
commit d374a3d
Showing
10 changed files
with
31 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
src/main/kotlin/com/github/dataanon/utils/FlatFileContentStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
package com.github.dataanon.utils | ||
|
||
import java.io.File | ||
|
||
object FlatFileContentStore { | ||
|
||
private var fileContent: HashMap<String, List<String>> = File(this::class.java.getResource("/data/").path) | ||
.walk() | ||
.filter { it.extension.equals("dat") } | ||
.associateByTo (HashMap(), { it.path }, { it.readLines() } ) | ||
private var fileContent: HashMap<String, List<String>> = HashMap() | ||
|
||
fun getFileContentByPath(path: String): List<String> = if ( !fileContent.containsKey(path) ) getFileContentPostRead(path) else fileContent[path] as List<String> | ||
|
||
|
||
private fun getFileContentPostRead(path: String): List<String> { | ||
fileContent[path] = File(path).readLines() | ||
val lineList = mutableListOf<String>() | ||
this::class.java.getResourceAsStream(path).bufferedReader().useLines { lines -> lines.forEach { lineList.add(it)} } | ||
|
||
fileContent[path] = lineList | ||
return fileContent[path] as List<String> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters