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 Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 Summary
Modifier 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.OutputStream
nullOutputStream
-
Field Details
-
lock
-
-
Constructor Details
-
EntityOutputStream
public EntityOutputStream()Creates a new entity stream with the maximum in memory threshold of a default value. -
EntityOutputStream
Creates 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
-
EntityOutputStream
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 memoryfilePrefix- the file prefix if a file is created
-
EntityOutputStream
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 memorytmpDir- the temporary directory used for files, can benullto use the defaultfilePrefix- the file prefix if a file is created
-
EntityOutputStream
public 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 memorytmpDir- the temporary directory used for files, can benullto use the defaultfilePrefix- the file prefix if a file is created
-
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
isClosed
public boolean isClosed()Checks if the output stream has been closed.- Returns:
trueif the output stream has been closed, otherwisefalse
-
toInputStream
Creates 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
-
getFile
-
getAndClearMemory
-
checkExported
-
getContentLength
The 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
-