TLDR:如何使用Spring WebClient (reactive )逐行处理响应?
详细信息:
不幸的是,我没有找到任何将Flux<ByteBuffer>转换为Flux<String>的解决方案(在行尾拆分)。
问题:是否有任何嵌入式转换器/解码器可以这样做?
可能的解决办法:
另外:您不能仅仅将输入缓冲区转换为字符串,因为一些utf8字符可以从缓冲区N开始,在缓冲区N+1继续。
发布于 2019-07-24 08:40:42
下面的代码可以工作,但是这是完全同步的代码(可能只是预取能力)。它使用Apache Http组件。
HttpClientBuilder.create().build().use { client ->
val responseHandler = ResponseHandler { response ->
response.entity.content.use { content ->
content.bufferedReader().use { buffered ->
// create class, which can process each line.
val processor = StreamedLinesProcessor<TResult>()
do {
val nextLine = buffered.readLine()
val needContinue = processor.processNextLine(nextLine)
} while (needContinue)
processor.getResult()
}
}
}
client.execute(HttpGet(url.toString()), responseHandler)
}https://stackoverflow.com/questions/57162062
复制相似问题