Class TimeoutInputStream

    • Constructor Detail

      • TimeoutInputStream

        public TimeoutInputStream​(InputStream aInputStream,
                                  long aTimeoutInMs)
        Constructs a TimeoutInputStream decorating an InputStream with additional timeout functionality.
        Parameters:
        aInputStream - The InputStream to be decorated.
        aTimeoutInMs - The default timeout for read operations not explicitly called with a timeout argument. With a value of -1 timeout handling is disabled (blocking mode).
      • TimeoutInputStream

        public TimeoutInputStream​(InputStream aInputStream,
                                  Object aMonitor)
        Constructs a TimeoutInputStream decorating an InputStream with additional timeout functionality.
        Parameters:
        aInputStream - The InputStream to be decorated.
        aMonitor - The monitor to use when waiting the poll loop time. This is useful required available data can be read before the poll loop time expires. E.g. an underlying system might call Object.notifyAll() on the monitor as soon as it received new data.
      • TimeoutInputStream

        public TimeoutInputStream​(InputStream aInputStream,
                                  long aTimeoutInMs,
                                  Object aMonitor)
        Constructs a TimeoutInputStream decorating an InputStream with additional timeout functionality.
        Parameters:
        aInputStream - The InputStream to be decorated.
        aTimeoutInMs - The default timeout for read operations not explicitly called with a timeout argument. With a value of -1 timeout handling is disabled (blocking mode).
        aMonitor - The monitor to use when waiting the poll loop time. This is useful required available data can be read before the poll loop time expires. E.g. an underlying system might call Object.notifyAll() on the monitor as soon as it received new data.
    • Method Detail

      • mark

        public void mark​(int readlimit)
        Overrides:
        mark in class InputStream
      • read

        public int read​(long aTimeoutInMs)
                 throws IOException
        Enriches the read() method with a timeout. This methods blocks till the result is available and can be returned or the timeout is reached. A timeout of -1 disables the timeout.
        Parameters:
        aTimeoutInMs - The timeout in milliseconds to wait for the next byte available.With a value of -1 timeout handling is disabled (blocking mode).
        Returns:
        the int
        Throws:
        IOException - thrown in case of according I/O related problems or an expired timeout.
      • read

        public int read​(byte[] b,
                        int off,
                        int len,
                        long aTimeoutInMs)
                 throws IOException
        Enriches the read(byte[], int, int) method with a timeout. This methods blocks till the result is available and can be returned or the timeout is reached. A timeout of -1 disables the timeout.
        Parameters:
        b - The byte array into which the data is read.
        off - The start offset in b at which the data is written.
        len - The maximum number of bytes to read.
        aTimeoutInMs - The timeout in milliseconds to wait for the next byte available.With a value of -1 timeout handling is disabled (blocking mode).
        Returns:
        the int
        Throws:
        IOException - thrown in case of according I/O related problems or an expired timeout.
      • read

        public int read​(byte[] b,
                        long aTimeoutInMs)
                 throws IOException
        Enriches the read(byte[]) method with a timeout. This methods blocks till the result is available and can be returned or the timeout is reached. A timeout of -1 disables the timeout. Calling this method has the same effect a read(b, 0, b.length), so we try to read as many bytes as the buffer's length is.
        Parameters:
        b - The byte array into which the data is read.
        aTimeoutInMs - The timeout in milliseconds to wait for the next byte available.With a value of -1 timeout handling is disabled (blocking mode).
        Returns:
        the int
        Throws:
        IOException - thrown in case of according I/O related problems or an expired timeout.
      • readNBytes

        public int readNBytes​(byte[] b,
                              int off,
                              int len,
                              long aTimeoutInMs)
                       throws IOException
        Enriches the readNBytes(byte[], int, int) method with a timeout. This methods blocks till the result is available and can be returned or the timeout is reached. A timeout of -1 disables the timeout.
        Parameters:
        b - the byte array into which the data is read
        off - the start offset in b at which the data is written
        len - the maximum number of bytes to read
        aTimeoutInMs - The timeout in milliseconds.
        Returns:
        the actual number of bytes read into the buffer
        Throws:
        IOException - if an I/O error occurs
        NullPointerException - if b is null
        IndexOutOfBoundsException - If off is negative, len is negative, or len is greater than b.length - off
      • getReadTimeoutInMs

        public long getReadTimeoutInMs()
        Specified by:
        getReadTimeoutInMs in interface org.refcodes.mixin.ReadTimeoutInMsAccessor