- All Implemented Interfaces:
Closeable, AutoCloseable, ByteChannel, Channel, GatheringByteChannel, InterruptibleChannel, NetworkChannel, ReadableByteChannel, ScatteringByteChannel, WritableByteChannel
Simple wrapper for a SSLSocket. Cannot be used for asynch ops.
Field Summary
Constructor Summary
ConstructorsConstructorDescriptionSSLSocketChannel(SSLSocket socket) Create a new SSLSocketChannel wrapping the given SSL socket.Method Summary
All MethodsModifier and TypeMethodDescriptionbind(SocketAddress local) Bind is not supported by this wrapper.booleanconnect(SocketAddress remote) Connect is not supported by this wrapper.booleanFinish connecting.Get the local socket address of the underlying SSL socket.<T> TgetOption(SocketOption<T> name) Get the value of a socket option.Get the remote socket address of the underlying SSL socket.voidClose the underlying SSL socket.voidimplConfigureBlocking(boolean block) Configure the blocking mode.booleanCheck if the underlying SSL socket is connected.booleanCheck if a connection operation is pending.intread(ByteBuffer src) Read bytes from the underlying SSL socket into the given buffer.longread(ByteBuffer[] srcs, int offset, int length) Scatter read is not supported by this wrapper.<T> SocketChannelsetOption(SocketOption<T> name, T value) Set a socket option.Shut down the input stream of the underlying SSL socket.Shut down the output stream of the underlying SSL socket.socket()Return the underlying SSL socket.Set<SocketOption<?>> Get the set of supported socket options.intwrite(ByteBuffer src) Write bytes from the given buffer to the underlying SSL socket.longwrite(ByteBuffer[] srcs, int offset, int length) Gather write is not supported by this wrapper.Methods inherited from class AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, registerMethods inherited from class SelectableChannel
registerMethods inherited from class AbstractInterruptibleChannel
begin, close, end, isOpen
Field Details
_socket
The SSL socket wrapped as a channel.
Constructor Details
SSLSocketChannel
Create a new SSLSocketChannel wrapping the given SSL socket.- Parameters:
socket- the SSL socket to wrap
Method Details
socket
Return the underlying SSL socket.- Specified by:
socketin classSocketChannel- Returns:
- the wrapped SSLSocket
connect
Connect is not supported by this wrapper.- Specified by:
connectin classSocketChannel- Parameters:
remote- the remote address to connect to (ignored)- Returns:
- true (never reached)
- Throws:
UnsupportedOperationException- always; the wrapper is built around an already-connected socket and has no address to connect to
finishConnect
public boolean finishConnect()Finish connecting. This wrapper assumes the connection is already established.- Specified by:
finishConnectin classSocketChannel- Returns:
- true always
isConnected
public boolean isConnected()Check if the underlying SSL socket is connected.- Specified by:
isConnectedin classSocketChannel- Returns:
- true if connected
isConnectionPending
public boolean isConnectionPending()Check if a connection operation is pending. Always returns false.- Specified by:
isConnectionPendingin classSocketChannel- Returns:
- false always
getRemoteAddress
Get the remote socket address of the underlying SSL socket.- Specified by:
getRemoteAddressin classSocketChannel- Returns:
- the remote socket address, or null if not connected
shutdownInput
Shut down the input stream of the underlying SSL socket.- Specified by:
shutdownInputin classSocketChannel- Returns:
- this channel, for chaining
- Throws:
IOException- if an I/O error occurs
shutdownOutput
Shut down the output stream of the underlying SSL socket.- Specified by:
shutdownOutputin classSocketChannel- Returns:
- this channel, for chaining
- Throws:
IOException- if an I/O error occurs
setOption
Set a socket option. This is a no-op for this wrapper.- Specified by:
setOptionin interfaceNetworkChannel- Specified by:
setOptionin classSocketChannel- Type Parameters:
T- the type of the socket option value- Parameters:
name- the socket option name (ignored)value- the socket option value (ignored)- Returns:
- this channel, so the ignored option still chains
bind
Bind is not supported by this wrapper.- Specified by:
bindin interfaceNetworkChannel- Specified by:
bindin classSocketChannel- Parameters:
local- the socket address to bind to (ignored)- Returns:
- this channel (never returned)
- Throws:
UnsupportedOperationException- always; the wrapper carries an already-bound socket and cannot bind another local address
read
Read bytes from the underlying SSL socket into the given buffer. The buffer must have a backing array.- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin classSocketChannel- Parameters:
src- the buffer to read into- Returns:
- the number of bytes read, or -1 if end of stream
- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if the buffer has no backing array
read
Scatter read is not supported by this wrapper.- Specified by:
readin interfaceScatteringByteChannel- Specified by:
readin classSocketChannel- Parameters:
srcs- the buffers to read into (ignored)offset- the offset in the buffer array (ignored)length- the number of buffers to use (ignored)- Returns:
- the number of bytes read (never reached)
- Throws:
UnsupportedOperationException- always; reads are performed one buffer at a time, since a scatter read cannot be expressed on a stream
write
Write bytes from the given buffer to the underlying SSL socket. The buffer must have a backing array.- Specified by:
writein interfaceWritableByteChannel- Specified by:
writein classSocketChannel- Parameters:
src- the buffer to write from- Returns:
- the number of bytes written
- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if the buffer has no backing array
write
Gather write is not supported by this wrapper.- Specified by:
writein interfaceGatheringByteChannel- Specified by:
writein classSocketChannel- Parameters:
srcs- the buffers to write from (ignored)offset- the offset in the buffer array (ignored)length- the number of buffers to use (ignored)- Returns:
- the number of bytes written (never reached)
- Throws:
UnsupportedOperationException- always; writes are performed one buffer at a time, since a gather write cannot be expressed on a stream
implCloseSelectableChannel
Close the underlying SSL socket.- Specified by:
implCloseSelectableChannelin classAbstractSelectableChannel- Throws:
IOException- if an I/O error occurs while closing
implConfigureBlocking
Configure the blocking mode. Only blocking mode is supported.- Specified by:
implConfigureBlockingin classAbstractSelectableChannel- Parameters:
block- true for blocking mode (accepted), false throws- Throws:
IOException- if an I/O error occursUnsupportedOperationException- if block is false
getLocalAddress
Get the local socket address of the underlying SSL socket.- Specified by:
getLocalAddressin interfaceNetworkChannel- Specified by:
getLocalAddressin classSocketChannel- Returns:
- the local socket address, or null if not bound
getOption
Get the value of a socket option. Not supported, always returns null.- Type Parameters:
T- the type of the socket option value- Parameters:
name- the socket option name (ignored)- Returns:
- null always
supportedOptions
Get the set of supported socket options. Returns an empty set.- Returns:
- an empty set of supported socket options