Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
theodelrieu committed Aug 14, 2019
1 parent 8f12160 commit e86b40f
Show file tree
Hide file tree
Showing 22 changed files with 238 additions and 568 deletions.
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ org.gradle.jvmargs=-Xmx1024m
# The Android Gradle Plugin uses deprecated APIs, they have until Gradle 6.0 to fix their crap.
# https://android.googlesource.com/platform/tools/base/+/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/scope/BuildArtifactsHolder.kt
org.gradle.warning.mode=none
android.enableJetifier=true
android.useAndroidX=true
2 changes: 0 additions & 2 deletions tanker-bindings/gradle.properties

This file was deleted.

Binary file removed tanker-bindings/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 0 additions & 6 deletions tanker-bindings/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

172 changes: 0 additions & 172 deletions tanker-bindings/gradlew

This file was deleted.

84 changes: 0 additions & 84 deletions tanker-bindings/gradlew.bat

This file was deleted.

3 changes: 0 additions & 3 deletions tanker-bindings/proguard-rules.pro

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.nio.channels.AsynchronousByteChannel
import java.nio.channels.CompletionHandler

@RequiresApi(26)
class AsynchronousByteChannelWrapper(private val channel: AsynchronousByteChannel) : TankerAsynchronousByteChannel {
internal class AsynchronousByteChannelWrapper(private val channel: AsynchronousByteChannel) : TankerAsynchronousByteChannel {
override fun close() {
channel.close()
}
Expand All @@ -15,15 +15,16 @@ class AsynchronousByteChannelWrapper(private val channel: AsynchronousByteChanne
return channel.isOpen
}

override fun <A> read(dst: ByteBuffer?, attachment: A, handler: TankerCompletionHandler<Int, in A>?) {
override fun <A> read(dst: ByteBuffer, attachment: A, handler: TankerCompletionHandler<Int, in A>) {
// CompletionHandler is API 26 only, hence the boilerplate
channel.read(dst, attachment, object : CompletionHandler<Int, A> {
override fun completed(result: Int, attachment: A) {
handler!!.completed(result, attachment)
handler.completed(result, attachment)
}

override fun failed(exc: Throwable, attachment: A) {
handler!!.failed(exc, attachment)
handler.failed(exc, attachment)
}
})
}
}
}
39 changes: 21 additions & 18 deletions tanker-bindings/src/main/kotlin/io/tanker/api/InputStreamWrapper.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
package io.tanker.api

import java.io.IOException
import java.io.InputStream
import java.nio.ByteBuffer
import java.util.concurrent.Future

class InputStreamWrapper(private val inputStream: InputStream) : TankerAsynchronousByteChannel {
companion object {
private var isClosed = false
}

override fun <A> read(dst: ByteBuffer?, attachment: A, handler: TankerCompletionHandler<Int, in A>?) {
class InputStreamWrapper(private var inputStream: InputStream?) : TankerAsynchronousByteChannel {
override fun <A> read(dst: ByteBuffer, attachment: A, handler: TankerCompletionHandler<Int, in A>) {
TankerFuture.threadPool.execute {
try {
val b = ByteArray(dst!!.remaining())
val nbRead = inputStream.read(b)
if (nbRead != -1) {
dst.put(b, 0, nbRead)
if (!isOpen)
handler.failed(IOException("Stream is closed"), attachment)
else {
try {
val b = ByteArray(dst.remaining())
val nbRead = inputStream!!.read(b)
if (nbRead != -1) {
dst.put(b, 0, nbRead)
}
handler.completed(nbRead, attachment)
} catch (e: Throwable) {
handler.failed(e, attachment)
}
handler!!.completed(nbRead, attachment)
} catch (e: Throwable) {
handler!!.failed(e, attachment)
}
}
}

override fun isOpen(): Boolean {
return !isClosed
return inputStream != null
}

override fun close() {
inputStream.close()
isClosed = true
if (inputStream != null) {
inputStream!!.close()
inputStream = null
}
}
}
Loading

0 comments on commit e86b40f

Please sign in to comment.