Package org.nuxeo.ecm.core.io.download
Class BufferingServletOutputStream
java.lang.Object
java.io.OutputStream
javax.servlet.ServletOutputStream
org.nuxeo.ecm.core.io.download.BufferingServletOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class BufferingServletOutputStream
extends javax.servlet.ServletOutputStream
A
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.
-
Field Summary
Modifier and TypeFieldDescriptionprotected OutputStream
static final int
Initial memory buffer size.static final int
Maximum memory buffer size, after this a file is used.protected ByteArrayOutputStream
protected boolean
protected boolean
protected final javax.servlet.ServletOutputStream
protected boolean
Have we stopped buffering to pass writes directly to the output stream.protected File
protected PrintWriter
-
Constructor Summary
ConstructorDescriptionBufferingServletOutputStream
(javax.servlet.ServletOutputStream outputStream) AServletOutputStream
wrapper that buffers everything untilstopBuffering()
is called. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
This implementation does nothing, we still want to keep the buffer untilstopBuffering()
time.protected void
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 writelen
bytes.boolean
boolean
isReady()
void
void
setWriteListener
(javax.servlet.WriteListener writeListener) void
Writes any buffered data to the underlyingOutputStream
and from now on don't buffer anymore.static void
Tells the givenOutputStream
to stop buffering (if it was).void
write
(byte[] b) void
write
(byte[] b, int off, int len) void
write
(int b) Methods inherited from class javax.servlet.ServletOutputStream
print, print, print, print, print, print, print, println, println, println, println, println, println, println, println
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
INITIAL
public static final int INITIALInitial memory buffer size.- See Also:
-
MAX
public static final int MAXMaximum memory buffer size, after this a file is used.- See Also:
-
streaming
protected boolean streamingHave we stopped buffering to pass writes directly to the output stream. -
needsFlush
protected boolean needsFlush -
needsClose
protected boolean needsClose -
outputStream
protected final javax.servlet.ServletOutputStream outputStream -
writer
-
memory
-
file
-
tmp
-
-
Constructor Details
-
BufferingServletOutputStream
public BufferingServletOutputStream(javax.servlet.ServletOutputStream outputStream) AServletOutputStream
wrapper that buffers everything untilstopBuffering()
is called.stopBuffering()
MUST be called in afinally
statement in order for resources to be closed properly.- Parameters:
outputStream
- the underlying output stream
-
-
Method Details
-
getWriter
-
getOutputStream
Finds the proper output stream where we can writelen
bytes.- Throws:
IOException
-
createTempFile
- Throws:
IOException
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
This implementation does nothing, we still want to keep buffering and not flush.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
close
This implementation does nothing, we still want to keep the buffer untilstopBuffering()
time.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
isCommitted
public boolean isCommitted()- Since:
- 11.5
-
resetBuffer
public void resetBuffer()- Since:
- 11.5
-
stopBuffering
Writes any buffered data to the underlyingOutputStream
and from now on don't buffer anymore.- Throws:
IOException
-
stopBuffering
Tells the givenOutputStream
to stop buffering (if it was).- Throws:
IOException
-
isReady
public boolean isReady()- Specified by:
isReady
in classjavax.servlet.ServletOutputStream
-
setWriteListener
public void setWriteListener(javax.servlet.WriteListener writeListener) - Specified by:
setWriteListener
in classjavax.servlet.ServletOutputStream
-