Package jadex.commons

Class ListenableStream

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

    public class ListenableStream
    extends java.io.OutputStream
    A stream that can be listened to.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] buffer
      The buffered bytes.
      protected int len
      The currently used length of the buffer.
      protected java.util.List listeners
      The listeners.
      protected byte[] newline
      The code(s) of the newline character.
      protected java.io.OutputStream out
      The super output stream.
      protected java.lang.String type
      The event type to be generated.
    • Constructor Summary

      Constructors 
      Constructor Description
      ListenableStream​(java.io.OutputStream out, java.lang.String type)
      Create a new stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addLineListener​(IChangeListener listener)
      Add a line listener.
      void close()
      Close the streams.
      void flush()
      Flush the streams.
      protected void generateEvent()
      Generate an event for a line and flush the buffer.
      void removeLineListener​(IChangeListener listener)
      Remove a line listener.
      void write​(int b)
      Write a byte to the stream.
      • Methods inherited from class java.io.OutputStream

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

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

      • out

        protected java.io.OutputStream out
        The super output stream.
      • type

        protected java.lang.String type
        The event type to be generated.
      • buffer

        protected byte[] buffer
        The buffered bytes.
      • len

        protected int len
        The currently used length of the buffer.
      • listeners

        protected java.util.List listeners
        The listeners.
      • newline

        protected byte[] newline
        The code(s) of the newline character.
    • Constructor Detail

      • ListenableStream

        public ListenableStream​(java.io.OutputStream out,
                                java.lang.String type)
        Create a new stream.
        Parameters:
        out - The output stream.
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Write a byte to the stream.
        Specified by:
        write in class java.io.OutputStream
        Parameters:
        b - The byte.
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Close the streams.
        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
      • flush

        public void flush()
                   throws java.io.IOException
        Flush the streams.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException
      • addLineListener

        public void addLineListener​(IChangeListener listener)
        Add a line listener.
      • removeLineListener

        public void removeLineListener​(IChangeListener listener)
        Remove a line listener.
      • generateEvent

        protected void generateEvent()
        Generate an event for a line and flush the buffer.