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
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates 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 void
checkExported
(Supplier<? extends RuntimeException> errorMessage) void
close()
void
flush()
protected byte[]
Returns the data in memory ifgetFile()
returnsnull
.long
The length of the length of the content written.protected Path
getFile()
Returns the file if one was written to.boolean
isClosed()
Checks if the output stream has been closed.Creates an input stream from this output stream.void
write
(byte[] b) void
write
(byte[] b, int off, int len) void
write
(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 benull
to 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 benull
to use the defaultfilePrefix
- the file prefix if a file is created
-
-
Method Details
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
isClosed
public boolean isClosed()Checks if the output stream has been closed.- Returns:
true
if 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
-