Package org.nuxeo.ecm.core.io.download
Class BufferingServletOutputStream
java.lang.Object
java.io.OutputStream
jakarta.servlet.ServletOutputStream
org.nuxeo.ecm.core.io.download.BufferingServletOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class BufferingServletOutputStream
extends jakarta.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
FieldsModifier and TypeFieldDescriptionprotected OutputStreamstatic final intInitial memory buffer size.static final intMaximum memory buffer size, after this a file is used.protected ByteArrayOutputStreamprotected booleanprotected booleanprotected final jakarta.servlet.ServletOutputStreamprotected booleanHave we stopped buffering to pass writes directly to the output stream.protected Fileprotected PrintWriter -
Constructor Summary
ConstructorsConstructorDescriptionBufferingServletOutputStream(jakarta.servlet.ServletOutputStream outputStream) AServletOutputStreamwrapper that buffers everything untilstopBuffering()is called. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This implementation does nothing, we still want to keep the buffer untilstopBuffering()time.protected voidvoidflush()This implementation does nothing, we still want to keep buffering and not flush.protected OutputStreamgetOutputStream(int len) Finds the proper output stream where we can writelenbytes.booleanbooleanisReady()voidvoidsetWriteListener(jakarta.servlet.WriteListener writeListener) voidWrites any buffered data to the underlyingOutputStreamand from now on don't buffer anymore.static voidTells the givenOutputStreamto stop buffering (if it was).voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class jakarta.servlet.ServletOutputStream
print, print, print, print, print, print, print, println, println, println, println, println, println, println, printlnMethods 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 jakarta.servlet.ServletOutputStream outputStream -
writer
-
memory
-
file
-
tmp
-
-
Constructor Details
-
BufferingServletOutputStream
public BufferingServletOutputStream(jakarta.servlet.ServletOutputStream outputStream) AServletOutputStreamwrapper that buffers everything untilstopBuffering()is called.stopBuffering()MUST be called in afinallystatement 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 writelenbytes.- Throws:
IOException
-
createTempFile
- Throws:
IOException
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
This implementation does nothing, we still want to keep buffering and not flush.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
This implementation does nothing, we still want to keep the buffer untilstopBuffering()time.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
isCommitted
public boolean isCommitted()- Since:
- 11.5
-
resetBuffer
public void resetBuffer()- Since:
- 11.5
-
stopBuffering
Writes any buffered data to the underlyingOutputStreamand from now on don't buffer anymore.- Throws:
IOException
-
stopBuffering
Tells the givenOutputStreamto stop buffering (if it was).- Throws:
IOException
-
isReady
public boolean isReady()- Specified by:
isReadyin classjakarta.servlet.ServletOutputStream
-
setWriteListener
public void setWriteListener(jakarta.servlet.WriteListener writeListener) - Specified by:
setWriteListenerin classjakarta.servlet.ServletOutputStream
-