javareactive-programmingmutinyquarkus-reactive

Howto use Mutiny to parse lines of a file


I learn Reactive/Mutiny. I try to use Mutiny to read lines of a file. In imperative way of doing it, it's easy :

public List<String> load(final InputStream inData) throws IOException {
    final List<String> content = new ArrayList<>();
    final BufferedReader bReader = new BufferedReader(new InputStreamReader(inData, ENCODING));
    String text;
    while ((text = bReader.readLine()) != null) {
        content.add(text);
    }
    return content;
}

I can't find any example of a reactive way of doing it .. something that would look like :

final BufferedReader bReader = new BufferedReader(new InputStreamReader(inData, ENCODING));
Multi<String> multi = Multi.createFrom(bReader::readline);

Am I totally out of the way ?


Solution

  • (coying my comment as response)

    I would recommend using the Vert.x File system (there is the Mutiny API), which will adequately read the file asynchronously. Here, you are blocking, which defeats the purpose of using mutiny. See smallrye.io/smallrye-mutiny-vertx-bindings/2.8.0/apidocs/io/… and quarkus.io/blog/mutiny-vertx.