2

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 ?

Lbro
  • 309
  • 2
  • 16
  • Rather than reinvent the wheel, you could delete your entire method and use this instead `List lines = Files.readAllLines(filePath, charset);` – Bohemian Jul 07 '23 at 21:48
  • You're right imperative way is easy. I see a lot of examples to access database in reactive way and i wonder how to do it but to access file .... – Lbro Jul 07 '23 at 22:16
  • 1
    I would recommend using the Vert.x File system (there is the Mutiny API) which will adequately read the file in an asynchronous fashion. Here, you are blocking which defeats the purpose of using mutiny. See https://smallrye.io/smallrye-mutiny-vertx-bindings/2.8.0/apidocs/io/vertx/mutiny/core/file/FileSystem.html and https://quarkus.io/blog/mutiny-vertx/. – Clement Jul 12 '23 at 06:41

0 Answers0