Class MemoryLink
java.lang.Object
com.codename1.io.link.ByteLink
com.codename1.io.link.MemoryLink
Two links joined back to back in memory: what one writes the other reads. For tests and for a simulated device a driver can talk to without hardware.
MemoryLink[] pair = MemoryLink.pair();
ByteLink tillSide = pair[0];
ByteLink deviceSide = pair[1]; // answer from a test thread
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Disconnects.booleanisOpen()WhetherByteLink.open()succeeded andByteLink.close()has not been called.voidopen()Connects.static MemoryLink[]pair()Two connected links.intread(byte[] buffer, int offset, int length, int timeout) Reads what has arrived, waiting up totimeoutmilliseconds for the first byte.voidwrite(byte[] data, int offset, int length) Writes bytes, returning once they are handed to the device.
-
Method Details
-
pair
Two connected links.
Returns
the two ends; either may be the device's
-
open
-
isOpen
public boolean isOpen()Description copied from class:ByteLink -
write
Description copied from class:ByteLinkWrites bytes, returning once they are handed to the device.
Parameters
-
data: the buffer -
offset: where to start in it -
length: how many bytes
Throws
IOException: when the link is closed or broken
- Specified by:
writein classByteLink- Throws:
IOException
-
-
read
Description copied from class:ByteLinkReads what has arrived, waiting up to
timeoutmilliseconds for the first byte.Parameters
-
buffer: where to put the bytes -
offset: where to start in it -
length: at most how many bytes -
timeout: how long to wait, in milliseconds
Returns
the number of bytes read; 0 when nothing arrived in time
Throws
IOException: when the link is closed or broken, including when the other side closed it
- Specified by:
readin classByteLink- Throws:
IOException
-
-
close
-