Class TimeoutOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, java.lang.Runnable

    public class TimeoutOutputStream
    extends java.io.FilterOutputStream
    implements java.lang.Runnable
    An output stream that self-closes if the specified timeout elapses between writes.
    • Field Summary

      • Fields inherited from class java.io.FilterOutputStream

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeoutOutputStream​(java.io.OutputStream out, long timeout)
      Create a TimeoutOutputStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void run()  
      void write​(byte[] buf)  
      void write​(byte[] buf, int offset, int length)  
      void write​(int b)  
      • Methods inherited from class java.io.FilterOutputStream

        flush
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • TimeoutOutputStream

        public TimeoutOutputStream​(java.io.OutputStream out,
                                   long timeout)
        Create a TimeoutOutputStream.
        Parameters:
        out - the wrapped output stream.
        timeout - the timeout in milliseconds between writes. If this timeout completes, the underlying stream will be closed.
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Overrides:
        write in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] buf)
                   throws java.io.IOException
        Overrides:
        write in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] buf,
                          int offset,
                          int length)
                   throws java.io.IOException
        Overrides:
        write in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable