Skip to content

Commit

Permalink
Increase thread safety
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbrooks committed Aug 27, 2024
1 parent b13ea2c commit 417ee42
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions vgo/src/main/kotlin/com/jzbrooks/vgo/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ class Application {
input.inputStream().use { inputStream ->
val sizeBefore = inputStream.channel.size()

val document = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder().parse(input)
val documentBuilderFactory = DocumentBuilderFactory.newInstance()

val document = documentBuilderFactory.newDocumentBuilder().parse(input)
document.documentElement.normalize()

val rootNodes = document.childNodes.asSequence().filter { it.nodeType == Document.ELEMENT_NODE }.toList()
Expand All @@ -164,7 +166,7 @@ class Application {
} else {
val pipeTerminal = ByteArrayInputStream(pipeOrigin.toByteArray())
val convertedDocument =
DOCUMENT_BUILDER_FACTORY.newDocumentBuilder().parse(pipeTerminal)
documentBuilderFactory.newDocumentBuilder().parse(pipeTerminal)
convertedDocument.documentElement.normalize()

val documentRoot =
Expand Down Expand Up @@ -289,7 +291,6 @@ class Application {
get() = key.isDirectory && (value.isDirectory || !value.exists())

companion object {
private val DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance()
private const val HELP_MESSAGE = """
> vgo [options] [file/directory]
Expand Down

0 comments on commit 417ee42

Please sign in to comment.