Different libs don’t know each other but they need to consume data from each other or product data for others. Many libs have both read and write operations. Data can be exchanged in non-stream or stream way:
Array[Byte]in memory. Not good for big data. Also it creates many short-lived objects that need to be garbarge collected.
java.io.OutputStream. It has limited data sources and it is not easy to to convert the your data to one of its source format.
Usually different libs define different intefaces that use differnt low-level APIs such as
java.nio.channel.Chaneel and data types such as
One solution is to starndardize the IO inerfaces.
The interface is defined as:
Readable doesn’t provide an
InputStream directly. It uses a callback to allow data source to perform any necessary cleanup actions after the reading is complete.
For streaming data, the concepts of push and pull are important. It is flexible to use push-based
Writable for data destinations and pull-based
Readable for data sources. Any pull-based
Readable can be trivially used as a push-based
Writable, and any method receiving a push-based
Writable can also receive a pull-based
Readable. This is reflected in type inheritence hierarchy
trait Readable extends Writable.
When you use
Writable, you want “push” data. When you use
Readable, you want “pull” data.