Package org.opendaylight.raft.spi
Class FileBackedOutputStream
java.lang.Object
java.io.OutputStream
org.opendaylight.raft.spi.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
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Callsclose()
if not already closed and, if data was buffered to a file, deletes the file.void
close()
void
flush()
long
getCount()
Returns current byte size.@NonNull SizedStreamSource
Returns a readableSizedStreamSource
view of the data that has been written to this stream.void
write
(byte[] bytes) void
write
(byte[] bytes, int off, int len) void
write
(int value) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
FileBackedOutputStream
Default constructor. Resulting instance uses the given file threshold, and does not reset the data when theSizedStreamSource
returned bytoStreamSource()
is finalized.- Parameters:
config
- theFileBackedOutputStream.Configuration
to use
-
-
Method Details
-
toStreamSource
Returns a readableSizedStreamSource
view 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 SizedStreamSource instance
- Throws:
IOException
- if close fails
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
getCount
public long getCount()Returns current byte size.- Returns:
- current byte size
-
cleanup
public void cleanup()Callsclose()
if not already closed and, if data was buffered to a file, deletes the file.
-