Reputation: 889
In my spring application, I am getting FilePart object and need to convert it to byteArray.
Below is my code.
val byteArray: ByteArray = file.content().map { it -> it.asInputStream().readBytes() }.blockLast()!!
But it is giving me error as
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-kqueue-3
Upvotes: 1
Views: 2928
Reputation: 837
Take a look at DataBufferUtils, the join(...) method offers a safe and efficient way to aggregate a data buffer stream into a single data buffer
Mono<byte[]> getByteArray(FilePart filePart) {
return DataBufferUtils.join(filePart.content())
.map(dataBuffer -> dataBuffer.asByteBuffer().array());
}
Upvotes: 3