Reapply "refactor: use Closeable#use extension where applicable"

This reverts commit 04f4b9804f.
This commit is contained in:
Harsh Shandilya 2024-09-28 23:35:54 +05:30
parent 7e1ed55ab7
commit 5803f0244a
2 changed files with 3 additions and 8 deletions

View file

@ -89,10 +89,7 @@ class PasswordExportService : Service() {
val destOutputStream = contentResolver.openOutputStream(targetPasswordFile.uri)
if (destOutputStream != null && sourceInputStream != null) {
sourceInputStream.copyTo(destOutputStream, 1024)
sourceInputStream.close()
destOutputStream.close()
sourceInputStream.use { source -> destOutputStream.use { dest -> source.copyTo(dest) } }
}
}
}

View file

@ -65,8 +65,7 @@ public class PGPainlessCryptoHandler @Inject constructor() :
.addDecryptionKeys(keyringCollection, protector)
.addDecryptionPassphrase(Passphrase.fromPassword(passphrase))
)
Streams.pipeAll(decryptionStream, outputStream)
decryptionStream.close()
decryptionStream.use { Streams.pipeAll(it, outputStream) }
return@runCatching
}
.mapError { error ->
@ -121,8 +120,7 @@ public class PGPainlessCryptoHandler @Inject constructor() :
.setAsciiArmor(options.isOptionEnabled(PGPEncryptOptions.ASCII_ARMOR))
val encryptionStream =
PGPainless.encryptAndOrSign().onOutputStream(outputStream).withOptions(producerOptions)
Streams.pipeAll(plaintextStream, encryptionStream)
encryptionStream.close()
encryptionStream.use { Streams.pipeAll(plaintextStream, it) }
val result = encryptionStream.result
publicKeyRingCollection.forEach { keyRing ->
require(result.isEncryptedFor(keyRing)) {