Skip to content

Commit 9ca1523

Browse files
committed
improve perf by writing to buffered stream
1 parent 329a46e commit 9ca1523

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

core/src/main/kotlin/com/fractalwrench/json2kotlin/SourceFileWriter.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package com.fractalwrench.json2kotlin
22

33
import com.squareup.kotlinpoet.FileSpec
44
import com.squareup.kotlinpoet.TypeSpec
5+
import java.io.BufferedWriter
56
import java.io.OutputStream
7+
import java.io.OutputStreamWriter
68
import java.util.*
79

810
/**
911
* Writes a collection of types to a source file OutputStream.
1012
*/
11-
internal class SourceFileWriter { // TODO rename once functionality has changed
13+
internal class SourceFileWriter {
1214

1315
/**
1416
* Writes a collection of types to a source file OutputStream.
@@ -21,10 +23,9 @@ internal class SourceFileWriter { // TODO rename once functionality has changed
2123
sourceFile.addType(stack.pop())
2224
}
2325

24-
with(StringBuilder()) { // FIXME inefficient use of resources
25-
sourceFile.build().writeTo(this)
26-
output.write(toString().toByteArray())
27-
}
26+
val bufferedWriter = BufferedWriter(OutputStreamWriter(output))
27+
sourceFile.build().writeTo(bufferedWriter)
28+
bufferedWriter.flush()
2829
}
2930

3031
}

0 commit comments

Comments
 (0)