Package net.bluemind.common.io
Class FileBackedOutputStream
java.lang.Object
java.io.OutputStream
net.bluemind.common.io.FileBackedOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
An
OutputStream that starts buffering to a byte array, but switches
to file buffering once the data reaches a configurable size.
This class is thread-safe.
- Since:
- 1.0
- Author:
- Chris Nokleberg
-
Constructor Summary
ConstructorsConstructorDescriptionFileBackedOutputStream(int fileThreshold, int sizeHint, String filenamePrefix) Creates a new instance that uses the given file threshold, and does not reset the data when theByteSourcereturned byasByteSource()is finalized.FileBackedOutputStream(int fileThreshold, String filenamePrefix) Creates a new instance that uses the given file threshold, and does not reset the data when theByteSourcereturned byasByteSource()is finalized. -
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.io.ByteSourceReturns a readableByteSourceview of the data that has been written to this stream.voidclose()protected voidfinalize()voidflush()voidreset()Callsclose()if not already closed, and then resets this object back to its initial state, for reuse.voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
FileBackedOutputStream
Creates a new instance that uses the given file threshold, and does not reset the data when theByteSourcereturned byasByteSource()is finalized.- Parameters:
fileThreshold- the number of bytes before the stream should switch to buffering to a filefilenamePrefix- name hint for the optional temporary file
-
FileBackedOutputStream
Creates a new instance that uses the given file threshold, and does not reset the data when theByteSourcereturned byasByteSource()is finalized.- Parameters:
fileThreshold- the number of bytes before the stream should switch to buffering to a file. Not smaller than core.io.write-buffersizeHint- if size store is known in advancefilenamePrefix- name hint for the optional temporary file
-
-
Method Details
-
asByteSource
public com.google.common.io.ByteSource asByteSource()Returns a readableByteSourceview of the data that has been written to this stream.- Since:
- 15.0
-
reset
Callsclose()if not already closed, and then resets this object back to its initial state, for reuse. If data was buffered to a file, it will be deleted.- Throws:
IOException- if an I/O error occurred while deleting the file buffer
-
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
-
finalize
-