Class MonitorOutputStream

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Direct Known Subclasses:
DefaultFileContent.FileContentOutputStream, FtpFileObject.FtpOutputStream, SftpFileObject.SftpOutputStream

public class MonitorOutputStream extends BufferedOutputStream
An OutputStream that provides buffering and end-of-stream monitoring.
  • Field Details

  • Constructor Details

    • MonitorOutputStream

      public MonitorOutputStream(OutputStream out)
      Constructs a MonitorOutputStream from the passed OutputStream
      Parameters:
      out - The output stream to wrap.
    • MonitorOutputStream

      public MonitorOutputStream(OutputStream out, int bufferSize)
      Constructs a MonitorOutputStream from the passed OutputStream and with the specified buffer size
      Parameters:
      out - The output stream to wrap.
      bufferSize - The buffer size to use.
      Since:
      2.4
  • Method Details

    • close

      public void close() throws IOException
      Closes this output stream.

      This makes sure the buffers are flushed, close the output stream and it will call onClose() and re-throw last exception from any of the three.

      This does nothing if the stream is closed already.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterOutputStream
      Throws:
      IOException - if an IO error occurs.
    • write

      public void write(int b) throws IOException
      Overrides:
      write in class BufferedOutputStream
      Parameters:
      b - The character to write.
      Throws:
      IOException - if an error occurs.
      Since:
      2.0
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Overrides:
      write in class BufferedOutputStream
      Parameters:
      b - The byte array.
      off - The offset into the array.
      len - The number of bytes to write.
      Throws:
      IOException - if an error occurs.
      Since:
      2.0
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class BufferedOutputStream
      Throws:
      IOException - if an error occurs.
      Since:
      2.0
    • write

      public void write(byte[] b) throws IOException
      Overrides:
      write in class FilterOutputStream
      Parameters:
      b - The byte array.
      Throws:
      IOException - if an error occurs.
      Since:
      2.0
    • assertOpen

      protected void assertOpen() throws FileSystemException
      Check if file is still open.

      This is a workaround for an oddity with Java's BufferedOutputStream where you can write to even if the stream has been closed.

      Throws:
      FileSystemException - if already closed.
      Since:
      2.0
    • onClose

      protected void onClose() throws IOException
      Called after this stream is closed.

      This implementation does nothing.

      Throws:
      IOException - if an error occurs.