Package org.jboss.resteasy.spi
Class EntityOutputStream
java.lang.Object
java.io.OutputStream
org.jboss.resteasy.spi.EntityOutputStream
- All Implemented Interfaces:
- Closeable,- Flushable,- AutoCloseable
A stream used for entities. This may buffer, given the threshold value, in memory or be written to a file. The file
 should be deleted after the 
resulting input stream is no longer referenced.
 
 Please note that if toInputStream() is not invoked the file must be manually deleted.
 
- Author:
- James R. Perkins
- 
Nested Class SummaryNested Classes
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a new entity stream with the maximum in memory threshold of a default value.EntityOutputStream(Threshold memoryThreshold) Creates a new entity stream with the maximum in memory threshold of the supplied value.EntityOutputStream(Threshold memoryThreshold, Path tmpDir, Supplier<String> filePrefix) Creates a new entity stream with the maximum in memory threshold and a file prefix to be used if the stream needs to be written to a file due to the threshold.EntityOutputStream(Threshold memoryThreshold, Path tmpDir, Threshold fileThreshold, Supplier<String> filePrefix) Creates a new entity stream with the maximum in memory threshold and a file prefix to be used if the stream needs to be written to a file due to the threshold.EntityOutputStream(Threshold memoryThreshold, Supplier<String> filePrefix) Creates a new entity stream with the maximum in memory threshold and a file prefix to be used if the stream needs to be written to a file due to the threshold.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidcheckExported(Supplier<? extends RuntimeException> errorMessage) voidclose()voidflush()protected byte[]Returns the data in memory ifgetFile()returnsnull.longThe length of the length of the content written.protected PathgetFile()Returns the file if one was written to.booleanisClosed()Checks if the output stream has been closed.Creates an input stream from this output stream.voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStreamnullOutputStream
- 
Field Details- 
lock
 
- 
- 
Constructor Details- 
EntityOutputStreampublic EntityOutputStream()Creates a new entity stream with the maximum in memory threshold of a default value.
- 
EntityOutputStreamCreates a new entity stream with the maximum in memory threshold of the supplied value.- Parameters:
- memoryThreshold- the maximum number of bytes to hold in memory
 
- 
EntityOutputStreamCreates a new entity stream with the maximum in memory threshold and a file prefix to be used if the stream needs to be written to a file due to the threshold.- Parameters:
- memoryThreshold- the maximum number of bytes to hold in memory
- filePrefix- the file prefix if a file is created
 
- 
EntityOutputStreamCreates a new entity stream with the maximum in memory threshold and a file prefix to be used if the stream needs to be written to a file due to the threshold.- Parameters:
- memoryThreshold- the maximum number of bytes to hold in memory
- tmpDir- the temporary directory used for files, can be- nullto use the default
- filePrefix- the file prefix if a file is created
 
- 
EntityOutputStreampublic EntityOutputStream(Threshold memoryThreshold, Path tmpDir, Threshold fileThreshold, Supplier<String> filePrefix) Creates a new entity stream with the maximum in memory threshold and a file prefix to be used if the stream needs to be written to a file due to the threshold.- Parameters:
- memoryThreshold- the maximum number of bytes to hold in memory
- tmpDir- the temporary directory used for files, can be- nullto use the default
- filePrefix- the file prefix if a file is created
 
 
- 
- 
Method Details- 
write- Specified by:
- writein class- OutputStream
- Throws:
- IOException
 
- 
write- Overrides:
- writein class- OutputStream
- Throws:
- IOException
 
- 
write- Overrides:
- writein class- OutputStream
- Throws:
- IOException
 
- 
flush- Specified by:
- flushin interface- Flushable
- Overrides:
- flushin class- OutputStream
- Throws:
- IOException
 
- 
close- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- OutputStream
- Throws:
- IOException
 
- 
isClosedpublic boolean isClosed()Checks if the output stream has been closed.- Returns:
- trueif the output stream has been closed, otherwise- false
 
- 
toInputStreamCreates an input stream from this output stream.Note that when invoking this method close()is invoked first.- Returns:
- an input stream for reading the output
- Throws:
- IOException- if an error occurs creating the input stream
 
- 
getFileReturns the file if one was written to. If this is in memory, this method will returnnull.Important: You must use the lockwhen accessing this method.- Returns:
- the file, if it exists, or null
 
- 
getAndClearMemoryprotected byte[] getAndClearMemory()Returns the data in memory ifgetFile()returnsnull.Important: You must use the lockwhen accessing this method.- Returns:
- the data in memory or an empty array
 
- 
checkExported
- 
getContentLengthThe length of the length of the content written.- Returns:
- the length of the content written
- Throws:
- IOException- if there is an error determining the length of the content
 
 
-