Class FileBackedOutputStream
java.lang.Object
java.io.OutputStream
org.opendaylight.controller.cluster.io.FileBackedOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
- Direct Known Subclasses:
SharedFileBackedOutputStream
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.- Author:
- Thomas Pantelis
-
Constructor Summary
ConstructorsConstructorDescriptionFileBackedOutputStream(int fileThreshold, @Nullable String fileDirectory) 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 TypeMethodDescription@NonNull ByteSourceReturns a readableByteSourceview of the data that has been written to this stream.voidcleanup()Callsclose()if not already closed and, if data was buffered to a file, deletes the file.voidclose()voidflush()longgetCount()voidwrite(byte[] bytes) voidwrite(byte[] bytes, int off, int len) voidwrite(int value) 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 filefileDirectory- the directory in which to create the file if needed. If null, the default temp file location is used.
-
-
Method Details
-
asByteSource
Returns a readableByteSourceview of the data that has been written to this stream. This stream is closed and further attempts to write to it will result in an IOException.- Returns:
- a ByteSource instance
- Throws:
IOException- if close fails
-
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
-
getCount
public long getCount() -
cleanup
public void cleanup()Callsclose()if not already closed and, if data was buffered to a file, deletes the file.
-