Class TimeoutOutputStream

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

    class TimeoutOutputStream
    extends java.io.OutputStream
    An OutputStream that wraps the Socket's OutputStream and uses the ScheduledExecutorService to schedule a task to close the socket (aborting the write) if the timeout expires.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] b1  
      private java.io.OutputStream os  
      private java.util.concurrent.ScheduledExecutorService ses  
      private int timeout  
      private java.util.concurrent.Callable<java.lang.Object> timeoutTask  
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeoutOutputStream​(java.io.OutputStream os0, java.util.concurrent.ScheduledExecutorService ses, int timeout)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void write​(byte[] bs, int off, int len)  
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        flush, nullOutputStream, write
      • Methods inherited from class java.lang.Object

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

      • os

        private final java.io.OutputStream os
      • ses

        private final java.util.concurrent.ScheduledExecutorService ses
      • timeoutTask

        private final java.util.concurrent.Callable<java.lang.Object> timeoutTask
      • timeout

        private final int timeout
      • b1

        private byte[] b1
    • Constructor Detail

      • TimeoutOutputStream

        public TimeoutOutputStream​(java.io.OutputStream os0,
                                   java.util.concurrent.ScheduledExecutorService ses,
                                   int timeout)
                            throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • write

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

        public void write​(byte[] bs,
                          int off,
                          int len)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        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.OutputStream
        Throws:
        java.io.IOException