Package org.codice.ddf.platform.util
Class TemporaryFileBackedOutputStream
java.lang.Object
java.io.OutputStream
org.codice.ddf.platform.util.TemporaryFileBackedOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
TemporaryFileBackedOutputStream buffers the written data to memory of a temporary file, and makes
the data available as a ByteSource. This class will make sure the temporary file is deleted when
close() is called. The method asByteSource() should not be called after close() is called.-
Constructor Summary
ConstructorsConstructorDescriptionUse a file threshold size ofDEFAULT_THRESHOLD.TemporaryFileBackedOutputStream(int fileThreshold) -
Method Summary
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
TemporaryFileBackedOutputStream
public TemporaryFileBackedOutputStream(int fileThreshold) - Parameters:
fileThreshold- the number of bytes before the stream should switch to buffering to a file
-
TemporaryFileBackedOutputStream
public TemporaryFileBackedOutputStream()Use a file threshold size ofDEFAULT_THRESHOLD.
-
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
asByteSource
Returns a readableByteSourceview of the data that has been written to this stream. Must not be called afterclose()is called, otherwise anIllegalStateExceptionwill be thrown.- Returns:
- ByteSource of the data
- Throws:
IOException- throws an exception if the stream is closed
-