public class BlaubotConnectionMock extends AbstractBlaubotConnection implements IBlaubotConnection
connectionListeners
Constructor and Description |
---|
BlaubotConnectionMock(IBlaubotDevice device,
java.net.Socket socket) |
Modifier and Type | Method and Description |
---|---|
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 |
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.
|
addConnectionListener, equals, hashCode, notifyDisconnected, removeConnectionListener
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addConnectionListener, removeConnectionListener
public BlaubotConnectionMock(IBlaubotDevice device, java.net.Socket socket)
public void disconnect()
IBlaubotConnection
disconnect
in interface IBlaubotConnection
public boolean isConnected()
isConnected
in interface IBlaubotConnection
public IBlaubotDevice getRemoteDevice()
IBlaubotConnection
getRemoteDevice
in interface IBlaubotConnection
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.write
in interface IBlaubotConnection
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)
.write
in interface IBlaubotConnection
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[] bytes, int byteOffset, int byteCount) 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.write
in interface IBlaubotConnection
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 outpublic 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.read
in interface IBlaubotConnection
-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[] buffer) 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)
read
in interface IBlaubotConnection
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)
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.
read
in interface IBlaubotConnection
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 readFully(byte[] buffer) throws java.io.IOException
IBlaubotConnection
readFully
method of DataInput
.
Bytes
for this operation are read from the contained
input stream.readFully
in interface IBlaubotConnection
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.readFully
in interface IBlaubotConnection
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