Package com.yahoo.jdisc.handler
Class FastContentOutputStream
java.lang.Object
java.io.OutputStream
com.yahoo.jdisc.handler.FastContentOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,Future<Boolean>
This class extends the AbstractContentOutputStream
, and forwards all write() and close() calls to a FastContentWriter
. This means that once OutputStream.close()
has been called, the asynchronous completion of all pending
operations can be awaited using the Future
interface of this class. Any asynchronous failure will be
rethrown when calling either of the get() methods on this class.
Please notice that the Future implementation of this class will NEVER complete unless OutputStream.close()
has been
called.
- Author:
- Simon Thoresen Hult
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs a new FastContentOutputStream that writes into the givenContentChannel
.Constructs a new FastContentOutputStream that writes into the givenFastContentWriter
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(Runnable listener, Executor executor) boolean
cancel
(boolean mayInterruptIfRunning) final void
close()
protected void
doClose()
protected void
doFlush
(ByteBuffer buf) final void
flush()
get()
boolean
boolean
isDone()
final void
write
(byte[] buffer) final void
write
(byte[] buffer, int offset, int length) final void
write
(int b) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
BUFFERSIZE
public static final int BUFFERSIZE- See Also:
-
-
Constructor Details
-
FastContentOutputStream
Constructs a new FastContentOutputStream that writes into the given
ContentChannel
.- Parameters:
out
- The ContentChannel to write the stream into.
-
FastContentOutputStream
Constructs a new FastContentOutputStream that writes into the given
FastContentWriter
.- Parameters:
out
- The ContentWriter to write the stream into.
-
-
Method Details
-
doFlush
-
doClose
protected void doClose() -
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
isCancelled
public boolean isCancelled()- Specified by:
isCancelled
in interfaceFuture<Boolean>
-
isDone
public boolean isDone() -
get
- Specified by:
get
in interfaceFuture<Boolean>
- Throws:
InterruptedException
ExecutionException
-
get
public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
get
in interfaceFuture<Boolean>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
addListener
-
write
public final void write(int b) - Specified by:
write
in classOutputStream
-
write
public final void write(byte[] buffer, int offset, int length) - Overrides:
write
in classOutputStream
-
write
public final void write(byte[] buffer) - Overrides:
write
in classOutputStream
-
flush
public final void flush()- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
-
close
public final void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
-