Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 5803f02

Browse files
committed
Reapply "refactor: use Closeable#use extension where applicable"
This reverts commit 04f4b98.
1 parent 7e1ed55 commit 5803f02

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ class PasswordExportService : Service() {
8989
val destOutputStream = contentResolver.openOutputStream(targetPasswordFile.uri)
9090

9191
if (destOutputStream != null && sourceInputStream != null) {
92-
sourceInputStream.copyTo(destOutputStream, 1024)
93-
94-
sourceInputStream.close()
95-
destOutputStream.close()
92+
sourceInputStream.use { source -> destOutputStream.use { dest -> source.copyTo(dest) } }
9693
}
9794
}
9895
}

crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public class PGPainlessCryptoHandler @Inject constructor() :
6565
.addDecryptionKeys(keyringCollection, protector)
6666
.addDecryptionPassphrase(Passphrase.fromPassword(passphrase))
6767
)
68-
Streams.pipeAll(decryptionStream, outputStream)
69-
decryptionStream.close()
68+
decryptionStream.use { Streams.pipeAll(it, outputStream) }
7069
return@runCatching
7170
}
7271
.mapError { error ->
@@ -121,8 +120,7 @@ public class PGPainlessCryptoHandler @Inject constructor() :
121120
.setAsciiArmor(options.isOptionEnabled(PGPEncryptOptions.ASCII_ARMOR))
122121
val encryptionStream =
123122
PGPainless.encryptAndOrSign().onOutputStream(outputStream).withOptions(producerOptions)
124-
Streams.pipeAll(plaintextStream, encryptionStream)
125-
encryptionStream.close()
123+
encryptionStream.use { Streams.pipeAll(plaintextStream, it) }
126124
val result = encryptionStream.result
127125
publicKeyRingCollection.forEach { keyRing ->
128126
require(result.isEncryptedFor(keyRing)) {

0 commit comments

Comments
 (0)