public class BlaubotConnectionQueueMock extends AbstractBlaubotConnection
writeMockDataToInputStream(byte[])
method. This data can then be retrieved via
the read*() methods like readFully(byte[])
.
If you want to read the data written to this connection via its write*() methods like
write(byte[])
, use the getInputStreamForWrittenConnectionData()
InputStream
to do so.
If you need a pair of connections where one connection writes to the other connections
input stream, use getOtherEndpointConnection(eu.hgross.blaubot.core.IBlaubotDevice)
.Modifier and Type | Field and Description |
---|---|
protected boolean |
connected |
protected java.lang.Object |
disconnnectMonitor |
protected java.util.concurrent.LinkedBlockingQueue<java.lang.Byte> |
inputQueue |
protected java.util.concurrent.LinkedBlockingQueue<java.lang.Byte> |
outputQueue |
connectionListeners
Constructor and Description |
---|
BlaubotConnectionQueueMock(IBlaubotDevice remoteDevice) |
Modifier and Type | Method and Description |
---|---|
void |
disconnect()
Disconnects the connection (if connected), nothing otherwise
|
boolean |
equals(java.lang.Object o) |
java.io.InputStream |
getInputStreamForWrittenConnectionData()
Retrieve an
InputStream to get the data written to this
IBlaubotConnection via it's write*() methods. |
BlaubotConnectionQueueMock |
getOtherEndpointConnection(IBlaubotDevice otherSidesDevice)
Retrieve a
BlaubotConnectionQueueMock object which reads from THIS object
for its read() methods and writes to THIS object. |
IBlaubotDevice |
getRemoteDevice()
The remote device connected to our device.
|
int |
hashCode() |
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.
|
void |
writeMockDataToInputStream(byte[] data)
Write data to the stream that can be retrieved via the
IBlaubotConnection s
read*() methods. |
addConnectionListener, notifyDisconnected, removeConnectionListener
protected java.util.concurrent.LinkedBlockingQueue<java.lang.Byte> inputQueue
protected java.util.concurrent.LinkedBlockingQueue<java.lang.Byte> outputQueue
protected volatile boolean connected
protected java.lang.Object disconnnectMonitor
public BlaubotConnectionQueueMock(IBlaubotDevice remoteDevice)
remoteDevice
- the remote devicepublic BlaubotConnectionQueueMock getOtherEndpointConnection(IBlaubotDevice otherSidesDevice)
BlaubotConnectionQueueMock
object which reads from THIS object
for its read() methods and writes to THIS object.otherSidesDevice
- the other endpoint's IBlaubotDevice
public void writeMockDataToInputStream(byte[] data)
IBlaubotConnection
s
read*() methods.data
- the data to write to the input stream as byte arraypublic java.io.InputStream getInputStreamForWrittenConnectionData()
InputStream
to get the data written to this
IBlaubotConnection
via it's write*() methods.public void disconnect()
IBlaubotConnection
public boolean isConnected()
public IBlaubotDevice getRemoteDevice()
IBlaubotConnection
public void write(int b) throws java.net.SocketTimeoutException, 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.net.SocketTimeoutException
- if the socket timed outjava.io.IOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.public void write(byte[] bytes) throws java.net.SocketTimeoutException, 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.net.SocketTimeoutException
- if the socket timed outjava.io.IOException
- if an I/O error occurs.OutputStream.write(byte[], int, int)
public void write(byte[] bytes, int byteOffset, int byteCount) throws java.net.SocketTimeoutException, 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.bytes
- the data.byteOffset
- the start offset in the data.byteCount
- the number of bytes to write.java.net.SocketTimeoutException
- if the socket timed outjava.io.IOException
- if an I/O error occurs. In particular,
an IOException
is thrown if the output
stream is closed.public int read() throws java.net.SocketTimeoutException, 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.net.SocketTimeoutException
- if the socket timed outjava.io.IOException
- if an I/O error occurs.public int read(byte[] buffer) throws java.net.SocketTimeoutException, 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)
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.net.SocketTimeoutException
- if the socket timed outjava.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.FilterInputStream.in
,
InputStream.read(byte[], int, int)
public int read(byte[] buffer, int byteOffset, int byteCount) throws java.net.SocketTimeoutException, 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.net.SocketTimeoutException
- if the socket timed outjava.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.FilterInputStream.in
,
InputStream.read(byte[], int, int)
public void readFully(byte[] buffer) throws java.net.SocketTimeoutException, 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.net.SocketTimeoutException
- if the socket timed outjava.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.FilterInputStream.in
public void readFully(byte[] buffer, int offset, int byteCount) throws java.net.SocketTimeoutException, 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.net.SocketTimeoutException
- if the socket timed outjava.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.FilterInputStream.in
public boolean equals(java.lang.Object o)
equals
in class AbstractBlaubotConnection
public int hashCode()
hashCode
in class AbstractBlaubotConnection