A Writable is a source of bytes that can be written to an OutputStream.
Essentially a push-based version of java.io.InputStream, that allows an
implementation to guarantee that cleanup logic runs after the bytes are
written.
Writable is also much easier to implement than java.io.InputStream: any
code that previously wrote output to an ByteArrayOutputStream or
StringBuilder can trivially satisfy the Writable interface. That makes
Writable very convenient to use for allowing zero-friction zero-overhead
streaming data exchange between different libraries.
Writable comes with implicit constructors from Array[Byte], String
and InputStream, and is itself a tiny interface with minimal functionality.
Libraries using Writable are expected to extend it to provide additional
methods or additional implicit constructors that make sense in their context.
A Writable is a source of bytes that can be written to an OutputStream.
Essentially a push-based version of
java.io.InputStream
, that allows an implementation to guarantee that cleanup logic runs after the bytes are written.Writable is also much easier to implement than
java.io.InputStream
: any code that previously wrote output to anByteArrayOutputStream
orStringBuilder
can trivially satisfy the Writable interface. That makes Writable very convenient to use for allowing zero-friction zero-overhead streaming data exchange between different libraries.Writable comes with implicit constructors from
Array[Byte]
,String
andInputStream
, and is itself a tiny interface with minimal functionality. Libraries using Writable are expected to extend it to provide additional methods or additional implicit constructors that make sense in their context.