aboutsummaryrefslogtreecommitdiffstats
path: root/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/ParcelFileDescriptorUtil.kt
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-03-09 14:53:11 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2021-03-18 11:40:30 +0530
commit774fda83ac276a635e3402034b1eedbd10be916f (patch)
tree57783a953fcd193d32f1e3dc8df26e07f03df328 /openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/ParcelFileDescriptorUtil.kt
parentbe31ae37f443982b377d027cd613f04d0926568d (diff)
downloadHardenedPass-774fda83ac276a635e3402034b1eedbd10be916f.tar.gz
HardenedPass-774fda83ac276a635e3402034b1eedbd10be916f.zip
all: reformat with ktfmt
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/ParcelFileDescriptorUtil.kt')
-rw-r--r--openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/ParcelFileDescriptorUtil.kt83
1 files changed, 40 insertions, 43 deletions
diff --git a/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/ParcelFileDescriptorUtil.kt b/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/ParcelFileDescriptorUtil.kt
index 58657118..26e04e97 100644
--- a/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/ParcelFileDescriptorUtil.kt
+++ b/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/ParcelFileDescriptorUtil.kt
@@ -14,50 +14,47 @@ import java.io.OutputStream
internal object ParcelFileDescriptorUtil {
- private const val TAG = "PFDUtils"
-
- @Throws(IOException::class)
- internal fun pipeFrom(inputStream: InputStream): ParcelFileDescriptor {
- val pipe = ParcelFileDescriptor.createPipe()
- val readSide = pipe[0]
- val writeSide = pipe[1]
- TransferThread(inputStream, AutoCloseOutputStream(writeSide))
- .start()
- return readSide
- }
-
- @Throws(IOException::class)
- internal fun pipeTo(outputStream: OutputStream, output: ParcelFileDescriptor?): TransferThread {
- val t = TransferThread(AutoCloseInputStream(output), outputStream)
- t.start()
- return t
- }
-
- internal class TransferThread(val `in`: InputStream, private val out: OutputStream) : Thread("IPC Transfer Thread") {
-
- override fun run() {
- val buf = ByteArray(4096)
- var len: Int
- try {
- while (`in`.read(buf).also { len = it } > 0) {
- out.write(buf, 0, len)
- }
- } catch (e: IOException) {
- Log.e(TAG, "IOException when writing to out", e)
- } finally {
- try {
- `in`.close()
- } catch (ignored: IOException) {
- }
- try {
- out.close()
- } catch (ignored: IOException) {
- }
- }
+ private const val TAG = "PFDUtils"
+
+ @Throws(IOException::class)
+ internal fun pipeFrom(inputStream: InputStream): ParcelFileDescriptor {
+ val pipe = ParcelFileDescriptor.createPipe()
+ val readSide = pipe[0]
+ val writeSide = pipe[1]
+ TransferThread(inputStream, AutoCloseOutputStream(writeSide)).start()
+ return readSide
+ }
+
+ @Throws(IOException::class)
+ internal fun pipeTo(outputStream: OutputStream, output: ParcelFileDescriptor?): TransferThread {
+ val t = TransferThread(AutoCloseInputStream(output), outputStream)
+ t.start()
+ return t
+ }
+
+ internal class TransferThread(val `in`: InputStream, private val out: OutputStream) : Thread("IPC Transfer Thread") {
+
+ override fun run() {
+ val buf = ByteArray(4096)
+ var len: Int
+ try {
+ while (`in`.read(buf).also { len = it } > 0) {
+ out.write(buf, 0, len)
}
+ } catch (e: IOException) {
+ Log.e(TAG, "IOException when writing to out", e)
+ } finally {
+ try {
+ `in`.close()
+ } catch (ignored: IOException) {}
+ try {
+ out.close()
+ } catch (ignored: IOException) {}
+ }
+ }
- init {
- isDaemon = true
- }
+ init {
+ isDaemon = true
}
+ }
}