@ThreadSafe public class FileBackedOutputStream extends OutputStream
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.Constructor and Description |
---|
FileBackedOutputStream(int fileThreshold,
String fileDirectory)
Creates a new instance that uses the given file threshold, and does not reset the data when the
ByteSource returned by asByteSource() is finalized. |
Modifier and Type | Method and Description |
---|---|
com.google.common.io.ByteSource |
asByteSource()
Returns a readable
ByteSource view of the data that has been written to this stream. |
void |
cleanup()
Calls
close() if not already closed and, if data was buffered to a file, deletes the file. |
void |
close() |
void |
flush() |
long |
getCount() |
void |
write(byte[] bytes) |
void |
write(byte[] bytes,
int off,
int len) |
void |
write(int value) |
public FileBackedOutputStream(int fileThreshold, @Nullable String fileDirectory)
ByteSource
returned by asByteSource()
is finalized.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.@Nonnull public com.google.common.io.ByteSource asByteSource() throws IOException
ByteSource
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.IOException
- if close failspublic void write(int value) throws IOException
write
in class OutputStream
IOException
public void write(byte[] bytes) throws IOException
write
in class OutputStream
IOException
public void write(byte[] bytes, int off, int len) throws IOException
write
in class OutputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public long getCount()
public void cleanup()
close()
if not already closed and, if data was buffered to a file, deletes the file.Copyright © 2019 OpenDaylight. All rights reserved.