@Override protected InputStream getInputStream() { if (inputStream == null) { if (channel instanceof AsynchronousByteChannel) { inputStream = new AsynchronousByteChannelInputStream((AsynchronousByteChannel) channel, timeout); } else { inputStream = Channels.newInputStream((ReadableByteChannel) channel); } } return inputStream; }
@Override protected OutputStream getOutputStream() { if (outputStream == null) { if (channel instanceof AsynchronousByteChannel) { outputStream = new AsynchronousByteChannelOutputStream((AsynchronousByteChannel) channel); } else { outputStream = Channels.newOutputStream((WritableByteChannel) channel); } } return outputStream; }
@Override protected void sendUrgentData(int data) throws IOException { if (outputStream == null) { if (channel instanceof AsynchronousByteChannel) { outputStream = new AsynchronousByteChannelOutputStream((AsynchronousByteChannel) channel); } else { outputStream = Channels.newOutputStream((WritableByteChannel) channel); } } outputStream.write(data); outputStream.flush(); }
public static CompletableAsynchronousByteChannel adapt(AsynchronousByteChannel original) { if (original instanceof CompletableAsynchronousByteChannel) { return (CompletableAsynchronousByteChannel)original; } return new Adapter(original); }
private Adapter(AsynchronousByteChannel delegate) { this.delegate = delegate; }
AsynchronousByteChannelInputStream(AsynchronousByteChannel channel, int timeout) { this.channel = channel; this.timeout = timeout; }
AsynchronousByteChannelOutputStream(AsynchronousByteChannel channel) { this.channel = channel; }