Class ThresholdingOutputStream
- java.lang.Object
- 
- java.io.OutputStream
- 
- org.apache.tomcat.util.http.fileupload.ThresholdingOutputStream
 
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.io.Flushable,- java.lang.AutoCloseable
 - Direct Known Subclasses:
- DeferredFileOutputStream
 
 public abstract class ThresholdingOutputStream extends java.io.OutputStreamAn output stream which triggers an event when a specified number of bytes of data have been written to it. The event can be used, for example, to throw an exception if a maximum has been reached, or to switch the underlying stream type when the threshold is exceeded.This class overrides all OutputStreammethods. However, these overrides ultimately call the corresponding methods in the underlying output stream implementation.NOTE: This implementation may trigger the event before the threshold is actually reached, since it triggers when a pending write operation would cause the threshold to be exceeded. 
- 
- 
Constructor SummaryConstructors Constructor Description ThresholdingOutputStream(int threshold)Constructs an instance of this class which will trigger an event at the specified threshold.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckThreshold(int count)Checks to see if writing the specified number of bytes would cause the configured threshold to be exceeded.voidclose()Closes this output stream and releases any system resources associated with this stream.voidflush()Flushes this output stream and forces any buffered output bytes to be written out.protected abstract java.io.OutputStreamgetStream()Returns the underlying output stream, to which the correspondingOutputStreammethods in this class will ultimately delegate.booleanisThresholdExceeded()Determines whether or not the configured threshold has been exceeded for this output stream.protected abstract voidthresholdReached()Indicates that the configured threshold has been reached, and that a subclass should take whatever action necessary on this event.voidwrite(byte[] b)Writesb.lengthbytes from the specified byte array to this output stream.voidwrite(byte[] b, int off, int len)Writeslenbytes from the specified byte array starting at offsetoffto this output stream.voidwrite(int b)Writes the specified byte to this output stream.
 
- 
- 
- 
Method Detail- 
writepublic void write(int b) throws java.io.IOExceptionWrites the specified byte to this output stream.- Specified by:
- writein class- java.io.OutputStream
- Parameters:
- b- The byte to be written.
- Throws:
- java.io.IOException- if an error occurs.
 
 - 
writepublic void write(byte[] b) throws java.io.IOExceptionWritesb.lengthbytes from the specified byte array to this output stream.- Overrides:
- writein class- java.io.OutputStream
- Parameters:
- b- The array of bytes to be written.
- Throws:
- java.io.IOException- if an error occurs.
 
 - 
writepublic void write(byte[] b, int off, int len) throws java.io.IOExceptionWriteslenbytes from the specified byte array starting at offsetoffto this output stream.- Overrides:
- writein class- java.io.OutputStream
- Parameters:
- b- The byte array from which the data will be written.
- off- The start offset in the byte array.
- len- The number of bytes to write.
- Throws:
- java.io.IOException- if an error occurs.
 
 - 
flushpublic void flush() throws java.io.IOExceptionFlushes this output stream and forces any buffered output bytes to be written out.- Specified by:
- flushin interface- java.io.Flushable
- Overrides:
- flushin class- java.io.OutputStream
- Throws:
- java.io.IOException- if an error occurs.
 
 - 
closepublic void close() throws java.io.IOExceptionCloses this output stream and releases any system resources associated with this stream.- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
- Overrides:
- closein class- java.io.OutputStream
- Throws:
- java.io.IOException- if an error occurs.
 
 - 
isThresholdExceededpublic boolean isThresholdExceeded() Determines whether or not the configured threshold has been exceeded for this output stream.- Returns:
- trueif the threshold has been reached;- falseotherwise.
 
 - 
checkThresholdprotected void checkThreshold(int count) throws java.io.IOExceptionChecks to see if writing the specified number of bytes would cause the configured threshold to be exceeded. If so, triggers an event to allow a concrete implementation to take action on this.- Parameters:
- count- The number of bytes about to be written to the underlying output stream.
- Throws:
- java.io.IOException- if an error occurs.
 
 - 
getStreamprotected abstract java.io.OutputStream getStream() throws java.io.IOExceptionReturns the underlying output stream, to which the correspondingOutputStreammethods in this class will ultimately delegate.- Returns:
- The underlying output stream.
- Throws:
- java.io.IOException- if an error occurs.
 
 - 
thresholdReachedprotected abstract void thresholdReached() throws java.io.IOExceptionIndicates that the configured threshold has been reached, and that a subclass should take whatever action necessary on this event. This may include changing the underlying output stream.- Throws:
- java.io.IOException- if an error occurs.
 
 
- 
 
-