可流动以执行任务并返回字符串Rx Java ReactiveX的列表

可流动以执行任务并返回字符串Rx Java ReactiveX的列表,java,rx-java,rx-java2,reactivex,rx-java3,Java,Rx Java,Rx Java2,Reactivex,Rx Java3,执行任务并最终使用可流动rxjva3返回值。我有下面的代码 public Maybe<List<String>> uploadObject(Publisher<CompletedFileUpload> images) { Storage storage = StorageOptions.getDefaultInstance().getService(); var returnValue = Flowable.fromPublis

执行任务并最终使用可流动rxjva3返回值。我有下面的代码

public Maybe<List<String>> uploadObject(Publisher<CompletedFileUpload> images) {
        Storage storage = StorageOptions.getDefaultInstance().getService();
        var returnValue = Flowable.fromPublisher(images)
                .collect((List<String> returnImages, CompletedFileUpload image) -> {
                    BlobId blobId = BlobId.of(googleUploadObjectConfiguration.bucketName(), image.getName());
                    BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
                    Blob updatedImage = storage.create(blobInfo, image.getBytes());
                    returnImages.add(updatedImage.getName());
                })
                .flatMapMaybe(returnImages -> Maybe.just(returnImages));
    }

这也是不正确的,返回类型应该是
可能是

从注释中,使用两个参数
collect
,然后使用
toMaybe
。您可能需要加强集合类型,如下所示:

Flowable.fromPublisher(图像)
.collect(ArrayList::new,(returnImages,image)->{
BlobId BlobId=BlobId.of(googleUploadObjectConfiguration.bucketName(),image.getName());
BlobInfo BlobInfo=BlobInfo.newBuilder(blobId.build();
Blob updateImage=storage.create(blobInfo,image.getBytes());
returnImages.add(updateImage.getName());
LOG.info(
String.format(“文件%s作为%s上载到存储桶%s”,image.getName(),
googleUploadObjectConfiguration.bucketName(),image.getName())
);
}).toMaybe();

您很可能使用了错误的
收集方法。编写
.collect(ArrayList::new,(returnImages,image)->{…})
.Mate谢谢你,你能展示完整的代码吗。返回类型可能应添加到问题的更新1中
Flowable.fromPublisher(images).collect(ArrayList::new, (returnImages, image) -> {
            BlobId blobId = BlobId.of(googleUploadObjectConfiguration.bucketName(), image.getName());
            BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
            Blob updatedImage = storage.create(blobInfo, image.getBytes());
            returnImages.add(updatedImage.getName());
            LOG.info(
                    String.format("File %s uploaded to bucket %s as %s", image.getName(),
                            googleUploadObjectConfiguration.bucketName(), image.getName())
            );
        }).flatMapMaybe((returnImages)-> List.of(returnImages));