CORDA-2157: Close inputStream properly in withContractsInJar (#4365)

Or else the file remains open and test `VaultQueryJavaTests.testAttachmentQueryCriteria` fails on Windows as
open for reading files cannot be deleted.
This commit is contained in:
Viktor Kolomeyko 2018-12-05 18:55:44 +00:00 committed by GitHub
parent 42252cd967
commit 5ad992d01f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,7 +51,9 @@ private val logger = LoggerFactory.getLogger("ClassloaderUtils")
fun <T> withContractsInJar(jarInputStream: InputStream, withContracts: (List<ContractClassName>, InputStream) -> T): T {
val tempFile = Files.createTempFile("attachment", ".jar")
try {
jarInputStream.copyTo(tempFile, StandardCopyOption.REPLACE_EXISTING)
jarInputStream.use {
it.copyTo(tempFile, StandardCopyOption.REPLACE_EXISTING)
}
val cordappJar = tempFile.toAbsolutePath()
val contracts = logElapsedTime("Contracts loading for '$cordappJar'", logger) {
ContractsJarFile(tempFile.toAbsolutePath()).scan()