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>
public class FastContentOutputStream extends OutputStream implements Future<Boolean>
This class extends the
AbstractContentOutputStream
, and forwards all write() and close() calls to aFastContentWriter
. This means that onceOutputStream.close()
has been called, the asynchronous completion of all pending operations can be awaited using the ListenableFuture 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
Fields Modifier and Type Field Description static int
BUFFERSIZE
-
Constructor Summary
Constructors Constructor Description FastContentOutputStream(ContentChannel out)
Constructs a new FastContentOutputStream that writes into the givenContentChannel
.FastContentOutputStream(FastContentWriter out)
Constructs a new FastContentOutputStream that writes into the givenFastContentWriter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(Runnable listener, Executor executor)
boolean
cancel(boolean mayInterruptIfRunning)
void
close()
protected void
doClose()
protected void
doFlush(ByteBuffer buf)
void
flush()
Boolean
get()
Boolean
get(long timeout, TimeUnit unit)
boolean
isCancelled()
boolean
isDone()
void
write(byte[] buffer)
void
write(byte[] buffer, int offset, int length)
void
write(int b)
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Field Detail
-
BUFFERSIZE
public static final int BUFFERSIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FastContentOutputStream
public FastContentOutputStream(ContentChannel out)
Constructs a new FastContentOutputStream that writes into the given
ContentChannel
.- Parameters:
out
- The ContentChannel to write the stream into.
-
FastContentOutputStream
public FastContentOutputStream(FastContentWriter out)
Constructs a new FastContentOutputStream that writes into the given
FastContentWriter
.- Parameters:
out
- The ContentWriter to write the stream into.
-
-
Method Detail
-
doFlush
protected void doFlush(ByteBuffer buf)
-
doClose
protected void doClose()
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<Boolean>
-
get
public Boolean get() throws InterruptedException, ExecutionException
- 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
-
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
-
-