Skip to content

Commit

Permalink
Merge pull request #57 from netheril96/main
Browse files Browse the repository at this point in the history
Properly close resources after writing.
  • Loading branch information
keiji authored Mar 23, 2024
2 parents 4667e25 + 3b4fb9d commit 89fa0d9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 36 deletions.
24 changes: 13 additions & 11 deletions tlv-ksp/src/main/java/dev/keiji/tlv/BerTlvDecoderProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,19 @@ fun ${classDeclaration.simpleName.asString()}.readFrom(

val onItemDetected = generateOnItemDetected(annotatedProperties, logger)

file.appendText("package $packageName")
.appendText("")
.appendText(imports)
.appendText("")
.appendText(classTemplate0)
.appendText("")
.appendText(classTemplate1)
.appendText("")
.appendText(onItemDetected)
.appendText("")
.appendText(classTemplate2)
file.use {
it.appendText("package $packageName")
.appendText("")
.appendText(imports)
.appendText("")
.appendText(classTemplate0)
.appendText("")
.appendText(classTemplate1)
.appendText("")
.appendText(onItemDetected)
.appendText("")
.appendText(classTemplate2)
}
}

@Suppress("MaxLineLength")
Expand Down
16 changes: 9 additions & 7 deletions tlv-ksp/src/main/java/dev/keiji/tlv/BerTlvEncoderProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ fun ${classDeclaration.simpleName.asString()}.writeTo(outputStream: OutputStream

val writeTo = generateWriteTo(annotatedProperties)

file.appendText("package $packageName")
.appendText("")
.appendText(imports)
.appendText("")
.appendText(classTemplate1)
.appendText(writeTo)
.appendText(classTemplate2)
file.use {
it.appendText("package $packageName")
.appendText("")
.appendText(imports)
.appendText("")
.appendText(classTemplate1)
.appendText(writeTo)
.appendText(classTemplate2)
}
}

@Suppress("MaxLineLength")
Expand Down
24 changes: 13 additions & 11 deletions tlv-ksp/src/main/java/dev/keiji/tlv/CompactTlvDecoderProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,19 @@ fun ${classDeclaration.simpleName.asString()}.readFrom(

val onItemDetected = generateOnItemDetected(annotatedProperties, logger)

file.appendText("package $packageName")
.appendText("")
.appendText(imports)
.appendText("")
.appendText(classTemplate0)
.appendText("")
.appendText(classTemplate1)
.appendText("")
.appendText(onItemDetected)
.appendText("")
.appendText(classTemplate2)
file.use {
it.appendText("package $packageName")
.appendText("")
.appendText(imports)
.appendText("")
.appendText(classTemplate0)
.appendText("")
.appendText(classTemplate1)
.appendText("")
.appendText(onItemDetected)
.appendText("")
.appendText(classTemplate2)
}
}

@Suppress("MaxLineLength")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ fun ${classDeclaration.simpleName.asString()}.writeTo(outputStream: OutputStream

val writeTo = generateWriteTo(annotatedProperties)

file.appendText("package $packageName")
.appendText("")
.appendText(imports)
.appendText("")
.appendText(classTemplate1)
.appendText(writeTo)
.appendText(classTemplate2)
file.use {
it.appendText("package $packageName")
.appendText("")
.appendText(imports)
.appendText("")
.appendText(classTemplate1)
.appendText(writeTo)
.appendText(classTemplate2)
}
}

@Suppress("MaxLineLength")
Expand Down

0 comments on commit 89fa0d9

Please sign in to comment.