Class FileBackedOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable


    @Beta
    public final class FileBackedOutputStream
    extends OutputStream
    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
    • Constructor Detail

      • FileBackedOutputStream

        public FileBackedOutputStream(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.
        Parameters:
        fileThreshold - the number of bytes before the stream should switch to buffering to a file
      • FileBackedOutputStream

        public FileBackedOutputStream(int fileThreshold,
                                      boolean resetOnFinalize)
        Creates a new instance that uses the given file threshold, and optionally resets the data when the ByteSource returned by asByteSource() is finalized.
        Parameters:
        fileThreshold - the number of bytes before the stream should switch to buffering to a file
        resetOnFinalize - if true, the reset() method will be called when the ByteSource returned by asByteSource() is finalized