Interface WritableSocket

All Superinterfaces:
AutoCloseable, Closeable, Flushable
All Known Implementing Classes:
SocketConnectionWritable

public interface WritableSocket extends Closeable, Flushable
Provides an abstraction layer for outgoing data over a socket.

None of the methods in this interface can throw an IOException. If the underlying socket implementation encounters an IO error, it should either try to handle the error, or propagate the error using a UncheckedIOException. In this case, the error will usually be propagated further to the caller during (in-)direct write calls, or cause close() to be called during internal write calls (this applies to any thrown exceptions).

Since:
1.2.1
  • Method Details

    • write

      default void write(byte[] data)
      Writes the given data to this WritableSocket.
      Parameters:
      data - The data
      See Also:
    • write

      void write(byte[] data, int offset, int length)
      Writes the given data to this WritableSocket.
      Parameters:
      data - The data
      offset - The index to start writing from
      length - The number of bytes to write, starting at offset
      See Also:
    • flush

      void flush()
      Flushes any remaining data in this WritableSocket's write buffer.
      Specified by:
      flush in interface Flushable
    • isConnected

      boolean isConnected()
      Returns true if this WritableSocket is connected, meaning data can still be written. This is distinct from isWritable() because a socket may still be connected, while not being writable, because data is backed up locally.
      Returns:
      true if this WritableSocket is connected
      See Also:
    • isWritable

      boolean isWritable()
      Returns true if this WritableSocket is writable. A socket is writable if data can be written without requiring this data to be buffered locally, potentially causing excessive memory consumption.
      Returns:
      true if this WritableSocket is writable
      See Also:
    • getRemoteName

      String getRemoteName()
      Returns a readable string identifier of the remote peer.
      Returns:
      A readable remote string identifier
    • close

      void close()
      Closes this WritableSocket.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable