All Implemented Interfaces:
Closeable, AutoCloseable, ByteChannel, Channel, GatheringByteChannel, InterruptibleChannel, NetworkChannel, ReadableByteChannel, ScatteringByteChannel, WritableByteChannel

class SSLSocketChannelextends SocketChannel
Simple wrapper for a SSLSocket. Cannot be used for asynch ops.
  • Field Details

    • _socket

      private final SSLSocket _socket
      The SSL socket wrapped as a channel.
  • Constructor Details

    • SSLSocketChannel

      public SSLSocketChannel(SSLSocket socket)
      Create a new SSLSocketChannel wrapping the given SSL socket.
      Parameters:
      socket - the SSL socket to wrap
  • Method Details

    • socket

      public Socket socket()
      Return the underlying SSL socket.
      Specified by:
      socket in class SocketChannel
      Returns:
      the wrapped SSLSocket
    • connect

      public boolean connect(SocketAddress remote)
      Connect is not supported by this wrapper.
      Specified by:
      connect in class SocketChannel
      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:
      finishConnect in class SocketChannel
      Returns:
      true always
    • isConnected

      public boolean isConnected()
      Check if the underlying SSL socket is connected.
      Specified by:
      isConnected in class SocketChannel
      Returns:
      true if connected
    • isConnectionPending

      public boolean isConnectionPending()
      Check if a connection operation is pending. Always returns false.
      Specified by:
      isConnectionPending in class SocketChannel
      Returns:
      false always
    • getRemoteAddress

      public SocketAddress getRemoteAddress()
      Get the remote socket address of the underlying SSL socket.
      Specified by:
      getRemoteAddress in class SocketChannel
      Returns:
      the remote socket address, or null if not connected
    • shutdownInput

      public SocketChannel shutdownInput() throws IOException
      Shut down the input stream of the underlying SSL socket.
      Specified by:
      shutdownInput in class SocketChannel
      Returns:
      this channel, for chaining
      Throws:
      IOException - if an I/O error occurs
    • shutdownOutput

      public SocketChannel shutdownOutput() throws IOException
      Shut down the output stream of the underlying SSL socket.
      Specified by:
      shutdownOutput in class SocketChannel
      Returns:
      this channel, for chaining
      Throws:
      IOException - if an I/O error occurs
    • setOption

      public <T> SocketChannel setOption(SocketOption<T> name, T value)
      Set a socket option. This is a no-op for this wrapper.
      Specified by:
      setOption in interface NetworkChannel
      Specified by:
      setOption in class SocketChannel
      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

      public SocketChannel bind(SocketAddress local)
      Bind is not supported by this wrapper.
      Specified by:
      bind in interface NetworkChannel
      Specified by:
      bind in class SocketChannel
      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

      public int read(ByteBuffer src) throws IOException
      Read bytes from the underlying SSL socket into the given buffer. The buffer must have a backing array.
      Specified by:
      read in interface ReadableByteChannel
      Specified by:
      read in class SocketChannel
      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 occurs
      UnsupportedOperationException - if the buffer has no backing array
    • read

      public long read(ByteBuffer[] srcs, int offset, int length)
      Scatter read is not supported by this wrapper.
      Specified by:
      read in interface ScatteringByteChannel
      Specified by:
      read in class SocketChannel
      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

      public int write(ByteBuffer src) throws IOException
      Write bytes from the given buffer to the underlying SSL socket. The buffer must have a backing array.
      Specified by:
      write in interface WritableByteChannel
      Specified by:
      write in class SocketChannel
      Parameters:
      src - the buffer to write from
      Returns:
      the number of bytes written
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if the buffer has no backing array
    • write

      public long write(ByteBuffer[] srcs, int offset, int length)
      Gather write is not supported by this wrapper.
      Specified by:
      write in interface GatheringByteChannel
      Specified by:
      write in class SocketChannel
      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

      public void implCloseSelectableChannel() throws IOException
      Close the underlying SSL socket.
      Specified by:
      implCloseSelectableChannel in class AbstractSelectableChannel
      Throws:
      IOException - if an I/O error occurs while closing
    • implConfigureBlocking

      public void implConfigureBlocking(boolean block) throws IOException
      Configure the blocking mode. Only blocking mode is supported.
      Specified by:
      implConfigureBlocking in class AbstractSelectableChannel
      Parameters:
      block - true for blocking mode (accepted), false throws
      Throws:
      IOException - if an I/O error occurs
      UnsupportedOperationException - if block is false
    • getLocalAddress

      public SocketAddress getLocalAddress()
      Get the local socket address of the underlying SSL socket.
      Specified by:
      getLocalAddress in interface NetworkChannel
      Specified by:
      getLocalAddress in class SocketChannel
      Returns:
      the local socket address, or null if not bound
    • getOption

      public <T> T getOption(SocketOption<T> name)
      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

      public Set<SocketOption<?>> supportedOptions()
      Get the set of supported socket options. Returns an empty set.
      Returns:
      an empty set of supported socket options