0
votes

I'm reading a property file using Vert.x File System API and would need to do some transformations on it. The problem is that the File is not being read line by line but as a single chunk. So, assuming I have this property file:

name=abc
name=def

And using this code:

vertx.fileSystem().rxReadFile("/path/file.properties")
        .map(buffer -> buffer.toString())
        .subscribe(data -> {
            System.out.println(">"+data);
        }, err -> System.out.println("Cannot read the file: " + err.getMessage()));

What I get printed is a single chunk of data:

>name=abc
name=def

I'd expect the following, as I have to perform transformations on each line:

>name=abc
>name=def
1

1 Answers

1
votes

You can just replace this line:

.map(buffer -> buffer.toString())

By:

.flatMapObservable(buffer -> Observable.fromArray(buffer.toString().split("\n")))

The code above will split the buffer by line breaks and emit line by line to the stream.