0

I'm new to Reactive programming. I'm attempting to use Mono.using to read a resource file as a string within a project that uses Spring. Here is my function:

public static Mono<String> LoadFileFromClasspath(String classPath) {
    return Mono.using(
            () -> new ClassPathResource(classPath).getInputStream(),
            (inputStream) -> StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8),
            (inputStream) -> inputStream.close()
    ).onErrorMap(original -> new RuntimeException("Cannot load from " + classPath));
}

I have onErrorMap at the end. but there's still an Unhandled java.io.IOException. Do I still need to wrap them in try catch? What is the correct way to handle an IO Exception using project reactor?

Also does this code mean the IO operation is non-blocking? Or do I need to control the tread myself?

Mox
  • 1
  • 1

0 Answers0