Class Intercom.RingBuffer.InputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Enclosing class:
    Intercom.RingBuffer

    class Intercom.RingBuffer.InputStream
    extends java.io.InputStream
    implements java.lang.AutoCloseable
    An InputStream to read data from this buffer
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean closedFlag
      Flag to mark a closed stream
    • Constructor Summary

      Constructors 
      Constructor Description
      InputStream()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()
      Gets the number of bytes of data that may be read from the InputStream.
      void close()
      Closes this stream
      int read()
      Read a single byte from the buffer.
      int read​(byte[] buf)
      Read bytes from the stream storing them into buf.
      int read​(byte[] buf, int off, int len)
      Reads len bytes into the byte buffer starting at the off.
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

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

      • closedFlag

        private volatile boolean closedFlag
        Flag to mark a closed stream
    • Constructor Detail

      • InputStream

        InputStream()
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Read a single byte from the buffer. If there is no data in the buffer this code will block until data is available.
        Specified by:
        read in class java.io.InputStream
        Returns:
        the byte read stored in an int
        Throws:
        java.io.IOException - if an attempt is made to read from a closed stream
      • read

        public int read​(byte[] buf,
                        int off,
                        int len)
                 throws java.io.IOException
        Reads len bytes into the byte buffer starting at the off.
        Overrides:
        read in class java.io.InputStream
        Parameters:
        buf - byte buffer to store the data that is read
        off - offset within buffer where first byte is stored
        len - number of bytes to attempt to read
        Returns:
        number of bytes read and stored in buf
        Throws:
        java.io.IOException - if an error occurs reading data
        java.lang.NullPointerException - if buf is null
        java.lang.IndexOutOfBoundsException - if off < 0, len < 0 or len > buf.length - off
      • read

        public int read​(byte[] buf)
                 throws java.io.IOException
        Read bytes from the stream storing them into buf. This is the same as calling read(buf,0,buf.length)
        Overrides:
        read in class java.io.InputStream
        Parameters:
        buf - byte buffer to store read bytes
        Returns:
        number of bytes read and stored in buf
        Throws:
        java.io.IOException - if an error occurs reading a byte
      • available

        public int available()
        Gets the number of bytes of data that may be read from the InputStream.
        Overrides:
        available in class java.io.InputStream
        Returns:
        number of bytes available to be read
      • close

        public void close()
                   throws java.io.IOException
        Closes this stream
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException - if an error occurs