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..."); } } }
socketChannel.connect();
@Override public void open() throws IOException { if (sslChannel == null) { super.open(); sslChannel = new SSLSocketChannel(sslContext, channel, true); } sslChannel.setTimeout(timeout); // SSLSocketChannel will check if already connected so we can safely call this sslChannel.connect(); sslOutputStream = new SSLSocketChannelOutputStream(sslChannel); }
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..."); } } }