I am totally new to RxJava and reactive programming. I have an assignment where i must read file and store it to Observable. I have tried to make a Callable with BufferedReader inside and use Observable.fromCallable(), but it didn't work much.
Could you please show me how can i do that?
I am using RxJava 2.0.
A basic solution where I use a nested class
FileObservableSource
to produce the data and then defer the creation of the Observable until an Observer subscribes:for Java 8, BufferedReader has a file stream and the iterator which you can use in tandem with RxJava. https://dzone.com/articles/java-8-stream-rx-java
you can get a Flowable using the following code
I use Flowable and Single to be more concise, it'll still work with Observable. the code snippet is an example of how I read each single line from the buffered reader.
You can do something similar to this implementation.
And then that class is used here in this way:
Eventually you can use it:
More details here.