public class SSLSocketChannel
extends java.nio.channels.SocketChannel
SocketChannel
that adds SSL support.Constructor and Description |
---|
SSLSocketChannel(java.nio.channels.SocketChannel socketChannel,
javax.net.ssl.SSLEngine sslEngine,
java.util.concurrent.ExecutorService executorService,
NioSslLogger log) |
Modifier and Type | Method and Description |
---|---|
java.nio.channels.SocketChannel |
bind(java.net.SocketAddress local) |
boolean |
connect(java.net.SocketAddress socketAddress) |
boolean |
finishConnect() |
java.net.SocketAddress |
getLocalAddress() |
<T> T |
getOption(java.net.SocketOption<T> name) |
java.net.SocketAddress |
getRemoteAddress() |
java.nio.channels.SocketChannel |
getWrappedSocketChannel() |
protected void |
implCloseSelectableChannel() |
protected void |
implConfigureBlocking(boolean b) |
boolean |
isConnected() |
boolean |
isConnectionPending() |
int |
read(java.nio.ByteBuffer applicationBuffer)
Reads a sequence of bytes from this channel into the given buffer.
|
long |
read(java.nio.ByteBuffer[] applicationByteBuffers,
int offset,
int length)
Reads a sequence of bytes from this channel into a subsequence of the given buffers.
|
<T> java.nio.channels.SocketChannel |
setOption(java.net.SocketOption<T> name,
T value) |
java.nio.channels.SocketChannel |
shutdownInput() |
java.nio.channels.SocketChannel |
shutdownOutput() |
java.net.Socket |
socket() |
java.util.Set<java.net.SocketOption<?>> |
supportedOptions() |
int |
write(java.nio.ByteBuffer applicationBuffer)
Writes a sequence of bytes to this channel from the given buffer.
|
long |
write(java.nio.ByteBuffer[] applicationByteBuffers,
int offset,
int length)
Writes a sequence of bytes to this channel from a subsequence of the given buffers.
|
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, register
begin, close, end, isOpen
public SSLSocketChannel(java.nio.channels.SocketChannel socketChannel, javax.net.ssl.SSLEngine sslEngine, java.util.concurrent.ExecutorService executorService, NioSslLogger log)
socketChannel
- The real SocketChannel.sslEngine
- The SSL engine to use for traffic back and forth on the given SocketChannel.executorService
- Used to execute long running, blocking SSL operations such as certificate validation with a CA (NEED_TASK)log
- The logger for debug and error messages. A null
logger will result in no log operations.java.io.IOException
public java.nio.channels.SocketChannel getWrappedSocketChannel()
public int read(java.nio.ByteBuffer applicationBuffer) throws java.io.IOException, java.lang.IllegalArgumentException
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.
read
in interface java.nio.channels.ReadableByteChannel
read
in class java.nio.channels.SocketChannel
applicationBuffer
- The buffer into which bytes are to be transferredjava.nio.channels.NotYetConnectedException
- If this channel is not yet connectedjava.nio.channels.ClosedChannelException
- If this channel is closedjava.nio.channels.AsynchronousCloseException
- If another thread closes this channel while the read operation is in progressjava.nio.channels.ClosedByInterruptException
- If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt statusjava.io.IOException
- If some other I/O error occursjava.lang.IllegalArgumentException
- If the given applicationBuffer capacity (Buffer.capacity()
is less then the application buffer size of the SSLEngine
session application buffer size (SSLSession.getApplicationBufferSize()
this channel was constructed was.public int write(java.nio.ByteBuffer applicationBuffer) throws java.io.IOException, java.lang.IllegalArgumentException
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.
write
in interface java.nio.channels.WritableByteChannel
write
in class java.nio.channels.SocketChannel
applicationBuffer
- The buffer from which bytes are to be retrievedjava.nio.channels.NotYetConnectedException
- If this channel is not yet connectedjava.nio.channels.ClosedChannelException
- If this channel is closedjava.nio.channels.AsynchronousCloseException
- If another thread closes this channel while the read operation is in progressjava.nio.channels.ClosedByInterruptException
- If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt statusjava.io.IOException
- If some other I/O error occursjava.lang.IllegalArgumentException
- If the given applicationBuffer capacity (Buffer.capacity()
is less then the application buffer size of the SSLEngine
session application buffer size (SSLSession.getApplicationBufferSize()
this channel was constructed was.public long read(java.nio.ByteBuffer[] applicationByteBuffers, int offset, int length) throws java.io.IOException, java.lang.IllegalArgumentException
Reads a sequence of bytes from this channel into a subsequence of the given buffers.
An invocation of this method attempts to read up to r bytes from this channel, where r is the total number of bytes remaining the specified subsequence of the given buffer array, that is,
dsts[offset].remaining()
+ dsts[offset+1].remaining()
+ ... + dsts[offset+length-1].remaining()
at the moment that this method is invoked.
Suppose that a byte sequence of length n is read, where 0 <= n <= r. Up to the first dsts[offset].remaining() bytes of this sequence are transferred into buffer dsts[offset], up to the next dsts[offset+1].remaining() bytes are transferred into buffer dsts[offset+1], and so forth, until the entire byte sequence is transferred into the given buffers. As many bytes as possible are transferred into each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit.
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.
read
in interface java.nio.channels.ScatteringByteChannel
read
in class java.nio.channels.SocketChannel
applicationByteBuffers
- The buffers into which bytes are to be transferredoffset
- The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than dsts.lengthlength
- The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.length - offset
java.nio.channels.NotYetConnectedException
- If this channel is not yet connectedjava.nio.channels.ClosedChannelException
- If this channel is closedjava.nio.channels.AsynchronousCloseException
- If another thread closes this channel while the read operation is in progressjava.nio.channels.ClosedByInterruptException
- If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt statusjava.io.IOException
- If some other I/O error occursjava.lang.IllegalArgumentException
- If one of the given applicationBuffers capacity (Buffer.capacity()
is less then the application buffer size of the SSLEngine
session application buffer size (SSLSession.getApplicationBufferSize()
this channel was constructed was.public long write(java.nio.ByteBuffer[] applicationByteBuffers, int offset, int length) throws java.io.IOException, java.lang.IllegalArgumentException
Writes a sequence of bytes to this channel from a subsequence of the given buffers.
An attempt is made to write up to r bytes to this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,
srcs[offset].remaining()
+ srcs[offset+1].remaining()
+ ... + srcs[offset+length-1].remaining()
at the moment that this method is invoked.
Suppose that a byte sequence of length n is written, where 0 <= n <= r. Up to the first srcs[offset].remaining() bytes of this sequence are written from buffer srcs[offset], up to the next srcs[offset+1].remaining() bytes are written from buffer srcs[offset+1], and so forth, until the entire byte sequence is written. As many bytes as possible are written from each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit.
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.
write
in interface java.nio.channels.GatheringByteChannel
write
in class java.nio.channels.SocketChannel
applicationByteBuffers
- The buffers from which bytes are to be retrievedoffset
- offset - The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length
length
- The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
java.nio.channels.NotYetConnectedException
- If this channel is not yet connectedjava.nio.channels.ClosedChannelException
- If this channel is closedjava.nio.channels.AsynchronousCloseException
- If another thread closes this channel while the read operation is in progressjava.nio.channels.ClosedByInterruptException
- If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt statusjava.io.IOException
- If some other I/O error occursjava.lang.IllegalArgumentException
- If one of the given applicationBuffers capacity (Buffer.capacity()
is less then the application buffer size of the SSLEngine
session application buffer size (SSLSession.getApplicationBufferSize()
this channel was constructed was.public java.net.Socket socket()
socket
in class java.nio.channels.SocketChannel
public boolean isConnected()
isConnected
in class java.nio.channels.SocketChannel
public boolean isConnectionPending()
isConnectionPending
in class java.nio.channels.SocketChannel
public boolean connect(java.net.SocketAddress socketAddress) throws java.io.IOException
connect
in class java.nio.channels.SocketChannel
java.io.IOException
public boolean finishConnect() throws java.io.IOException
finishConnect
in class java.nio.channels.SocketChannel
java.io.IOException
public java.nio.channels.SocketChannel bind(java.net.SocketAddress local) throws java.io.IOException
bind
in interface java.nio.channels.NetworkChannel
bind
in class java.nio.channels.SocketChannel
java.io.IOException
public java.net.SocketAddress getLocalAddress() throws java.io.IOException
java.io.IOException
public <T> java.nio.channels.SocketChannel setOption(java.net.SocketOption<T> name, T value) throws java.io.IOException
setOption
in interface java.nio.channels.NetworkChannel
setOption
in class java.nio.channels.SocketChannel
java.io.IOException
public <T> T getOption(java.net.SocketOption<T> name) throws java.io.IOException
java.io.IOException
public java.util.Set<java.net.SocketOption<?>> supportedOptions()
public java.nio.channels.SocketChannel shutdownInput() throws java.io.IOException
shutdownInput
in class java.nio.channels.SocketChannel
java.io.IOException
public java.nio.channels.SocketChannel shutdownOutput() throws java.io.IOException
shutdownOutput
in class java.nio.channels.SocketChannel
java.io.IOException
public java.net.SocketAddress getRemoteAddress() throws java.io.IOException
getRemoteAddress
in class java.nio.channels.SocketChannel
java.io.IOException
protected void implConfigureBlocking(boolean b) throws java.io.IOException
implConfigureBlocking
in class java.nio.channels.spi.AbstractSelectableChannel
java.io.IOException
protected void implCloseSelectableChannel() throws java.io.IOException
implCloseSelectableChannel
in class java.nio.channels.spi.AbstractSelectableChannel
java.io.IOException