-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f12160
commit e86b40f
Showing
22 changed files
with
238 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 21 additions & 18 deletions
39
tanker-bindings/src/main/kotlin/io/tanker/api/InputStreamWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.