Class StreamConnection<T>

    • Constructor Detail

      • StreamConnection

        public StreamConnection​(DataFormat<T> format)
        Creates a new connection instance.
        Parameters:
        format - the data format to use for communication
      • StreamConnection

        public StreamConnection​(DataFormat<T> format,
                                java.util.function.Consumer<StreamConnection<T>> onConnectionOpened,
                                java.util.function.BiConsumer<StreamConnection<T>,​java.lang.Exception> onIOError)
        Creates a new connection instance.
        Parameters:
        onConnectionOpened - task to be executed if the selected COM-port has been successfully opened
        onIOError - task to be executed if an io error has occurred
    • Method Detail

      • setOnConnectionOpened

        public StreamConnection<T> setOnConnectionOpened​(java.util.function.Consumer<StreamConnection<T>> onConnectionOpened)
        Specifies the action to be performed if the connection has been opened.
        Parameters:
        onConnectionOpened - the action to be performed if the connection has been opened
      • open

        public void open​(java.io.InputStream inputStream,
                         java.io.OutputStream outputStream)
        Opens the specified port and connects to it.
        Parameters:
        inputStream - input stream to be used by this connection
        outputStream - output stream to be used by this connection
      • setStreams

        public StreamConnection<T> setStreams​(java.io.InputStream inputStream,
                                              java.io.OutputStream outputStream)
        Sets the configuration to use for connecting to a port.
        Parameters:
        inputStream - the input stream to be used by this connection
        outputStream - the output stream to be used by this connection
        Returns:
        this connection
      • writeData

        public void writeData​(T msg)
                       throws java.io.IOException
        Description copied from interface: DataConnection
        Writes the specified raw message to the output stream.
        Specified by:
        writeData in interface DataConnection<T,​StreamConnection<T>>
        Parameters:
        msg - the message to send
        Throws:
        java.io.IOException - if an i/o error occurs during message sending
      • close

        public void close()
        Closes the connection to the specified port.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface DataConnection<T,​StreamConnection<T>>
      • isOpen

        public boolean isOpen()
        Description copied from interface: DataConnection
        Indicates whether this connection is open.
        Specified by:
        isOpen in interface DataConnection<T,​StreamConnection<T>>
        Returns:
        true if this connection is currently open; false otherwise