Class StreamLink
java.lang.Object
com.codename1.io.link.ByteLink
com.codename1.io.link.StreamLink
- Direct Known Subclasses:
TcpLink
A link over a pair of streams that are already connected, such as a
Bluetooth socket's. Reads wait by polling
available(), so the input
stream must report it; most socket streams do.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFor subclasses that connect inopen()and callsetStreams(InputStream, OutputStream).StreamLink(InputStream in, OutputStream out) Parameters
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Disconnects.booleanisOpen()WhetherByteLink.open()succeeded andByteLink.close()has not been called.voidopen()Connects.intread(byte[] buffer, int offset, int length, int timeout) Reads what has arrived, waiting up totimeoutmilliseconds for the first byte.protected voidsetStreams(InputStream in, OutputStream out) Supplies the streams once connected; for subclasses.voidwrite(byte[] data, int offset, int length) Writes bytes, returning once they are handed to the device.
-
Constructor Details
-
StreamLink
Parameters
-
in: the stream from the device -
out: the stream to the device
-
-
StreamLink
protected StreamLink()For subclasses that connect inopen()and callsetStreams(InputStream, OutputStream).
-
-
Method Details
-
setStreams
Supplies the streams once connected; for subclasses.
Parameters
-
in: the stream from the device -
out: the stream to the device
-
-
open
Description copied from class:ByteLinkConnects. Does nothing when already open.
Throws
IOException: when the device cannot be reached
- Specified by:
openin classByteLink- Throws:
IOException
-
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
-