Skip to content

Commit 3c44868

Browse files
closed leaked streams
1 parent bcb9e2e commit 3c44868

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/main/kotlin/com/haulmont/cuba/cli/generation/Snippets.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Snippets(private val snippetsPath: Path) {
2626

2727
operator fun get(name: String): String {
2828
if (name !in snippets) {
29-
snippets[name] = Files.newInputStream(snippetsPath.resolve(name)).reader().readText()
29+
snippets[name] = Files.newInputStream(snippetsPath.resolve(name)).use { stream -> stream.reader().readText() }
3030
}
3131
return snippets[name]!!
3232
}

src/main/kotlin/com/haulmont/cuba/cli/generation/TemplateProcessor.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,19 @@ class TemplateProcessor(templateBasePath: Path, private val bindings: Map<String
152152
return kClass.memberProperties.first { it.name == name }.getter.call(obj)!!
153153
}
154154

155-
fun copy(subPath: Path, to: Path = projectRoot, filter: PathFilter = {true}) {
155+
fun copy(subPath: Path, to: Path = projectRoot, filter: PathFilter = { true }) {
156156
process(templatePath.resolve(subPath), to, false, filter)
157157
}
158158

159-
fun copy(subPath: String, to: Path = projectRoot, filter: PathFilter = {true}) {
159+
fun copy(subPath: String, to: Path = projectRoot, filter: PathFilter = { true }) {
160160
process(templatePath.resolve(subPath), to, false, filter)
161161
}
162162

163-
fun transform(subPath: Path, to: Path = projectRoot, filter: PathFilter = {true}) {
163+
fun transform(subPath: Path, to: Path = projectRoot, filter: PathFilter = { true }) {
164164
process(templatePath.resolve(subPath), to, true, filter)
165165
}
166166

167-
fun transform(subPath: String, to: Path = projectRoot, filter: PathFilter = {true}) {
167+
fun transform(subPath: String, to: Path = projectRoot, filter: PathFilter = { true }) {
168168
process(templatePath.resolve(subPath), to, true, filter)
169169
}
170170

@@ -188,7 +188,9 @@ class TemplateProcessor(templateBasePath: Path, private val bindings: Map<String
188188

189189
check(Files.isRegularFile(filePath)) { "Only file may be saved to output stream" }
190190

191-
Files.newInputStream(filePath).copyTo(to)
191+
Files.newInputStream(filePath).use {
192+
it.copyTo(to)
193+
}
192194
}
193195

194196
fun transformWhole(to: Path = projectRoot) {
@@ -225,8 +227,9 @@ class TemplateProcessor(templateBasePath: Path, private val bindings: Map<String
225227
.takeIf { Files.exists(it) }
226228
?.let {
227229
Files.newInputStream(it)
228-
.bufferedReader()
229-
.readText()
230+
.use { stream ->
231+
stream.bufferedReader().readText()
232+
}
230233
}
231234
}
232235
}

src/main/kotlin/com/haulmont/cuba/cli/generation/VelocityHelper.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class VelocityHelper {
3838
}
3939

4040
fun generate(inputPath: Path, vc: VelocityContext): String {
41-
val templateText = Files.newInputStream(inputPath)
42-
.bufferedReader().readText()
41+
val templateText = Files.newInputStream(inputPath).use {
42+
it.bufferedReader().readText()
43+
}
4344
val templateName = generate(templateText, inputPath.fileName.toString(), vc)
4445

4546
return generate(templateText, templateName, vc)

src/main/kotlin/com/haulmont/cuba/cli/generation/XmlUtils.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ import javax.xml.parsers.ParserConfigurationException
3737
private val writer: PrintWriter by kodein.instance()
3838
private val printHelper: PrintHelper by kodein.instance()
3939

40-
fun parse(path: Path): Document = Files.newInputStream(path).let(::InputSource).let {
41-
createDocumentBuilder().parse(it)
40+
fun parse(path: Path): Document = Files.newInputStream(path).use { stream ->
41+
InputSource(stream).let {
42+
createDocumentBuilder().parse(it)
43+
}
4244
}
4345

4446
fun parse(xml: String): Document = xml.let(::StringReader).let(::InputSource).let {

0 commit comments

Comments
 (0)