- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个遗留库,我必须使用它来检索文件。这个遗留库不会返回 InputStream,正如您通常期望的那样读取内容,但它期望它传递一个开放的 OutputStream,它可以写入。
我必须编写一个 Webflux REST 服务,将此 OutputStream 写入 org.springframework.web.reactive.function.server.ServerResponse 主体。
legacyLib.BlobRead(outputStream); // writes the stream to an outputstream, that has to be provided by me, and somehow has to end up in the ServerResponse
因为我想将 Stream 直接传递给 ServerResponse,我可能必须做这样的事情,对吧?
ServerResponse.ok().body(magicOutpuStreamToFluxConverter(), DataBuffer.class);
最佳答案
这是 RequestHandler 的重要部分。我遗漏了一些通常不需要的错误处理/异常捕获。请注意,我为读取publishedOn
一个不同的Scheduler
(或者至少,这是我想做的),这样阻塞读取就不会干扰我的主要事件主题:
private Mono<ServerResponse> writeToServerResponse(@NotNull FPTag tag) {
final long blobSize = tag.getBlobSize();
return ServerResponse.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(Flux.<DataBuffer>create((FluxSink<DataBuffer> emitter) -> {
// for a really big blob I want to read it in chunks, so that my server doesn't use too much memory
for(int i = 0; i < blobSize; i+= tagChunkSize) {
// new DataBuffer that is written to, then emitted later
DefaultDataBuffer dataBuffer = new DefaultDataBufferFactory().allocateBuffer();
try (OutputStream outputStream = dataBuffer.asOutputStream()) {
// write to the outputstream of DataBuffer
tag.BlobReadPartial(outputStream, i, tagChunkSize, FPLibraryConstants.FP_OPTION_DEFAULT_OPTIONS);
// don't know if flushing is strictly neccessary
outputStream.flush();
} catch (IOException | FPLibraryException e) {
log.error("Error reading + writing from tag to http outputstream", e);
emitter.error(e);
}
emitter.next(dataBuffer);
}
// if blob is finished, send "complete" to my flux of DataBuffers
emitter.complete();
}, FluxSink.OverflowStrategy.BUFFER).publishOn(Schedulers.newElastic("centera")).doOnComplete(() -> closeQuietly(tag)), DataBuffer.class);
}
关于spring-webflux - 将对 OutputStream 的写入转换为 ServerResponse 可用的 Flux<DataBuffer>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49426304/
当我正要调查 BufferedImage 的内部实现时在Java中,我遇到了DataBuffer 。 DataBuffer最后是用来保存空白图像数据的,只能用相关的ColorModel来解读和 Sam
我正在编写一个org.springframework.cloud.gateway.filter.GatewayFilter(spring-cloud-gateway),它尝试使用遵循特定任意协议(pr
我正在制作一个 Android 应用程序,我希望该应用程序使用 json 和 POST 将数据添加到我的 mysql 数据库。 日志猫: 11-15 17:29:44.928: E/DataHolde
本文整理了Java中us.ihmc.yoVariables.dataBuffer.YoVariableHolder类的一些代码示例,展示了YoVariableHolder类的具体用法。这些代码示例主要
我创建了一个 spring-cloud gateway 项目,但是我无法从 serverHttpRequest.body 获取数据,似乎 body.subscribe 不起作用。我应该如何从 body
我有以下java代码 final byte[] pixels; DataBuffer rasterData = image.getRaster().getDataBuffer(); DataBuffe
我正在使用 AppState 来存储我当前的 Android 应用程序数据。当我调用load 方法并设置回调监听器 我在 logcat 输出中看到以下内容。 Internal data leak wi
我需要在没有中间存储的情况下读取和写入压缩 (GZIP) 流。目前,我正在使用 Spring RestTemplate进行写入,Apache HTTP 客户端进行读取(请参阅我的回答 here 以了解
我正在使用 spring boot 版本 - 2.0.6.RELEASE 和 spring cloud 版本 - Finchley.SR2 并且我已经创建了我的自定义网关过滤器来修改请求正文。 但是在
我正在尝试使用 TYPE_3BYTE_BGR 类型的 BufferedImage 的底层 DataBufferByte 尽快设置像素值。 也许我没有理解,但是当我执行以下操作时...... byte[
我正在为我的 spring-boot 应用程序使用 WebClient 和自定义 BodyExtractor类 WebClient webLCient = WebClient.create(); we
本文整理了Java中us.ihmc.yoVariables.dataBuffer.YoVariableHolder.getVariable()方法的一些代码示例,展示了YoVariableHolder
我目前正在研究 Spring WebFlux。 我正在尝试使用 Spring WebFlux 上传大文件 (70mo)。 我的 Controller @RequestMapping(method =
这是我的 Java 代码: import java.awt.image.DataBuffer; public class B extends DataBuffer { public float[]
这几行代码检索图像所有像素的数组。 ImageInputStream is = ImageIO.createImageInputStream(f); Iterator iter = ImageIO.g
我有一个遗留库,我必须使用它来检索文件。这个遗留库不会返回 InputStream,正如您通常期望的那样读取内容,但它期望它传递一个开放的 OutputStream,它可以写入。 我必须编写一个 We
我正在动态构建一个 tarball,并希望将其直接流式传输回来,使用 .tar.gz 应该是 100% 可能的。 通过大量谷歌搜索,下面的代码是我能得到的最接近 dataBuffer 的代码。基本上,
我正在尝试通过网络从 Windows 上用 C# 编写的程序向使用 Flatbuffers 用 java 编写的 Android 应用程序发送 float 。 根据 Android 应用程序中接收到的
我正在尝试对来自 LIDAR 传感器的数据进行动画处理,但在尝试对其进行动画处理时出现此错误!希望您能帮助解决这个问题,我对Python编程很陌生,非常感谢! 这是我遇到的问题: File "C:\U
我需要通过 REST 下载非常大的文件并将其存储到 Azure Blobstorage。我面临着一些问题。 对于所有示例,我都使用此调用来获取数据 var flux = this.webClient
我是一名优秀的程序员,十分优秀!