public class BackedFileOutputStream extends OutputStream
OutputStream that starts buffering to a byte array, but switches to file buffering
once the data reaches a configurable size.
Temporary files created by this stream may live in the local filesystem until either:
reset() is called (removing the data in this stream and deleting the file), or...
asByteSource() view) is finalized during
garbage collection, AND this stream was not constructed with the 1-arg constructor
This class is thread-safe.
| 构造器和说明 |
|---|
BackedFileOutputStream(int fileThreshold)
Creates a new instance that uses the given file threshold, and does
not reset the data when the
ByteSource returned by
asByteSource() is finalized. |
BackedFileOutputStream(int fileThreshold,
boolean resetOnFinalize,
File parentDirectory)
Creates a new instance that uses the given file threshold, and
optionally resets the data when the
ByteSource returned
by asByteSource() is finalized. |
| 限定符和类型 | 方法和说明 |
|---|---|
com.google.common.io.ByteSource |
asByteSource()
Returns a readable
ByteSource view of the data that has been
written to this stream. |
void |
close() |
void |
flush() |
File |
getFile()
Returns the file holding the data (possibly null).
|
void |
reset()
Calls
close() if not already closed, and then resets this
object back to its initial state, for reuse. |
long |
size() |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
void |
writeTo(OutputStream out) |
public BackedFileOutputStream(int fileThreshold)
ByteSource returned by
asByteSource() is finalized.fileThreshold - the number of bytes before the stream should
switch to buffering to a filepublic BackedFileOutputStream(int fileThreshold,
boolean resetOnFinalize,
File parentDirectory)
ByteSource returned
by asByteSource() is finalized.fileThreshold - the number of bytes before the stream should
switch to buffering to a fileresetOnFinalize - if true, the reset() method will
be called when the ByteSource returned by asByteSource() is finalizedpublic File getFile()
public com.google.common.io.ByteSource asByteSource()
ByteSource view of the data that has been
written to this stream.public void reset()
throws IOException
close() 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.IOException - if an I/O error occurred while deleting the file bufferpublic void write(int b)
throws IOException
write 在类中 OutputStreamIOExceptionpublic void write(byte[] b)
throws IOException
write 在类中 OutputStreamIOExceptionpublic void write(byte[] b,
int off,
int len)
throws IOException
write 在类中 OutputStreamIOExceptionpublic void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableclose 在类中 OutputStreamIOExceptionpublic void flush()
throws IOException
flush 在接口中 Flushableflush 在类中 OutputStreamIOExceptionpublic long size()
public void writeTo(OutputStream out) throws IOException
IOExceptionCopyright © 2023 The Apache Software Foundation. All rights reserved.