Package org.omegazero.http.util
Interface WritableSocket
- All Superinterfaces:
AutoCloseable,Closeable,Flushable
- All Known Implementing Classes:
SocketConnectionWritable
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 Summary
Modifier and TypeMethodDescriptionvoidclose()Closes thisWritableSocket.voidflush()Flushes any remaining data in thisWritableSocket's write buffer.Returns a readable string identifier of the remote peer.booleanReturnstrueif thisWritableSocketis connected, meaning data can still be written.booleanReturnstrueif thisWritableSocketis writable.default voidwrite(byte[] data) Writes the given data to thisWritableSocket.voidwrite(byte[] data, int offset, int length) Writes the given data to thisWritableSocket.
-
Method Details
-
write
default void write(byte[] data) Writes the given data to thisWritableSocket.- Parameters:
data- The data- See Also:
-
write
void write(byte[] data, int offset, int length) Writes the given data to thisWritableSocket.- Parameters:
data- The dataoffset- The index to start writing fromlength- The number of bytes to write, starting at offset- See Also:
-
flush
void flush()Flushes any remaining data in thisWritableSocket's write buffer. -
isConnected
boolean isConnected()Returnstrueif thisWritableSocketis connected, meaning data can still be written. This is distinct fromisWritable()because a socket may still be connected, while not being writable, because data is backed up locally.- Returns:
trueif thisWritableSocketis connected- See Also:
-
isWritable
boolean isWritable()Returnstrueif thisWritableSocketis writable. A socket is writable if data can be written without requiring this data to be buffered locally, potentially causing excessive memory consumption.- Returns:
trueif thisWritableSocketis 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 thisWritableSocket.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-