feat: govern knowledge assets and source citations
This commit is contained in:
+22
@@ -318,6 +318,28 @@ public class OssClient {
|
||||
}
|
||||
}
|
||||
|
||||
/** Streams one RFC 7233 byte range without buffering the object in application memory. */
|
||||
public void downloadRange(String key, String range, OutputStream out, Consumer<GetObjectResponse> responseConsumer) {
|
||||
try {
|
||||
DownloadRequest.TypedBuilder<ResponsePublisher<GetObjectResponse>> typedBuilder = DownloadRequest.builder()
|
||||
.responseTransformer(AsyncResponseTransformer.toPublisher())
|
||||
.getObjectRequest(y -> y.bucket(properties.getBucketName()).key(key).range(range).build());
|
||||
Download<ResponsePublisher<GetObjectResponse>> download = transferManager.download(typedBuilder.build());
|
||||
ResponsePublisher<GetObjectResponse> publisher = download.completionFuture().join().result();
|
||||
Optional.ofNullable(responseConsumer).ifPresent(consumer -> consumer.accept(publisher.response()));
|
||||
try (WritableByteChannel channel = Channels.newChannel(out)) {
|
||||
publisher.subscribe(buffer -> {
|
||||
while (buffer.hasRemaining()) {
|
||||
try { channel.write(buffer); }
|
||||
catch (IOException e) { throw new RuntimeException(e); }
|
||||
}
|
||||
}).join();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new OssException("文件范围下载失败,错误信息:[" + e.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除云存储服务中指定路径下文件
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user