public class FastContentOutputStream extends OutputStream implements com.google.common.util.concurrent.ListenableFuture<Boolean>
This class extends the AbstractContentOutputStream
, and forwards all write() and close() calls to a FastContentWriter
. This means that once 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 close()
has been
called.
Modifier and Type | Field and Description |
---|---|
static int |
BUFFERSIZE |
Constructor and Description |
---|
FastContentOutputStream(ContentChannel out)
Constructs a new FastContentOutputStream that writes into the given
ContentChannel . |
FastContentOutputStream(FastContentWriter out)
Constructs a new FastContentOutputStream that writes into the given
FastContentWriter . |
Modifier and Type | Method and 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) |
public static final int BUFFERSIZE
public FastContentOutputStream(ContentChannel out)
Constructs a new FastContentOutputStream that writes into the given ContentChannel
.
out
- The ContentChannel to write the stream into.public FastContentOutputStream(FastContentWriter out)
Constructs a new FastContentOutputStream that writes into the given FastContentWriter
.
out
- The ContentWriter to write the stream into.protected void doFlush(ByteBuffer buf)
protected void doClose()
public boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
isCancelled
in interface Future<Boolean>
public Boolean get() throws InterruptedException, ExecutionException
get
in interface Future<Boolean>
InterruptedException
ExecutionException
public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get
in interface Future<Boolean>
InterruptedException
ExecutionException
TimeoutException
public void addListener(Runnable listener, Executor executor)
addListener
in interface com.google.common.util.concurrent.ListenableFuture<Boolean>
public final void write(int b)
write
in class OutputStream
public final void write(byte[] buffer, int offset, int length)
write
in class OutputStream
public final void write(byte[] buffer)
write
in class OutputStream
public final void flush()
flush
in interface Flushable
flush
in class OutputStream
public final void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
Copyright © 2018. All rights reserved.