Remove use of MonoProcessor.fromSinks

See gh-25884
This commit is contained in:
Rossen Stoyanchev
2020-10-09 20:45:27 +01:00
parent cdd48ddd7f
commit e73e489fd8
30 changed files with 300 additions and 227 deletions

View File

@@ -18,12 +18,12 @@ package org.springframework.core.codec;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.MonoProcessor;
import reactor.core.publisher.Sinks;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
@@ -93,16 +93,21 @@ public interface Decoder<T> {
default T decode(DataBuffer buffer, ResolvableType targetType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException {
MonoProcessor<T> processor = MonoProcessor.fromSink(Sinks.one());
decodeToMono(Mono.just(buffer), targetType, mimeType, hints).subscribeWith(processor);
CompletableFuture<T> future = decodeToMono(Mono.just(buffer), targetType, mimeType, hints).toFuture();
Assert.state(future.isDone(), "DataBuffer decoding should have completed.");
Assert.state(processor.isTerminated(), "DataBuffer decoding should have completed.");
Throwable ex = processor.getError();
if (ex != null) {
throw (ex instanceof CodecException ? (CodecException) ex :
new DecodingException("Failed to decode: " + ex.getMessage(), ex));
Throwable failure;
try {
return future.get();
}
return processor.peek();
catch (ExecutionException ex) {
failure = ex.getCause();
}
catch (InterruptedException ex) {
failure = ex;
}
throw (failure instanceof CodecException ? (CodecException) failure :
new DecodingException("Failed to decode: " + failure.getMessage(), failure));
}
/**