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 TypeMethodDescriptionvoid
close()
Closes thisWritableSocket
.void
flush()
Flushes any remaining data in thisWritableSocket
's write buffer.Returns a readable string identifier of the remote peer.boolean
Returnstrue
if thisWritableSocket
is connected, meaning data can still be written.boolean
Returnstrue
if thisWritableSocket
is writable.default void
write
(byte[] data) Writes the given data to thisWritableSocket
.void
write
(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()Returnstrue
if thisWritableSocket
is 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:
true
if thisWritableSocket
is connected- See Also:
-
isWritable
boolean isWritable()Returnstrue
if thisWritableSocket
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 thisWritableSocket
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 thisWritableSocket
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-