public class BufferingServletOutputStream extends javax.servlet.ServletOutputStream
ServletOutputStream
that buffers everything until stopBuffering()
is called.
There may only be one such instance per thread.
Buffering is done first in memory, then on disk if the size exceeds a limit.
Modifier and Type | Field and Description |
---|---|
protected OutputStream |
file |
static int |
INITIAL
Initial memory buffer size.
|
static int |
MAX
Maximum memory buffer size, after this a file is used.
|
protected ByteArrayOutputStream |
memory |
protected boolean |
needsClose |
protected boolean |
needsFlush |
protected OutputStream |
outputStream |
protected boolean |
streaming
Have we stopped buffering to pass writes directly to the output stream.
|
protected File |
tmp |
protected PrintWriter |
writer |
Constructor and Description |
---|
BufferingServletOutputStream(OutputStream outputStream)
A
ServletOutputStream wrapper that buffers everything until stopBuffering() is called. |
Modifier and Type | Method and Description |
---|---|
void |
close()
This implementation does nothing, we still want to keep the buffer until
stopBuffering() time. |
protected void |
createTempFile() |
void |
flush()
This implementation does nothing, we still want to keep buffering and not flush.
|
protected OutputStream |
getOutputStream(int len)
Finds the proper output stream where we can write
len bytes. |
PrintWriter |
getWriter() |
void |
stopBuffering()
Writes any buffered data to the underlying
OutputStream and from now on don't buffer anymore. |
static void |
stopBuffering(OutputStream out)
Tells the given
OutputStream to stop buffering (if it was). |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
public static final int INITIAL
public static final int MAX
protected boolean streaming
protected boolean needsFlush
protected boolean needsClose
protected final OutputStream outputStream
protected PrintWriter writer
protected ByteArrayOutputStream memory
protected OutputStream file
public BufferingServletOutputStream(OutputStream outputStream)
ServletOutputStream
wrapper that buffers everything until stopBuffering()
is called.
stopBuffering()
MUST be called in a finally
statement in order for resources to be closed
properly.
outputStream
- the underlying output streampublic PrintWriter getWriter()
protected OutputStream getOutputStream(int len) throws IOException
len
bytes.IOException
protected void createTempFile() throws IOException
IOException
public void write(int b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public void close() throws IOException
stopBuffering()
time.
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
public void stopBuffering() throws IOException
OutputStream
and from now on don't buffer anymore.IOException
public static void stopBuffering(OutputStream out) throws IOException
OutputStream
to stop buffering (if it was).IOException
Copyright © 2018 Nuxeo. All rights reserved.