Jose A.
09/14/2021, 11:59 AMpost {
val targetChannel = FileOutputStream(Files.createTempFile("job-", ".json").toFile()).channel
val originChannel = newChannel(call.receiveStream())
originChannel.use {
targetChannel.use {
targetChannel.transferFrom(originChannel, 0L, 100000)
}
}
...
FileOutputStream, etc. are blocking calls. Is there a nonblocking API to write to files so I can use receiveChannel()
?Aleksei Tirman [JB]
09/14/2021, 12:52 PMByteWriteChannel
instance created from a file to copy bytes from input to output channel:
post {
val tmpFile = Files.createTempFile("job-", ".json").toFile()
call.receiveChannel().copyTo(tmpFile.writeChannel())
}
Jose A.
09/14/2021, 1:50 PMAleksei Tirman [JB]
09/14/2021, 1:53 PMcall.receiveChannel().copyAndClose(tmpFile.writeChannel())
instead