Byte sink is similar to OutputStream, but is defined as an interface for allowing stream operations over RMI. RMI solutions can create proxy objects for network transferred objects only for interfaces, therefore it was necessary to declare such an interface that is usable for this use-case.
This interface works in similar ways as the OutputStream class, but is designed to be RMI compatible. The
interface also contains extra method(s) for more efficient implementations of common use-cases (like
readFrom(
To convert between OutputStream and ByteSink objects use the static methods declared in this interface.
Byte sink implementations are not thread-safe by default.
public default void | close() Closes this stream and releases any system resources associated
with it. |
public default void | flush() Flushes this stream by writing any buffered output to the underlying
stream. |
public default long | readFrom( Reads bytes from the argument byte source and writes it to this byte sink. |
public static OutputStream | toOutputStream( Converts the argument ByteSink to an OutputStream. |
public static ByteSink | valueOf( Converts the argument ObjectOutput to a ByteSink. |
public static ByteSink | valueOf( Converts the argument OutputStream to a ByteSink. |
public default void | write( Writes a single byte to the byte sink. |
public void | write( Writes the bytes contained in the argument byte array to the byte sink. |
As noted in AutoCloseable.close(), cases where the
close may fail require careful attention. It is strongly advised
to relinquish the underlying resources and to internally
mark the Closeable
as closed, prior to throwing
the IOException
.
this
byte sink. This method will possibly read all bytes from the argument byte source and all the read bytes will be written to this byte sink. If the argument is a blocking source, then this method will block too.
Calling this method instead of copying the bytes externally can have advantages, as implementations can read the bytes into an internal buffer more efficiently, therefore avoiding unnecessary copying and allocations.
The default implementation calls ByteSource.writeTo(
null
.If the argument is already an OutputStream, then it will be returned without modification.
Else it will be wrapped into a forwarding OutputStream.
Closing the result will close the argument too.
null
if the argument is
null
.If the argument is already a byte sink, then it will be returned without modification.
Else it will be wrapped into a forwarding ByteSink.
Closing the result will close the argument.
null
if the argument is
null
.If the argument is already a byte sink, then it will be returned without modification.
Else it will be wrapped into a forwarding ByteSink.
Closing the result will close the argument too.
null
if the argument is
null
.
This method works similarly to OutputStream.write(
This method works similarly to OutputStream.write(
null
.