当前位置: 首页>>代码示例>>Java>>正文


Java SSLEngineResult.bytesConsumed方法代码示例

本文整理汇总了Java中javax.net.ssl.SSLEngineResult.bytesConsumed方法的典型用法代码示例。如果您正苦于以下问题:Java SSLEngineResult.bytesConsumed方法的具体用法?Java SSLEngineResult.bytesConsumed怎么用?Java SSLEngineResult.bytesConsumed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.net.ssl.SSLEngineResult的用法示例。


在下文中一共展示了SSLEngineResult.bytesConsumed方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkResult

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private void checkResult(SSLEngineResult result, boolean wrap)
        throws SSLException {

    handshakeStatus = result.getHandshakeStatus();
    resultStatus = result.getStatus();

    if (resultStatus != Status.OK &&
            (wrap || resultStatus != Status.BUFFER_UNDERFLOW)) {
        throw new SSLException("TODO");
    }
    if (wrap && result.bytesConsumed() != 0) {
        throw new SSLException("TODO");
    }
    if (!wrap && result.bytesProduced() != 0) {
        throw new SSLException("TODO");
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:18,代码来源:AsyncChannelWrapperSecure.java

示例2: write

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
* Writes a sequence of bytes to this channel from the given buffer.
*
* @param src The buffer from which bytes are to be retrieved
* @return The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
* @throws IOException If some other I/O error occurs
*/
@Override
public int write(ByteBuffer src) throws IOException {
    int written = 0;
    if (closing) throw new IllegalStateException("Channel is in closing state");
    if (!handshakeComplete) return written;

    if (!flush(netWriteBuffer))
        return written;

    netWriteBuffer.clear();
    SSLEngineResult wrapResult = sslEngine.wrap(src, netWriteBuffer);
    netWriteBuffer.flip();

    //handle ssl renegotiation
    if (wrapResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && wrapResult.getStatus() == Status.OK) {
        renegotiate();
        return written;
    }

    if (wrapResult.getStatus() == Status.OK) {
        written = wrapResult.bytesConsumed();
        flush(netWriteBuffer);
    } else if (wrapResult.getStatus() == Status.BUFFER_OVERFLOW) {
        int currentNetWriteBufferSize = netWriteBufferSize();
        netWriteBuffer.compact();
        netWriteBuffer = Utils.ensureCapacity(netWriteBuffer, currentNetWriteBufferSize);
        netWriteBuffer.flip();
        if (netWriteBuffer.limit() >= currentNetWriteBufferSize)
            throw new IllegalStateException("SSL BUFFER_OVERFLOW when available data size (" + netWriteBuffer.limit() + ") >= network buffer size (" + currentNetWriteBufferSize + ")");
    } else if (wrapResult.getStatus() == Status.BUFFER_UNDERFLOW) {
        throw new IllegalStateException("SSL BUFFER_UNDERFLOW during write");
    } else if (wrapResult.getStatus() == Status.CLOSED) {
        throw new EOFException();
    }
    return written;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:44,代码来源:SslTransportLayer.java

示例3: checkResult

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private void checkResult(SSLEngineResult result, boolean wrap) throws SSLException {

			handshakeStatus = result.getHandshakeStatus();
			resultStatus = result.getStatus();

			if (resultStatus != Status.OK && (wrap || resultStatus != Status.BUFFER_UNDERFLOW)) {
				throw new SSLException("TODO");
			}
			if (wrap && result.bytesConsumed() != 0) {
				throw new SSLException("TODO");
			}
			if (!wrap && result.bytesProduced() != 0) {
				throw new SSLException("TODO");
			}
		}
 
开发者ID:how2j,项目名称:lazycat,代码行数:16,代码来源:AsyncChannelWrapperSecure.java

示例4: writeInternal

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private void writeInternal(ByteBuffer buffer) throws IOException {
    Platform.blockGuardOnNetwork();
    checkOpen();
    init();

    // Need to loop through at least once to enable handshaking where no application
    // bytes are
    // processed.
    int len = buffer.remaining();
    SSLEngineResult engineResult;
    do {
        target.clear();
        engineResult = engine.wrap(buffer, target);
        if (engineResult.getStatus() != OK) {
            throw new SSLException("Unexpected engine result " + engineResult.getStatus());
        }
        if (target.position() != engineResult.bytesProduced()) {
            throw new SSLException("Engine bytesProduced " + engineResult.bytesProduced()
                    + " does not match bytes written " + target.position());
        }
        len -= engineResult.bytesConsumed();
        if (len != buffer.remaining()) {
            throw new SSLException("Engine did not read the correct number of bytes");
        }

        target.flip();

        // Write the data to the socket.
        writeToSocket();
    } while (len > 0);
}
 
开发者ID:google,项目名称:conscrypt,代码行数:32,代码来源:ConscryptEngineSocket.java

示例5: verifyResult

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
private void verifyResult(ByteBuffer src, SSLEngineResult result) {
    if (result.getStatus() != SSLEngineResult.Status.OK) {
        throw new RuntimeException("Operation returned unexpected result " + result);
    }
    if (result.bytesConsumed() != src.limit()) {
        throw new RuntimeException(
                String.format(Locale.US,
                        "Operation didn't consume all bytes. Expected %d, consumed %d.",
                        src.limit(), result.bytesConsumed()));
    }
}
 
开发者ID:google,项目名称:conscrypt,代码行数:12,代码来源:EngineWrapBenchmark.java

示例6: write

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
@Override public void write(byte[] buf, int off, int len) throws IOException
{
  if (!initialHandshakeDone
      || engine.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING)
    {
      doHandshake();
      if (handshakeException != null)
        throw handshakeException;
    }

  int k = 0;
  while (k < len)
    {
      synchronized (engine)
        {
          int l = Math.min(len-k, getSession().getApplicationBufferSize());
          ByteBuffer in = ByteBuffer.wrap(buf, off+k, l);
          SSLEngineResult result = engine.wrap(in, buffer);
          if (result.getStatus() == Status.CLOSED)
            return;
          if (result.getStatus() != Status.OK)
            throw new SSLException("unexpected SSL state " + result.getStatus());
          buffer.flip();
          out.write(buffer.array(), 0, buffer.limit());
          k += result.bytesConsumed();
          buffer.clear();
        }
    }
}
 
开发者ID:vilie,项目名称:javify,代码行数:30,代码来源:SSLSocketImpl.java

示例7: run

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
@Override
public void run() {
    long written = 0;

    try {
        for (int i = offset; i < offset + length; i++) {
            ByteBuffer src = srcs[i];
            while (src.hasRemaining()) {
                socketWriteBuffer.clear();

                // Encrypt the data
                SSLEngineResult r = sslEngine.wrap(src, socketWriteBuffer);
                written += r.bytesConsumed();
                Status s = r.getStatus();

                if (s == Status.OK || s == Status.BUFFER_OVERFLOW) {
                    // Need to write out the bytes and may need to read from
                    // the source again to empty it
                } else {
                    // Status.BUFFER_UNDERFLOW - only happens on unwrap
                    // Status.CLOSED - unexpected
                    throw new IllegalStateException(sm.getString(
                            "asyncChannelWrapperSecure.statusWrap"));
                }

                // Check for tasks
                if (r.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
                    Runnable runnable = sslEngine.getDelegatedTask();
                    while (runnable != null) {
                        runnable.run();
                        runnable = sslEngine.getDelegatedTask();
                    }
                }

                socketWriteBuffer.flip();

                // Do the write
                int toWrite = r.bytesProduced();
                while (toWrite > 0) {
                    Future<Integer> f =
                            socketChannel.write(socketWriteBuffer);
                    Integer socketWrite = f.get();
                    toWrite -= socketWrite.intValue();
                }
            }
        }


        if (writing.compareAndSet(true, false)) {
            future.complete(Long.valueOf(written));
        } else {
            future.fail(new IllegalStateException(sm.getString(
                    "asyncChannelWrapperSecure.wrongStateWrite")));
        }
    } catch (Exception e) {
        future.fail(e);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:59,代码来源:AsyncChannelWrapperSecure.java

示例8: run

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
@Override
public void run() {
	long written = 0;

	try {
		for (int i = offset; i < offset + length; i++) {
			ByteBuffer src = srcs[i];
			while (src.hasRemaining()) {
				socketWriteBuffer.clear();

				// Encrypt the data
				SSLEngineResult r = sslEngine.wrap(src, socketWriteBuffer);
				written += r.bytesConsumed();
				Status s = r.getStatus();

				if (s == Status.OK || s == Status.BUFFER_OVERFLOW) {
					// Need to write out the bytes and may need to read
					// from
					// the source again to empty it
				} else {
					// Status.BUFFER_UNDERFLOW - only happens on unwrap
					// Status.CLOSED - unexpected
					throw new IllegalStateException(sm.getString("asyncChannelWrapperSecure.statusWrap"));
				}

				// Check for tasks
				if (r.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
					Runnable runnable = sslEngine.getDelegatedTask();
					while (runnable != null) {
						runnable.run();
						runnable = sslEngine.getDelegatedTask();
					}
				}

				socketWriteBuffer.flip();

				// Do the write
				int toWrite = r.bytesProduced();
				while (toWrite > 0) {
					Future<Integer> f = socketChannel.write(socketWriteBuffer);
					Integer socketWrite = f.get();
					toWrite -= socketWrite.intValue();
				}
			}
		}

		if (writing.compareAndSet(true, false)) {
			future.complete(Long.valueOf(written));
		} else {
			future.fail(new IllegalStateException(sm.getString("asyncChannelWrapperSecure.wrongStateWrite")));
		}
	} catch (Exception e) {
		future.fail(e);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:56,代码来源:AsyncChannelWrapperSecure.java

示例9: wrapOutput

import javax.net.ssl.SSLEngineResult; //导入方法依赖的package包/类
/**
 * Wrap the underlying transport's output, passing it to the output buffer.
 *
 * {@link #_outputBuffer} is assumed to be writeable on entry and is guaranteed to
 * be still writeable on exit.
 */
private void wrapOutput() throws SSLException
{
    while (true) {
        int pending = _underlyingOutput.pending();
        if (pending < 0) {
            _head_closed = true;
        }

        ByteBuffer clearOutputBuffer = _underlyingOutput.head();
        SSLEngineResult result = _sslEngine.wrap(clearOutputBuffer, _outputBuffer);
        logEngineClientModeAndResult(result, "output");

        int written = result.bytesConsumed();
        _underlyingOutput.pop(written);
        pending = _underlyingOutput.pending();

        Status status = result.getStatus();
        switch (status) {
        case CLOSED:
            _head_closed = true;
            break;
        case OK:
            break;
        case BUFFER_OVERFLOW:
            ByteBuffer old = _outputBuffer;
            _outputBuffer = newWriteableBuffer(_outputBuffer.capacity()*2);
            _head = _outputBuffer.asReadOnlyBuffer();
            old.flip();
            _outputBuffer.put(old);
            continue;
        case BUFFER_UNDERFLOW:
            throw new IllegalStateException("app buffer underflow");
        }

        HandshakeStatus hstatus = result.getHandshakeStatus();
        switch (hstatus) {
        case NEED_UNWRAP:
            // wait for input data
            if (_inputBuffer.position() == 0 && _tail_closed) {
                _head_closed = true;
            }
            break;
        case NEED_WRAP:
            // keep looping
            continue;
        case NEED_TASK:
            runDelegatedTasks(result);
            continue;
        case FINISHED:
            updateCipherAndProtocolName(result);
            // intentionally fall through
        case NOT_HANDSHAKING:
            if (pending > 0 && status == Status.OK) {
                continue;
            } else {
                break;
            }
        }

        break;
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:69,代码来源:SimpleSslTransportWrapper.java


注:本文中的javax.net.ssl.SSLEngineResult.bytesConsumed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。