public class BlaubotBluetoothConnection extends AbstractBlaubotConnection
IBlaubotConnection
implementation for bluetooth.connectionListeners
Constructor and Description |
---|
BlaubotBluetoothConnection(IBlaubotDevice device,
BluetoothSocket socket) |
Modifier and Type | Method and Description |
---|---|
void |
disconnect()
Disconnects the connection (if connected), nothing otherwise
|
boolean |
equals(java.lang.Object o) |
IBlaubotDevice |
getRemoteDevice()
The remote device connected to our device.
|
int |
hashCode() |
boolean |
isConnected() |
protected void |
notifyDisconnected()
Notifies all registered listeners that this connection is now disconnected
|
int |
read()
Reads the next byte of data from the input stream.
|
int |
read(byte[] b)
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 . |
java.lang.String |
toString() |
void |
write(byte[] bytes)
Writes
b.length bytes from the specified byte array
to this output stream. |
void |
write(byte[] b,
int off,
int len)
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.
|
addConnectionListener, removeConnectionListener
public BlaubotBluetoothConnection(IBlaubotDevice device, BluetoothSocket socket)
protected void notifyDisconnected()
AbstractBlaubotConnection
notifyDisconnected
in class AbstractBlaubotConnection
public void disconnect()
IBlaubotConnection
public int read() throws java.io.IOException
IBlaubotConnection
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 outpublic int read(byte[] b) throws java.io.IOException
IBlaubotConnection
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)
b
- 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)
public int read(byte[] buffer, int byteOffset, int byteCount) throws java.io.IOException
IBlaubotConnection
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.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)
public void write(int b) throws java.io.IOException
IBlaubotConnection
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 outpublic void write(byte[] bytes) throws java.io.IOException
IBlaubotConnection
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)
public void write(byte[] b, int off, int len) throws java.io.IOException
IBlaubotConnection
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.b
- the data.off
- the start offset in the data.len
- 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 outpublic void readFully(byte[] buffer) throws java.io.IOException
IBlaubotConnection
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
public void readFully(byte[] buffer, int offset, int byteCount) throws java.io.IOException
IBlaubotConnection
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
public IBlaubotDevice getRemoteDevice()
IBlaubotConnection
public boolean isConnected()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class AbstractBlaubotConnection
public int hashCode()
hashCode
in class AbstractBlaubotConnection