Search in sources :

Example 1 with BufferStateManager

use of org.apache.nifi.remote.io.socket.BufferStateManager in project nifi by apache.

the class SSLSocketChannel method write.

public void write(final byte[] data, final int offset, final int len) throws IOException {
    logger.debug("{} Writing {} bytes of data", this, len);
    if (!connected) {
        connect();
    }
    int iterations = len / MAX_WRITE_SIZE;
    if (len % MAX_WRITE_SIZE > 0) {
        iterations++;
    }
    for (int i = 0; i < iterations; i++) {
        streamOutManager.clear();
        final int itrOffset = offset + i * MAX_WRITE_SIZE;
        final int itrLen = Math.min(len - itrOffset, MAX_WRITE_SIZE);
        final ByteBuffer byteBuffer = ByteBuffer.wrap(data, itrOffset, itrLen);
        final BufferStateManager buffMan = new BufferStateManager(byteBuffer, Direction.READ);
        final Status status = encryptAndWriteFully(buffMan);
        switch(status) {
            case BUFFER_OVERFLOW:
                streamOutManager.ensureSize(engine.getSession().getPacketBufferSize());
                appDataManager.ensureSize(engine.getSession().getApplicationBufferSize());
                continue;
            case OK:
                continue;
            case CLOSED:
                throw new IOException("Channel is closed");
            case BUFFER_UNDERFLOW:
                throw new AssertionError("Got Buffer Underflow but should not have...");
        }
    }
}
Also used : Status(javax.net.ssl.SSLEngineResult.Status) BufferStateManager(org.apache.nifi.remote.io.socket.BufferStateManager) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Status (javax.net.ssl.SSLEngineResult.Status)1 BufferStateManager (org.apache.nifi.remote.io.socket.BufferStateManager)1