public class ReadableInputStreamFrameChannel extends Object implements ReadableFrameChannel
InputStream
.
Frame channels are expected to be nonblocking, but InputStreams cannot be read in nonblocking fashion.
This implementation deals with that by using an ExecutorService
to read from the stream in a
separate thread.
Modifier and Type | Method and Description |
---|---|
boolean |
canRead()
Returns whether this channel has a frame or error condition currently available.
|
void |
close()
Releases any resources associated with this readable channel.
|
boolean |
isFinished()
Returns whether this channel is finished.
|
static ReadableInputStreamFrameChannel |
open(InputStream inputStream,
String id,
ExecutorService executorService,
boolean framesOnly)
Create an instance of this class and immediately start reading from the provided InputStream.
|
Frame |
read()
Returns the next available frame from this channel.
|
com.google.common.util.concurrent.ListenableFuture<?> |
readabilityFuture()
Returns a future that will resolve when either
ReadableFrameChannel.isFinished() or ReadableFrameChannel.canRead() would
return true. |
public static ReadableInputStreamFrameChannel open(InputStream inputStream, String id, ExecutorService executorService, boolean framesOnly)
public boolean isFinished()
ReadableFrameChannel
ReadableFrameChannel.close()
and then
discard it.
Note that it is possible for a channel to be unfinished and also have no available frames or errors. This happens
when it is not in a ready-for-reading state. See ReadableFrameChannel.readabilityFuture()
for details.isFinished
in interface ReadableFrameChannel
public boolean canRead()
ReadableFrameChannel
ReadableFrameChannel.read()
to retrieve the frame or error.
Note that it is possible for a channel to be unfinished and also have no available frames or errors. This happens
when it is not in a ready-for-reading state. See ReadableFrameChannel.readabilityFuture()
for details.canRead
in interface ReadableFrameChannel
public Frame read()
ReadableFrameChannel
ReadableFrameChannel.canRead()
to ensure there is a frame or
error available.read
in interface ReadableFrameChannel
public com.google.common.util.concurrent.ListenableFuture<?> readabilityFuture()
ReadableFrameChannel
ReadableFrameChannel.isFinished()
or ReadableFrameChannel.canRead()
would
return true. The future will never resolve to an exception. If something exceptional has happened, the exception
can be retrieved from ReadableFrameChannel.read()
.readabilityFuture
in interface ReadableFrameChannel
public void close()
ReadableFrameChannel
close
in interface Closeable
close
in interface AutoCloseable
close
in interface ReadableFrameChannel
Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.