public class SecureNioChannel extends NioChannel
SecureNioChannel
This class is an extension of the class NioChannel to allow using
secure communication channels.
SSLEngine| Modifier and Type | Field and Description |
|---|---|
protected boolean |
handshakeComplete |
protected SSLEngineResult.HandshakeStatus |
handshakeStatus |
protected SSLEngine |
sslEngine |
channel, OP_STATUS_CLOSED, OP_STATUS_ERROR, OP_STATUS_NORMAL, OP_STATUS_READ_KILLED, OP_STATUS_READ_TIMEOUT, OP_STATUS_WRITE_KILLED, OP_STATUS_WRITE_TIMEOUT| Modifier | Constructor and Description |
|---|---|
protected |
SecureNioChannel(AsynchronousSocketChannel channel,
SSLEngine engine)
Create a new instance of
SecureNioChannel |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this channel.
|
SSLEngine |
getSslEngine()
Getter for sslEngine
|
SSLSession |
getSSLSession() |
protected void |
handshake()
Initiates handshaking (initial or renegotiation) on this SSLEngine.
|
protected boolean |
handshakeComplete()
Check if the handshake was done or not yet
|
boolean |
isSecure() |
Future<Integer> |
read(ByteBuffer dst)
Deprecated.
|
<A> void |
read(ByteBuffer[] dsts,
int offset,
int length,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Long,? super A> handler)
Reads a sequence of bytes from this channel into a subsequence of the
given buffers.
|
<A> void |
read(ByteBuffer dst,
A attachment,
CompletionHandler<Integer,? super A> handler) |
<A> void |
read(ByteBuffer dst,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
Reads a sequence of bytes from this channel into the given buffer.
|
int |
readBytes(ByteBuffer dst)
Read a sequence of bytes in blocking mode.
|
int |
readBytes(ByteBuffer dst,
long timeout,
TimeUnit unit)
Read a sequence of bytes in blocking mode
|
protected void |
reHandshake()
Start a new handshake operation for this channel.
|
protected void |
setSslEngine(SSLEngine sslEngine)
Setter for the sslEngine
|
Future<Integer> |
write(ByteBuffer src)
Deprecated.
|
<A> void |
write(ByteBuffer[] srcs,
int offset,
int length,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Long,? super A> handler)
Writes a sequence of bytes to this channel from a subsequence of the
given buffers.
|
<A> void |
write(ByteBuffer src,
A attachment,
CompletionHandler<Integer,? super A> handler) |
<A> void |
write(ByteBuffer src,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
Writes a sequence of bytes to this channel from the given buffer.
|
int |
writeBytes(ByteBuffer src)
Writes a sequence of bytes to this channel from the given buffer.
|
int |
writeBytes(ByteBuffer src,
long timeout,
TimeUnit unit)
Write a sequence of bytes in blocking mode.
|
awaitRead, awaitRead, bind, bind, close, connect, connect, getBuffer, getId, getLocalAddress, getName, getOption, getRemoteAddress, isClosed, isOpen, open, open, provider, reset, reset, setOption, shutdownInput, shutdownOutput, supportedOptions, toStringprotected SSLEngine sslEngine
protected boolean handshakeComplete
protected SSLEngineResult.HandshakeStatus handshakeStatus
protected SecureNioChannel(AsynchronousSocketChannel channel, SSLEngine engine)
SecureNioChannelchannel - the AsynchronousSocketChannelengine - The SSLEngine linked to this channelNullPointerException - if the one at least one of the parameters is nullpublic boolean isSecure()
isSecure in class NioChannel@Deprecated public Future<Integer> read(ByteBuffer dst)
read in interface AsynchronousByteChannelread in class NioChannelpublic int readBytes(ByteBuffer dst) throws Exception
NioChannelreadBytes(dst, Integer.MAX_VALUE, TimeUnit.MILLISECONDS).readBytes in class NioChanneldst - the buffer containing the read bytesExceptionExecutionExceptionInterruptedExceptionpublic int readBytes(ByteBuffer dst, long timeout, TimeUnit unit) throws Exception
NioChannelreadBytes in class NioChanneldst - the buffer containing the read bytestimeout - the read timeoutunit - the timeout unitNioChannel.OP_STATUS_CLOSED if the channel is closedNioChannel.OP_STATUS_READ_TIMEOUT if the operation
was timed outExceptionExecutionExceptionInterruptedExceptionpublic <A> void read(ByteBuffer dst, A attachment, CompletionHandler<Integer,? super A> handler)
read in interface AsynchronousByteChannelread in class NioChannelpublic <A> void read(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)
NioChannel
This method initiates an asynchronous read operation to read a sequence
of bytes from this channel into the given buffer. The handler
parameter is a completion handler that is invoked when the read operation
completes (or fails). The result passed to the completion handler is the
number of bytes read or -1 if no bytes could be read because the
channel has reached end-of-stream.
If a timeout is specified and the timeout elapses before the operation
completes then the operation completes with the exception
InterruptedByTimeoutException. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been read, or will
not be read from the channel into the given buffer, then further attempts
to read from the channel will cause an unspecific runtime exception to be
thrown.
Otherwise this method works in the same manner as the
NioChannel.read(ByteBuffer,Object,CompletionHandler) method.
read in class NioChanneldst - The buffer into which bytes are to be transferredtimeout - The maximum time for the I/O operation to completeunit - The time unit of the timeout argumentattachment - The object to attach to the I/O operation; can be nullhandler - The handler for consuming the resultpublic <A> void read(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler)
NioChannelhandler parameter is a completion handler that is invoked when
the read operation completes (or fails). The result passed to the
completion handler is the number of bytes read or -1 if no bytes
could be read because the channel has reached end-of-stream.
This method initiates a read of up to r bytes from this channel, where r is the total number of bytes remaining in 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 the read is attempted.
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. The underlying operating system may impose a limit on the number of buffers that may be used in an I/O operation. Where the number of buffers (with bytes remaining), exceeds this limit, then the I/O operation is performed with the maximum number of buffers allowed by the operating system.
If a timeout is specified and the timeout elapses before the operation
completes then it completes with the exception
InterruptedByTimeoutException. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been read, or will
not be read from the channel into the given buffers, then further
attempts to read from the channel will cause an unspecific runtime
exception to be thrown.
read in class NioChanneldsts - 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 - offsettimeout - The maximum time for the I/O operation to completeunit - The time unit of the timeout argumentattachment - The object to attach to the I/O operation; can be nullhandler - The handler for consuming the result@Deprecated public Future<Integer> write(ByteBuffer src)
NioChannelwrite in interface AsynchronousByteChannelwrite in class NioChannelsrc - The buffer from which bytes are to be retrievedFuture containing the
number of bytes writtenAsynchronousByteChannel.write(java.nio.ByteBuffer)public int writeBytes(ByteBuffer src) throws Exception
NioChannel
This method initiates an asynchronous write operation to write a sequence
of bytes to this channel from the given buffer. The method behaves in
exactly the same manner as the
NioChannel.writeBytes(ByteBuffer, long, TimeUnit) with
Integer.MAX_VALUE as a timeout and
TimeUnit.MILLISECONDS as a time unit.
writeBytes in class NioChannelsrc - The buffer from which bytes are to be retrievedWritePendingException - If the channel does not allow more than one write to be
outstanding and a previous write has not completedExecutionExceptionInterruptedExceptionException - If any other type of errors occursNioChannel.writeBytes(ByteBuffer, long, TimeUnit)public int writeBytes(ByteBuffer src, long timeout, TimeUnit unit) throws Exception
NioChannelwriteBytes in class NioChannelsrc - the buffer containing the bytes to writetimeout - the read timeoutunit - the timeout unitNioChannel.OP_STATUS_CLOSED if the channel is closedNioChannel.OP_STATUS_WRITE_TIMEOUT if the operation
was timed outExceptionExecutionExceptionInterruptedExceptionpublic <A> void write(ByteBuffer src, A attachment, CompletionHandler<Integer,? super A> handler)
write in interface AsynchronousByteChannelwrite in class NioChannelpublic <A> void write(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)
NioChannel
This method initiates an asynchronous write operation to write a sequence
of bytes to this channel from the given buffer. The handler
parameter is a completion handler that is invoked when the write
operation completes (or fails). The result passed to the completion
handler is the number of bytes written.
If a timeout is specified and the timeout elapses before the operation
completes then it completes with the exception
InterruptedByTimeoutException. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been written, or will
not be written to the channel from the given buffer, then further
attempts to write to the channel will cause an unspecific runtime
exception to be thrown.
Otherwise this method works in the same manner as the
NioChannel.write(ByteBuffer,Object,CompletionHandler) method.
write in class NioChannelsrc - The buffer from which bytes are to be retrievedtimeout - The maximum time for the I/O operation to completeunit - The time unit of the timeout argumentattachment - The object to attach to the I/O operation; can be nullhandler - The handler for consuming the resultpublic <A> void write(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler)
NioChannelhandler parameter is a completion handler that is invoked when
the write operation completes (or fails). The result passed to the
completion handler is the number of bytes written.
This method initiates a write of 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 the write is attempted.
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. The underlying operating system may impose a limit on the number of buffers that may be used in an I/O operation. Where the number of buffers (with bytes remaining), exceeds this limit, then the I/O operation is performed with the maximum number of buffers allowed by the operating system.
If a timeout is specified and the timeout elapses before the operation
completes then it completes with the exception
InterruptedByTimeoutException. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been written, or will
not be written to the channel from the given buffers, then further
attempts to write to the channel will cause an unspecific runtime
exception to be thrown.
write in class NioChannelsrcs - The buffers from which bytes are to be retrievedoffset - 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.lengthlength - The maximum number of buffers to be accessed; must be
non-negative and no larger than srcs.length - offsettimeout - The maximum time for the I/O operation to completeunit - The time unit of the timeout argumentattachment - The object to attach to the I/O operation; can be nullhandler - The handler for consuming the resultpublic void close()
throws IOException
NioChannel
Any outstanding asynchronous operations upon this channel will complete
with the exception AsynchronousCloseException. After a channel is
closed, further attempts to initiate asynchronous I/O operations complete
immediately with cause ClosedChannelException.
This method otherwise behaves exactly as specified by the
Channel interface.
close in interface Closeableclose in interface AutoCloseableclose in interface AsynchronousChannelclose in interface Channelclose in class NioChannelIOException - If an I/O error occurspublic SSLEngine getSslEngine()
protected void setSslEngine(SSLEngine sslEngine)
sslEngine - the sslEngine to setprotected void handshake()
throws SSLException
This method is not needed for the initial handshake, as the
wrap() and unwrap() methods will implicitly
call this method if handshaking has not already begun.
Note that the client may also request a session renegotiation with this
SSLEngine by sending the appropriate session renegotiate
handshake message.
Unlike the SSLSocket#startHandshake()
method, this method does not block until handshaking is completed.
To force a complete SSL/TLS session renegotiation, the current session should be invalidated prior to calling this method.
Some protocols may not support multiple handshakes on an existing engine
and may throw an SSLException.
SSLException - if a problem was encountered while signaling the
SSLEngine to begin a new handshake. See the
class description for more information on engine closure.IllegalStateException - if the client/server mode has not yet been set.SSLEngine.beginHandshake(),
SSLSession.invalidate()protected void reHandshake()
throws SSLException
SSLExceptionhandshake()protected boolean handshakeComplete()
public SSLSession getSSLSession()
Copyright © 2016 JBoss by Red Hat. All rights reserved.