public interface IBlaubotConnection
Socket
class as well as the convenience readFully
methods known from the DataInputStream
class.
Furthermore an implementation MUST inform it's IBlaubotConnectionListener
s
if this connection disconnects - whether from an intended disconnect or a
connection loss.
A disconnected connection object is not of further interest to blaubot and
should to be thought of as dead and ready for garbage collection.Modifier and Type | Method and Description |
---|---|
void |
addConnectionListener(IBlaubotConnectionListener listener)
Adds a connection listener to get informed if the connection gets closed.
|
void |
disconnect()
Disconnects the connection (if connected), nothing otherwise
|
IBlaubotDevice |
getRemoteDevice()
The remote device connected to our device.
|
boolean |
isConnected() |
int |
read()
Reads the next byte of data from the input stream.
|
int |
read(byte[] buffer)
Reads some number of bytes from the contained input stream and
stores them into the buffer array
b . |
int |
read(byte[] buffer,
int byteOffset,
int byteCount)
Reads up to
len bytes of data from the contained
input stream into an array of bytes. |
void |
readFully(byte[] buffer)
See the general contract of the
readFully
method of DataInput . |
void |
readFully(byte[] buffer,
int offset,
int byteCount)
See the general contract of the
readFully
method of DataInput . |
void |
removeConnectionListener(IBlaubotConnectionListener listener)
Removes a connection listener.
|
void |
write(byte[] bytes)
Writes
b.length bytes from the specified byte array
to this output stream. |
void |
write(byte[] bytes,
int byteOffset,
int byteCount)
Writes
len bytes from the specified byte array
starting at offset off to this output stream. |
void |
write(int b)
Writes the specified byte to this output stream.
|
void disconnect()
boolean isConnected()
void addConnectionListener(IBlaubotConnectionListener listener)
listener
- the listener to addvoid removeConnectionListener(IBlaubotConnectionListener listener)
listener
- the previoulsy attached listenerIBlaubotDevice getRemoteDevice()
void write(int b) throws java.net.SocketTimeoutException, java.io.IOException
write
is that one byte is written
to the output stream. The byte to be written is the eight
low-order bits of the argument b
. The 24
high-order bits of b
are ignored.
Subclasses of OutputStream
must provide an
implementation for this method.b
- the byte
.java.io.IOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.java.net.SocketTimeoutException
- if the socket timed outvoid write(byte[] bytes) throws java.net.SocketTimeoutException, java.io.IOException
b.length
bytes from the specified byte array
to this output stream. The general contract for write(b)
is that it should have exactly the same effect as the call
write(b, 0, b.length)
.bytes
- the data.java.io.IOException
- if an I/O error occurs.java.net.SocketTimeoutException
- if the socket timed outOutputStream.write(byte[], int, int)
void write(byte[] bytes, int byteOffset, int byteCount) throws java.net.SocketTimeoutException, java.io.IOException
len
bytes from the specified byte array
starting at offset off
to this output stream.
The general contract for write(b, off, len)
is that
some of the bytes in the array b
are written to the
output stream in order; element b[off]
is the first
byte written and b[off+len-1]
is the last byte written
by this operation.
The write
method of OutputStream
calls
the write method of one argument on each of the bytes to be
written out. Subclasses are encouraged to override this method and
provide a more efficient implementation.
If b
is null
, a
NullPointerException
is thrown.
If off
is negative, or len
is negative, or
off+len
is greater than the length of the array
b
, then an IndexOutOfBoundsException is thrown.bytes
- the data.byteOffset
- the start offset in the data.byteCount
- the number of bytes to write.java.io.IOException
- if an I/O error occurs. In particular,
an IOException
is thrown if the output
stream is closed.java.net.SocketTimeoutException
- if the socket timed outint read() throws java.net.SocketTimeoutException, java.io.IOException
int
in the range 0
to
255
. If no byte is available because the end of the stream
has been reached, the value -1
is returned. This method
blocks until input data is available, the end of the stream is detected,
or an exception is thrown.
A subclass must provide an implementation of this method.-1
if the end of the
stream is reached.java.io.IOException
- if an I/O error occurs.java.net.SocketTimeoutException
- if the socket timed outint read(byte[] buffer) throws java.net.SocketTimeoutException, java.io.IOException
b
. The number of
bytes actually read is returned as an integer. This method blocks
until input data is available, end of file is detected, or an
exception is thrown.
If b
is null, a NullPointerException
is
thrown. If the length of b
is zero, then no bytes are
read and 0
is returned; otherwise, there is an attempt
to read at least one byte. If no byte is available because the
stream is at end of file, the value -1
is returned;
otherwise, at least one byte is read and stored into b
.
The first byte read is stored into element b[0]
, the
next one into b[1]
, and so on. The number of bytes read
is, at most, equal to the length of b
. Let k
be the number of bytes actually read; these bytes will be stored in
elements b[0]
through b[k-1]
, leaving
elements b[k]
through b[b.length-1]
unaffected.
The read(b)
method has the same effect as:
read(b, 0, b.length)
buffer
- the buffer into which the data is read.-1
if there is no more data because the end
of the stream has been reached.java.io.IOException
- if the first byte cannot be read for any reason
other than end of file, the stream has been closed and the underlying
input stream does not support reading after close, or another I/O
error occurs.java.net.SocketTimeoutException
- if the socket timed outFilterInputStream.in
,
InputStream.read(byte[], int, int)
int read(byte[] buffer, int byteOffset, int byteCount) throws java.net.SocketTimeoutException, java.io.IOException
len
bytes of data from the contained
input stream into an array of bytes. An attempt is made to read
as many as len
bytes, but a smaller number may be read,
possibly zero. The number of bytes actually read is returned as an
integer.
This method blocks until input data is available, end of file is detected, or an exception is thrown.
If len
is zero, then no bytes are read and
0
is returned; otherwise, there is an attempt to read at
least one byte. If no byte is available because the stream is at end of
file, the value -1
is returned; otherwise, at least one
byte is read and stored into b
.
The first byte read is stored into element b[off]
, the
next one into b[off+1]
, and so on. The number of bytes read
is, at most, equal to len
. Let k be the number of
bytes actually read; these bytes will be stored in elements
b[off]
through b[off+
k-1]
,
leaving elements b[off+
k]
through
b[off+len-1]
unaffected.
In every case, elements b[0]
through
b[off]
and elements b[off+len]
through
b[b.length-1]
are unaffected.
buffer
- the buffer into which the data is read.byteOffset
- the start offset in the destination array b
byteCount
- the maximum number of bytes read.-1
if there is no more data because the end
of the stream has been reached.java.lang.NullPointerException
- If b
is null
.java.lang.IndexOutOfBoundsException
- If off
is negative,
len
is negative, or len
is greater than
b.length - off
java.io.IOException
- if the first byte cannot be read for any reason
other than end of file, the stream has been closed and the underlying
input stream does not support reading after close, or another I/O
error occurs.java.net.SocketTimeoutException
- if the socket timed outFilterInputStream.in
,
InputStream.read(byte[], int, int)
void readFully(byte[] buffer) throws java.net.SocketTimeoutException, java.io.IOException
readFully
method of DataInput
.
Bytes
for this operation are read from the contained
input stream.buffer
- the buffer into which the data is read.java.io.EOFException
- if this input stream reaches the end before
reading all the bytes.java.io.IOException
- the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.java.net.SocketTimeoutException
- if the socket timed outFilterInputStream.in
void readFully(byte[] buffer, int offset, int byteCount) throws java.net.SocketTimeoutException, java.io.IOException
readFully
method of DataInput
.
Bytes
for this operation are read from the contained
input stream.buffer
- the buffer into which the data is read.offset
- the start offset of the data.byteCount
- the number of bytes to read.java.io.EOFException
- if this input stream reaches the end before
reading all the bytes.java.io.IOException
- the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.java.net.SocketTimeoutException
- if the socket timed outFilterInputStream.in