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.ServletOutputStreamAServletOutputStreamthat buffers everything untilstopBuffering()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
Fields Modifier and Type Field Description protected OutputStreamfilestatic intINITIALInitial memory buffer size.static intMAXMaximum memory buffer size, after this a file is used.protected ByteArrayOutputStreammemoryprotected booleanneedsCloseprotected booleanneedsFlushprotected javax.servlet.ServletOutputStreamoutputStreamprotected booleanstreamingHave we stopped buffering to pass writes directly to the output stream.protected Filetmpprotected PrintWriterwriter 
- 
Constructor Summary
Constructors Constructor Description BufferingServletOutputStream(javax.servlet.ServletOutputStream outputStream)AServletOutputStreamwrapper that buffers everything untilstopBuffering()is called. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This implementation does nothing, we still want to keep the buffer untilstopBuffering()time.protected voidcreateTempFile()voidflush()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.PrintWritergetWriter()booleanisCommitted()booleanisReady()voidresetBuffer()voidsetWriteListener(javax.servlet.WriteListener writeListener)voidstopBuffering()Writes any buffered data to the underlyingOutputStreamand from now on don't buffer anymore.static voidstopBuffering(OutputStream out)Tells the givenOutputStreamto stop buffering (if it was).voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(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 Detail
- 
INITIAL
public static final int INITIAL
Initial memory buffer size.- See Also:
 - Constant Field Values
 
 
- 
MAX
public static final int MAX
Maximum memory buffer size, after this a file is used.- See Also:
 - Constant Field Values
 
 
- 
streaming
protected boolean streaming
Have 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
protected PrintWriter writer
 
- 
memory
protected ByteArrayOutputStream memory
 
- 
file
protected OutputStream file
 
- 
tmp
protected File tmp
 
 - 
 
- 
Constructor Detail
- 
BufferingServletOutputStream
public BufferingServletOutputStream(javax.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 Detail
- 
getWriter
public PrintWriter getWriter()
 
- 
getOutputStream
protected OutputStream getOutputStream(int len) throws IOException
Finds the proper output stream where we can writelenbytes.- Throws:
 IOException
 
- 
createTempFile
protected void createTempFile() throws IOException- Throws:
 IOException
 
- 
write
public void write(int b) throws IOException- Specified by:
 writein classOutputStream- Throws:
 IOException
 
- 
write
public void write(byte[] b) throws IOException- Overrides:
 writein classOutputStream- Throws:
 IOException
 
- 
write
public void write(byte[] b, int off, int len) throws IOException- Overrides:
 writein classOutputStream- Throws:
 IOException
 
- 
flush
public void flush() throws IOExceptionThis implementation does nothing, we still want to keep buffering and not flush.- Specified by:
 flushin interfaceFlushable- Overrides:
 flushin classOutputStream- Throws:
 IOException
 
- 
close
public void close() throws IOExceptionThis 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
public void stopBuffering() throws IOExceptionWrites any buffered data to the underlyingOutputStreamand from now on don't buffer anymore.- Throws:
 IOException
 
- 
stopBuffering
public static void stopBuffering(OutputStream out) throws IOException
Tells the givenOutputStreamto stop buffering (if it was).- Throws:
 IOException
 
- 
isReady
public boolean isReady()
- Specified by:
 isReadyin classjavax.servlet.ServletOutputStream
 
- 
setWriteListener
public void setWriteListener(javax.servlet.WriteListener writeListener)
- Specified by:
 setWriteListenerin classjavax.servlet.ServletOutputStream
 
 - 
 
 -