Class FileBackedOutputStream

java.lang.Object
java.io.OutputStream
net.bluemind.common.io.FileBackedOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

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
Author:
Chris Nokleberg
  • Constructor Summary

    Constructors
    Constructor
    Description
    FileBackedOutputStream(int fileThreshold, int sizeHint, String filenamePrefix)
    Creates a new instance that uses the given file threshold, and does not reset the data when the ByteSource returned by asByteSource() is finalized.
    FileBackedOutputStream(int fileThreshold, String filenamePrefix)
    Creates a new instance that uses the given file threshold, and does not reset the data when the ByteSource returned by asByteSource() is finalized.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.google.common.io.ByteSource
    Returns a readable ByteSource view of the data that has been written to this stream.
    void
     
    protected void
     
    void
     
    void
    Calls close() 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

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FileBackedOutputStream

      public FileBackedOutputStream(int fileThreshold, String filenamePrefix)
      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
      filenamePrefix - name hint for the optional temporary file
    • FileBackedOutputStream

      public FileBackedOutputStream(int fileThreshold, int sizeHint, String filenamePrefix)
      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. Not smaller than core.io.write-buffer
      sizeHint - if size store is known in advance
      filenamePrefix - name hint for the optional temporary file
  • Method Details