public interface IConnectionInterface
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.
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.
|
InputStream getInputStream()
getOutputStream()
,
InputStream
OutputStream getOutputStream()
getInputStream()
,
OutputStream
boolean isOpen()
void open() throws InterfaceInUseException, InvalidInterfaceException, InvalidConfigurationException, PermissionDeniedException
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.close()
,
isOpen()
int readData(byte[] data) throws IOException
data
- The byte array to store the read data.IOException
- if there is any problem reading from the input stream.NullPointerException
- if data == null
.readData(byte[], int, int)
int readData(byte[] data, int offset, int length) throws IOException
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.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
.readData(byte[])
void writeData(byte[] data) throws IOException
data
- The data to be written in the connection interface.IOException
- if there is any problem writing to the output stream.NullPointerException
- if data == null
.writeData(byte[], int, int)
void writeData(byte[] data, int offset, int length) throws IOException
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.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
.writeData(byte[])
© Copyright 2014–2014 Digi International Inc. All rights reserved.