Class OverflowToDiskOutputStream

java.lang.Object
java.io.OutputStream
org.frankframework.stream.OverflowToDiskOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class OverflowToDiskOutputStream extends OutputStream implements AutoCloseable, Flushable
Writes to an in-memory buffer until it 'overflows', after which a file on disk will be created and the in-memory buffer will be flushed to it.
  • Constructor Summary

    Constructors
    Constructor
    Description
    OverflowToDiskOutputStream(int maxSize, Path tempDirectory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Flushes and closes the OutputStream, clears all resources, does not remove the file if has been created on disk.
    void
    Doesn't do anything if the message is kept in memory
    void
    flush(boolean writeBufferToDisk)
    Doesn't do anything if the message is kept in memory unless parameter writeBufferToDisk is true.
    If the contents was small enough to be kept in memory a ByteArray-message will be returned.
    void
    write(byte[] b, int off, int len)
     
    void
    write(int b)
     

    Methods inherited from class java.io.OutputStream

    nullOutputStream, write

    Methods inherited from class java.lang.Object

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

    • OverflowToDiskOutputStream

      public OverflowToDiskOutputStream(int maxSize, Path tempDirectory) throws IOException
      Throws:
      IOException
  • Method Details

    • write

      public void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • toMessage

      public Message toMessage()
      If the contents was small enough to be kept in memory a ByteArray-message will be returned. If the contents was written to disk a TemporaryMessage will be returned. Once read the buffer will be removed.
      Returns:
      A new Message object representing the contents written to this OutputStream.
    • flush

      public void flush() throws IOException
      Doesn't do anything if the message is kept in memory
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException
    • flush

      public void flush(boolean writeBufferToDisk) throws IOException
      Doesn't do anything if the message is kept in memory unless parameter writeBufferToDisk is true.
      Parameters:
      writeBufferToDisk - Forces the in-memory buffer to be written to disk.
      Throws:
      IOException
    • close

      public void close() throws IOException
      Flushes and closes the OutputStream, clears all resources, does not remove the file if has been created on disk.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException