rocketraman
07/03/2018, 4:16 PMrocketraman
07/03/2018, 4:17 PMOutgoingContent.WriteChannelContent
somehow, but its unclear to me how.rocketraman
07/03/2018, 4:18 PMjava.io.Writer
(or OutputStream
) to the body.Deactivated User
07/03/2018, 4:23 PMsuspend fun InputStream.toByteChannel(dispatcher: CoroutineDispatcher = ioCoroutineDispatcher): ByteReadChannel {
val inputStream = this
return writer(dispatcher) {
while (true) {
val temp = ByteArray(1024)
val readSize = inputStream.read(temp)
if (readSize <= 0) break
channel.writeFully(temp, 0, readSize)
}
}.channel
}
Deactivated User
07/03/2018, 4:26 PMsuspend fun OutputStream.toByteWriteChannel(dispatcher: CoroutineDispatcher = ioCoroutineDispatcher): ByteWriteChannel {
val outputStream = this
return reader(dispatcher) {
while (true) {
val temp = ByteArray(1024)
val readSize = channel.readAvailable(temp)
if (readSize <= 0) break
outputStream.write(temp, 0, readSize)
}
}.channel
}
rocketraman
07/03/2018, 4:36 PMByteReadChannel.toInputStream()
.rocketraman
07/03/2018, 4:43 PMOutputStream
... I'd rather create an OutputStream
connected to a ByteWriteChannel
. So I think I just need to create a new ByteWriteChannel
and call toOutputStream
on it.rocketraman
07/03/2018, 4:44 PMByteWriteChannel
from?rocketraman
07/03/2018, 4:46 PMByteChannel(true).toOutputStream()
?Deactivated User
07/03/2018, 4:47 PMDeactivated User
07/03/2018, 4:47 PMDeactivated User
07/03/2018, 4:47 PMrocketraman
07/03/2018, 4:54 PMOutgoingContent
that is a ByteWriteChannel
, from which it looks like I can do toOutputStream
. But it seems that class is internal, so I don't have a way to create it.rocketraman
07/03/2018, 5:17 PMDeactivated User
07/03/2018, 5:55 PMDeactivated User
07/03/2018, 5:57 PMDeactivated User
07/03/2018, 5:58 PMDeactivated User
07/03/2018, 6:12 PMOutgoingContent
has several abstract inner classes, (if you look at the implementations of those classes)rocketraman
07/03/2018, 6:35 PMWriteChannelContent
I'll get a writeTo
callback in which I can write to the output stream?Deactivated User
07/03/2018, 6:36 PMrocketraman
07/05/2018, 4:13 PMWriterContent
worked as expected, BUT I note this class is in the server-core package, so it cannot easily be used as OutgoingContent
in the ktor client. Should this and other implementations of OutgoingContent
be moved to somewhere common to client and server?Deactivated User
07/05/2018, 4:46 PMrocketraman
07/05/2018, 4:50 PM