0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply. I'd go with the first solution, however in that context "buffer" is undefined. By using .flatMap(buffer -> Observable.fromArray(buffer.toString().split("\n"))) does not compile either because it does not conform to a SingleSource
I've tried with the second solution too, but I don't have any .collect method available from vertx.fileSystem().rxReadFile
apologies, I thought vertx.fileSystem().rxReadFile was returning an Observable, but it returns a Single. I updated my answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.