예제 #1
0
 /**
  * Wraps an existing socket in a TLS-enabled socket. Any data within 'data' will be pushed into
  * the TLS layer.
  *
  * <p>This currently only works for creating server-side TLS sockets.
  *
  * <p>You must ensure that <code>isTLSCapable</code> returns true for the socket, otherwise an
  * <code>IllegalArgumentException</code> is thrown.
  */
 public static TLSNIOSocket startTLS(Socket socket, ByteBuffer data) throws IOException {
   if (socket instanceof AbstractNBSocket) {
     TLSNIOSocket tlsSocket = new TLSNIOSocket(socket);
     // Tell the channel to read in the buffered data.
     if (data.hasRemaining()) {
       SSLReadWriteChannel sslChannel = tlsSocket.getSSLChannel();
       InterestReadableByteChannel oldReader = sslChannel.getReadChannel();
       sslChannel.setReadChannel(new BufferReader(data));
       sslChannel.read(BufferUtils.getEmptyBuffer());
       if (data.hasRemaining())
         throw new IllegalStateException("unable to read all prebuffered data in one pass!");
       sslChannel.setReadChannel(oldReader);
     }
     return tlsSocket;
   } else {
     throw new IllegalArgumentException("cannot wrap non AbstractNBSocket");
   }
 }
예제 #2
0
 public long getWrittenBytesProduced() {
   return channel.getWrittenBytesProduced();
 }
예제 #3
0
 public long getReadBytesProduced() {
   return channel.getReadBytesProduced();
 }
예제 #4
0
 public long getWrittenBytesConsumed() {
   return channel.getWrittenBytesConsumed();
 }
예제 #5
0
 public long getReadBytesConsumed() {
   return channel.getReadBytesConsumed();
 }