com.digi.xbee.api.connection

## Interface IConnectionInterface

- All Known Implementing Classes:
    AbstractSerialPort, SerialPortRxTx

      public interface IConnectionInterface

  This interface represents a protocol independent connection with an XBee device.

  The connection can be made using sockets, serial port, etc.

  As an important point, the class implementing this interface must call `this.notify()` whenever new data is available to read. Not doing this will make the `DataReader` class to wait forever for new data.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Attempts to close the connection interface.
    `InputStream` | `getInputStream()` Returns the connection interface input stream to read data from.
    `OutputStream` | `getOutputStream()` Returns the connection interface output stream to write data to.
    `boolean` | `isOpen()` Returns whether the connection interface is open or not.
    `void` | `open()` Attempts to open the connection interface.
    `int` | `readData(byte[] data)` Reads data from the connection interface and stores it in the provided byte array returning the number of read bytes.
    `int` | `readData(byte[] data, int offset, int length)` Reads the given number of bytes at the given offset from the connection interface and stores it in the provided byte array returning the number of read bytes.
    `void` | `writeData(byte[] data)` Writes the given data in the connection interface.
    `void` | `writeData(byte[] data, int offset, int length)` Writes the given data in the connection interface.

- - ### Method Detail

    - #### close

          void close()

      Attempts to close the connection interface.
      See Also:
        `isOpen()`, `open()`

    - #### getInputStream

          InputStream getInputStream()

      Returns the connection interface input stream to read data from.
      Returns:
        The connection interface input stream to read data from.
      See Also:
        `getOutputStream()`, `InputStream`

    - #### getOutputStream

          OutputStream getOutputStream()

      Returns the connection interface output stream to write data to.
      Returns:
        The connection interface output stream to write data to.
      See Also:
        `getInputStream()`, `OutputStream`

    - #### isOpen

          boolean isOpen()

      Returns whether the connection interface is open or not.
      Returns:
        `true` if the connection interface is open, `false` otherwise.
      See Also:
        `close()`, `open()`

    - #### open

          void open()
                    throws InterfaceInUseException,
                           InvalidInterfaceException,
                           InvalidConfigurationException,
                           PermissionDeniedException

      Attempts to open the connection interface.
      Throws:
        `InterfaceInUseException` - if the interface is in use by other application(s).
        `InvalidConfigurationException` - if the configuration used to open the interface is invalid.
        `InvalidInterfaceException` - if the interface is invalid or does not exist.
        `PermissionDeniedException` - if you do not have permissions to access the interface.
      See Also:
        `close()`, `isOpen()`

    - #### readData

          int readData(byte[] data)
                       throws IOException

      Reads data from the connection interface and stores it in the provided byte array returning the number of read bytes.
      Parameters:
        `data` - The byte array to store the read data.
      Returns:
        The number of bytes read.
      Throws:
        `IOException` - if there is any problem reading from the input stream.
        `NullPointerException` - if `data == null`.
      See Also:
        `readData(byte[], int, int)`

    - #### readData

          int readData(byte[] data,
                     int offset,
                     int length)
                       throws IOException

      Reads the given number of bytes at the given offset from the connection interface and stores it in the provided byte array returning the number of read bytes.
      Parameters:
        `data` - The byte array to store the read data.
        `offset` - The start offset in data array at which the data is written.
        `length` - Maximum number of bytes to read.
      Returns:
        The number of bytes read.
      Throws:
        `IllegalArgumentException` - if `offset < 0` or if `length < 1` or if `offset >= data.length` or if `offset + length > data.length`.
        `IOException` - if there is any problem reading from the input stream.
        `NullPointerException` - if `data == null`.
      See Also:
        `readData(byte[])`

    - #### writeData

          void writeData(byte[] data)
                         throws IOException

      Writes the given data in the connection interface.
      Parameters:
        `data` - The data to be written in the connection interface.
      Throws:
        `IOException` - if there is any problem writing to the output stream.
        `NullPointerException` - if `data == null`.
      See Also:
        `writeData(byte[], int, int)`

    - #### writeData

          void writeData(byte[] data,
                       int offset,
                       int length)
                         throws IOException

      Writes the given data in the connection interface.
      Parameters:
        `data` - The data to be written in the connection interface.
        `offset` - The start offset in the data to write.
        `length` - The number of bytes to write.
      Throws:
        `IllegalArgumentException` - if `offset < 0` or if `length < 1` or if `offset >= data.length` or if `offset + length > data.length`.
        `IOException` - if there is any problem writing to the output stream.
        `NullPointerException` - if `data == null`.
      See Also:
        `writeData(byte[])`

© Copyright 2014–2014 Digi International Inc. All rights reserved.