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
ConstructorDescriptionFileBackedOutputStream
(int fileThreshold, int sizeHint, String filenamePrefix) Creates a new instance that uses the given file threshold, and does not reset the data when theByteSource
returned 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 theByteSource
returned byasByteSource()
is finalized. -
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.io.ByteSource
Returns a readableByteSource
view of the data that has been written to this stream.void
close()
protected void
finalize()
void
flush()
void
reset()
Callsclose()
if not already closed, and then resets this object back to its initial state, for reuse.void
write
(byte[] b) void
write
(byte[] b, int off, int len) void
write
(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 theByteSource
returned 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 theByteSource
returned 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 readableByteSource
view 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:
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
-
finalize
-