Jul 23, 2017 · 1 min read
Vladimir Chernis A buffer is a temporary reusable space managed by a program for the purpose of making the data stream efficient. We can understand buffering process by an excellent analogy I found at StackOverflow.
Imagine that you’re eating candy out of a bowl. You take one piece regularly. To prevent the bowl from running out, someone might refill the bowl before it gets empty, so that when you want to take another piece, there’s candy in the bowl.
The bowl acts as a buffer between you and the candy bag.
Let’s puts a test on an Observable
List<Integer> data = Arrays.asList(1, 2, 3, 4);
Observable stream = Observable.fromIterable(data);
stream.subscribe(
val -> System.out.print(val + " "),
err -> System.out.println("\nerror " + err),
() -> {
System.out.println("\ncompleted");
data.set(0, 5);
data.set(1, 6);
data.set(2, 7);
data.set(3, 8);
stream.subscribe(
val -> System.out.print(val + " "),
err -> {
System.out.println("\nerror ");
},
() -> System.out.println("\ncompleted"));
});Output:
1 2 3 4
completed
5 6 7 8
completed
If we modify the items of the data the publisher sends the new items meaning that it is not storing the information in a buffer.
