public SSLSocketChannelCommunicationsSession(final SSLSocketChannel channel) { super(); request = new SSLSocketChannelInput(channel); response = new SSLSocketChannelOutput(channel); this.channel = channel; }
@Override public boolean isDataAvailable() { try { return request.isDataAvailable(); } catch (final Exception e) { return false; } }
@Override public void consume() throws IOException { in.consume(); } }
@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); }
@Override public boolean isClosed() { return sslSocketChannel.isClosed(); }
/** * Closes the underlying SSLSocketChannel, which will also close the OutputStream and connection */ @Override public void close() throws IOException { channel.close(); }
@Override public void setTimeout(final int millis) throws IOException { channel.setTimeout(millis); }
public int read() throws IOException { final int bytesRead = read(oneByteBuffer); if (bytesRead == -1) { return -1; } return oneByteBuffer[0] & 0xFF; }
@Override protected void write(byte[] data) throws IOException { sslChannel.write(data); }
@Override public int getTimeout() throws IOException { return channel.getTimeout(); }
@Override public void interrupt() { sslSocketChannel.interrupt(); }
@Override public long getBytesWritten() { return response.getBytesWritten(); }
@Override public long getBytesRead() { return request.getBytesRead(); }
public boolean isDataAvailable() throws IOException { return available() > 0; } }
@Override public int available() throws IOException { return channel.available(); }
/** * Closes the underlying SSLSocketChannel, which also will close the InputStream and the connection */ @Override public void close() throws IOException { channel.close(); } }
@Override public int read() throws IOException { return channel.read(); }
@Override public void write(final int b) throws IOException { channel.write(b); }
@Override public int read(final byte[] b, final int off, final int len) throws IOException { return channel.read(b, off, len); }
@Override public void write(byte[] b) throws IOException { channel.write(b); }