Top Inners Fields Constructors Methods
jnr.unixsocket

public Class UnixSocket

extends Socket
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, java.net.InetAddress, .SocketAddress, .SocketException, java.nio.ByteBuffer, java.nio.channels.Channels, .ReadableByteChannel, .SelectableChannel, .SocketChannel, .WritableByteChannel, java.util.concurrent.atomic.AtomicBoolean

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
UnixSocket.UnselectableByteChannel

A byte channel that doesn't implement SelectableChannel.

Field Summary

Modifier and TypeField and Description
private UnixSocketChannel
private AtomicBoolean
private InputStream
private AtomicBoolean
private OutputStream
private AtomicBoolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
bind(SocketAddress
the SocketAddress to bind to
local
)

Overrides java.net.Socket.bind.

Binds the socket to a local address.
public void
close()

Overrides java.net.Socket.close.

Implements java.io.Closeable.close.

Closes this socket.
public void
connect(SocketAddress
the SocketAddress
addr
)

Overrides java.net.Socket.connect.

Connects this socket to the server.
public void
connect(SocketAddress
the SocketAddress
addr
,
int
the timeout value to be used in milliseconds.
timeout
)

Overrides java.net.Socket.connect.

Connects this socket to the server with a specified timeout value.
public SocketChannel
getChannel()

Overrides java.net.Socket.getChannel.

Returns the unique SocketChannel object associated with this socket, if any.
public final Credentials

Returns:

the credentials of the remote; null if not connected
getCredentials
()

Retrieves the credentials for this UNIX socket.

public InetAddress
getInetAddress()

Overrides java.net.Socket.getInetAddress.

Returns the address to which the socket is connected.
public InputStream
getInputStream()

Overrides java.net.Socket.getInputStream.

Returns an input stream for this socket.
public boolean
getKeepAlive()

Overrides java.net.Socket.getKeepAlive.

Tests if SO_KEEPALIVE is enabled.
public SocketAddress
getLocalSocketAddress()

Overrides java.net.Socket.getLocalSocketAddress.

Returns the address of the endpoint this socket is bound to.
public OutputStream
getOutputStream()

Overrides java.net.Socket.getOutputStream.

Returns an output stream for this socket.
public int
getReceiveBufferSize()

Overrides java.net.Socket.getReceiveBufferSize.

Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.
public SocketAddress
getRemoteSocketAddress()

Overrides java.net.Socket.getRemoteSocketAddress.

Returns the address of the endpoint this socket is connected to, or null if it is unconnected.
public int
getSendBufferSize()

Overrides java.net.Socket.getSendBufferSize.

Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.
public int
getSoTimeout()

Overrides java.net.Socket.getSoTimeout.

Returns setting for SO_TIMEOUT.
private void
public boolean
isBound()

Overrides java.net.Socket.isBound.

Returns the binding state of the socket.
public boolean
isClosed()

Overrides java.net.Socket.isClosed.

Returns the closed state of the socket.
public boolean
isConnected()

Overrides java.net.Socket.isConnected.

Returns the connection state of the socket.
public boolean
isInputShutdown()

Overrides java.net.Socket.isInputShutdown.

Returns whether the read-half of the socket connection is closed.
public boolean
isOutputShutdown()

Overrides java.net.Socket.isOutputShutdown.

Returns whether the write-half of the socket connection is closed.
public void
setKeepAlive(boolean
whether or not to have socket keep alive turned on.
on
)

Overrides java.net.Socket.setKeepAlive.

Enable/disable SO_KEEPALIVE.
public void
setReceiveBufferSize(int
the size to which to set the receive buffer size. This value must be greater than 0.
size
)

Overrides java.net.Socket.setReceiveBufferSize.

Sets the SO_RCVBUF option to the specified value for this Socket.
public void
setSendBufferSize(int
the size to which to set the send buffer size. This value must be greater than 0.
size
)

Overrides java.net.Socket.setSendBufferSize.

Sets the SO_SNDBUF option to the specified value for this Socket.
public void
setSoTimeout(int
the specified timeout, in milliseconds.
timeout
)

Overrides java.net.Socket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
public void
shutdownInput()

Overrides java.net.Socket.shutdownInput.

Places the input stream for this socket at "end of stream".
public void
shutdownOutput()

Overrides java.net.Socket.shutdownOutput.

Disables the output stream for this socket.
Inherited from java.net.Socket:
getLocalAddressgetLocalPortgetOOBInlinegetOptiongetPortgetReuseAddressgetSoLingergetTcpNoDelaygetTrafficClasssendUrgentDatasetOOBInlinesetOptionsetPerformancePreferencessetReuseAddresssetSocketImplFactorysetSoLingersetTcpNoDelaysetTrafficClasssupportedOptionstoString

Field Detail

chanback to summary
private UnixSocketChannel chan
closedback to summary
private AtomicBoolean closed
inback to summary
private InputStream in

Hides java.net.Socket.in.

indownback to summary
private AtomicBoolean indown
outback to summary
private OutputStream out

Hides java.net.Socket.out.

outdownback to summary
private AtomicBoolean outdown

Constructor Detail

UnixSocketback to summary
public UnixSocket(UnixSocketChannel chan)

Method Detail

bindback to summary
public void bind(SocketAddress local) throws IOException

Overrides java.net.Socket.bind.

Doc from java.net.Socket.bind.

Binds the socket to a local address.

If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.

Parameters
local:SocketAddress

the SocketAddress to bind to

Annotations
@Override
Exceptions
IOException:
if the bind operation fails, or if the socket is already bound.
closeback to summary
public void close() throws IOException

Overrides java.net.Socket.close.

Implements java.io.Closeable.close.

Doc from java.net.Socket.close.

Closes this socket.

Any thread currently blocked in an I/O operation upon this socket will throw a SocketException.

Once a socket has been closed, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created.

Closing this socket will also close the socket's InputStream and OutputStream.

If this socket has an associated channel then the channel is closed as well.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when closing this socket.
connectback to summary
public void connect(SocketAddress addr) throws IOException

Overrides java.net.Socket.connect.

Doc from java.net.Socket.connect.

Connects this socket to the server.

This method is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread establishing a connection will close the underlying channel and cause this method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is establishing a connection. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. This method will then throw SocketException with the interrupt status set.
Parameters
addr:SocketAddress

the SocketAddress

Annotations
@Override
Exceptions
IOException:
if an error occurs during the connection
connectback to summary
public void connect(SocketAddress addr, int timeout) throws IOException

Overrides java.net.Socket.connect.

Doc from java.net.Socket.connect.

Connects this socket to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.

This method is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread establishing a connection will close the underlying channel and cause this method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is establishing a connection. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. This method will then throw SocketException with the interrupt status set.
Parameters
addr:SocketAddress

the SocketAddress

timeout:int

the timeout value to be used in milliseconds.

Annotations
@Override
Exceptions
IOException:
if an error occurs during the connection
getChannelback to summary
public SocketChannel getChannel()

Overrides java.net.Socket.getChannel.

Doc from java.net.Socket.getChannel.

Returns the unique SocketChannel object associated with this socket, if any.

A socket will have a channel if, and only if, the channel itself was created via the SocketChannel.open or ServerSocketChannel.accept methods.

Returns:SocketChannel

the socket channel associated with this socket, or null if this socket was not created for a channel

Annotations
@Override
getCredentialsback to summary
public final Credentials getCredentials() throws SocketException

Retrieves the credentials for this UNIX socket. Clients calling this method will receive the server's credentials, and servers will receive the client's credentials. User ID, group ID, and PID are supplied. See man unix 7; SCM_CREDENTIALS

Returns:Credentials

the credentials of the remote; null if not connected

Exceptions
SocketException:
if fetching the socket option failed.
UnsupportedOperationException:
if the underlying socket library doesn't support the SO_PEERCRED option
getInetAddressback to summary
public InetAddress getInetAddress()

Overrides java.net.Socket.getInetAddress.

Doc from java.net.Socket.getInetAddress.

Returns the address to which the socket is connected.

If the socket was connected prior to being closed, then this method will continue to return the connected address after the socket is closed.

Returns:InetAddress

the remote IP address to which this socket is connected, or null if the socket is not connected.

Annotations
@Override
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Overrides java.net.Socket.getInputStream.

Doc from java.net.Socket.getInputStream.

Returns an input stream for this socket.

If this socket has an associated channel then the resulting input stream delegates all of its operations to the channel. If the channel is in non-blocking mode then the input stream's read operations will throw an java.nio.channels.IllegalBlockingModeException.

Reading from the input stream is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread reading from the input stream will close the underlying channel and cause the read method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is reading from the input stream. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. The read method will then throw SocketException with the interrupt status set.

Under abnormal conditions the underlying connection may be broken by the remote host or the network software (for example a connection reset in the case of TCP connections). When a broken connection is detected by the network software the following applies to the returned input stream :-

  • The network software may discard bytes that are buffered by the socket. Bytes that aren't discarded by the network software can be read using read.

  • If there are no bytes buffered on the socket, or all buffered bytes have been consumed by read, then all subsequent calls to read will throw an IOException.

  • If there are no bytes buffered on the socket, and the socket has not been closed using close, then available will return 0.

Closing the returned InputStream will close the associated socket.

Returns:InputStream

an input stream for reading bytes from this socket.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when creating the input stream, the socket is closed, the socket is not connected, or the socket input has been shutdown using shutdownInput()
getKeepAliveback to summary
public boolean getKeepAlive() throws SocketException

Overrides java.net.Socket.getKeepAlive.

Doc from java.net.Socket.getKeepAlive.

Tests if SO_KEEPALIVE is enabled.

Returns:boolean

a boolean indicating whether or not SO_KEEPALIVE is enabled.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
getLocalSocketAddressback to summary
public SocketAddress getLocalSocketAddress()

Overrides java.net.Socket.getLocalSocketAddress.

Doc from java.net.Socket.getLocalSocketAddress.

Returns the address of the endpoint this socket is bound to.

If a socket bound to an endpoint represented by an InetSocketAddress is closed, then this method will continue to return an InetSocketAddress after the socket is closed. In that case the returned InetSocketAddress's address is the wildcard address and its port is the local port that it was bound to.

If there is a security manager set, its checkConnect method is called with the local address and -1 as its arguments to see if the operation is allowed. If the operation is not allowed, a SocketAddress representing the loopback address and the local port to which this socket is bound is returned.

Returns:SocketAddress

a SocketAddress representing the local endpoint of this socket, or a SocketAddress representing the loopback address if denied by the security manager, or null if the socket is not bound yet.

Annotations
@Override
getOutputStreamback to summary
public OutputStream getOutputStream() throws IOException

Overrides java.net.Socket.getOutputStream.

Doc from java.net.Socket.getOutputStream.

Returns an output stream for this socket.

If this socket has an associated channel then the resulting output stream delegates all of its operations to the channel. If the channel is in non-blocking mode then the output stream's write operations will throw an java.nio.channels.IllegalBlockingModeException.

Writing to the output stream is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread writing to the output stream will close the underlying channel and cause the write method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is writing to the output stream. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. The write method will then throw SocketException with the interrupt status set.

Closing the returned OutputStream will close the associated socket.

Returns:OutputStream

an output stream for writing bytes to this socket.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when creating the output stream or if the socket is not connected.
getReceiveBufferSizeback to summary
public int getReceiveBufferSize() throws SocketException

Overrides java.net.Socket.getReceiveBufferSize.

Doc from java.net.Socket.getReceiveBufferSize.

Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.

Returns:int

the value of the SO_RCVBUF option for this Socket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
getRemoteSocketAddressback to summary
public SocketAddress getRemoteSocketAddress()

Overrides java.net.Socket.getRemoteSocketAddress.

Doc from java.net.Socket.getRemoteSocketAddress.

Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

If the socket was connected prior to being closed, then this method will continue to return the connected address after the socket is closed.

Returns:SocketAddress

a SocketAddress representing the remote endpoint of this socket, or null if it is not connected yet.

Annotations
@Override
getSendBufferSizeback to summary
public int getSendBufferSize() throws SocketException

Overrides java.net.Socket.getSendBufferSize.

Doc from java.net.Socket.getSendBufferSize.

Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.

Returns:int

the value of the SO_SNDBUF option for this Socket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
getSoTimeoutback to summary
public int getSoTimeout() throws SocketException

Overrides java.net.Socket.getSoTimeout.

Doc from java.net.Socket.getSoTimeout.

Returns setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).

Returns:int

the setting for SO_TIMEOUT

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
ignoreback to summary
private void ignore()
isBoundback to summary
public boolean isBound()

Overrides java.net.Socket.isBound.

Doc from java.net.Socket.isBound.

Returns the binding state of the socket.

Note

Closing a socket doesn't clear its binding state, which means this method will return true for a closed socket (see isClosed()) if it was successfully bound prior to being closed.

Returns:boolean

true if the socket was successfully bound to an address

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Overrides java.net.Socket.isClosed.

Doc from java.net.Socket.isClosed.

Returns the closed state of the socket.

Returns:boolean

true if the socket has been closed

Annotations
@Override
isConnectedback to summary
public boolean isConnected()

Overrides java.net.Socket.isConnected.

Doc from java.net.Socket.isConnected.

Returns the connection state of the socket.

Note

Closing a socket doesn't clear its connection state, which means this method will return true for a closed socket (see isClosed()) if it was successfully connected prior to being closed.

Returns:boolean

true if the socket was successfully connected to a server

Annotations
@Override
isInputShutdownback to summary
public boolean isInputShutdown()

Overrides java.net.Socket.isInputShutdown.

Doc from java.net.Socket.isInputShutdown.

Returns whether the read-half of the socket connection is closed.

Returns:boolean

true if the input of the socket has been shutdown

Annotations
@Override
isOutputShutdownback to summary
public boolean isOutputShutdown()

Overrides java.net.Socket.isOutputShutdown.

Doc from java.net.Socket.isOutputShutdown.

Returns whether the write-half of the socket connection is closed.

Returns:boolean

true if the output of the socket has been shutdown

Annotations
@Override
setKeepAliveback to summary
public void setKeepAlive(boolean on) throws SocketException

Overrides java.net.Socket.setKeepAlive.

Doc from java.net.Socket.setKeepAlive.

Enable/disable SO_KEEPALIVE.

Parameters
on:boolean

whether or not to have socket keep alive turned on.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
setReceiveBufferSizeback to summary
public void setReceiveBufferSize(int size) throws SocketException

Overrides java.net.Socket.setReceiveBufferSize.

Doc from java.net.Socket.setReceiveBufferSize.

Sets the SO_RCVBUF option to the specified value for this Socket. The SO_RCVBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers.

Increasing the receive buffer size can increase the performance of network I/O for high-volume connection, while decreasing it can help reduce the backlog of incoming data.

Because SO_RCVBUF is a hint, applications that want to verify what size the buffers were set to should call getReceiveBufferSize().

The value of SO_RCVBUF is also used to set the TCP receive window that is advertised to the remote peer. Generally, the window size can be modified at any time when a socket is connected. However, if a receive window larger than 64K is required then this must be requested before the socket is connected to the remote peer. There are two cases to be aware of:

  1. For sockets accepted from a ServerSocket, this must be done by calling ServerSocket#setReceiveBufferSize(int) before the ServerSocket is bound to a local address.
  2. For client sockets, setReceiveBufferSize() must be called before connecting the socket to its remote peer.
Parameters
size:int

the size to which to set the receive buffer size. This value must be greater than 0.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
setSendBufferSizeback to summary
public void setSendBufferSize(int size) throws SocketException

Overrides java.net.Socket.setSendBufferSize.

Doc from java.net.Socket.setSendBufferSize.

Sets the SO_SNDBUF option to the specified value for this Socket. The SO_SNDBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers.

Because SO_SNDBUF is a hint, applications that want to verify what size the buffers were set to should call getSendBufferSize().

Parameters
size:int

the size to which to set the send buffer size. This value must be greater than 0.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
setSoTimeoutback to summary
public void setSoTimeout(int timeout) throws SocketException

Overrides java.net.Socket.setSoTimeout.

Doc from java.net.Socket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a positive timeout value, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. A timeout of zero is interpreted as an infinite timeout. The option must be enabled prior to entering the blocking operation to have effect.

Parameters
timeout:int

the specified timeout, in milliseconds.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error
shutdownInputback to summary
public void shutdownInput() throws IOException

Overrides java.net.Socket.shutdownInput.

Doc from java.net.Socket.shutdownInput.

Places the input stream for this socket at "end of stream". Any data sent to the input stream side of the socket is acknowledged and then silently discarded.

If you read from a socket input stream after invoking this method on the socket, the stream's available method will return 0, and its read methods will return -1 (end of stream).

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when shutting down this socket.
shutdownOutputback to summary
public void shutdownOutput() throws IOException

Overrides java.net.Socket.shutdownOutput.

Doc from java.net.Socket.shutdownOutput.

Disables the output stream for this socket. For a TCP socket, any previously written data will be sent followed by TCP's normal connection termination sequence. If you write to a socket output stream after invoking shutdownOutput() on the socket, the stream will throw an IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when shutting down this socket.
jnr.unixsocket back to summary

pack-priv final Class UnixSocket.UnselectableByteChannel

extends Object
implements ReadableByteChannel, WritableByteChannel
Class Inheritance
All Implemented Interfaces
java.nio.channels.WritableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ReadableByteChannel

A byte channel that doesn't implement SelectableChannel. Though that type isn't in the public API, if the channel passed in implements that interface then unwanted synchronization is performed which can harm concurrency and can cause deadlocks. https://bugs.openjdk.java.net/browse/JDK-4774871

Field Summary

Modifier and TypeField and Description
private final UnixSocketChannel

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.nio.channels.Channel.close.

Closes this channel.
public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.
public int
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
)

Implements java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.
public int
write(ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

channelback to summary
private final UnixSocketChannel channel

Constructor Detail

UnselectableByteChannelback to summary
pack-priv UnselectableByteChannel(UnixSocketChannel channel)

Method Detail

closeback to summary
public void close() throws IOException

Implements java.nio.channels.Channel.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

Annotations
@Override
readback to summary
public int read(ByteBuffer dst) throws IOException

Implements java.nio.channels.ReadableByteChannel.read.

Doc from java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

An attempt is made to read up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is read, where 0 <= n <= r. This byte sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p + n - 1, where p is the buffer's position at the moment this method is invoked. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

A read operation might not fill the buffer, and in fact it might not read any bytes at all. Whether or not it does so depends upon the nature and state of the channel. A socket channel in non-blocking mode, for example, cannot read any more bytes than are immediately available from the socket's input buffer; similarly, a file channel cannot read any more bytes than remain in the file. It is guaranteed, however, that if a channel is in blocking mode and there is at least one byte remaining in the buffer then this method will block until at least one byte is read.

This method may be invoked at any time. If another thread has already initiated a read operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
dst:ByteBuffer

The buffer into which bytes are to be transferred

Returns:int

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public int write(ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Doc from java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

An attempt is made to write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment this method is invoked; the index of the last byte written will be p + n - 1. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
src:ByteBuffer

The buffer from which bytes are to be retrieved

Returns:int

The number of bytes written, possibly zero

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs