public class SerialInputStream
extends java.io.InputStream
SerialPort
to provide
InputStream
functionality. This stream
also provides support for performing blocking reads
with timeouts.
SerialPort
instance. Do not create multiple streams for the
same serial port unless you implement your own
synchronization.Constructor and Description |
---|
SerialInputStream(jssc.SerialPort sp)
Instantiates a SerialInputStream for the given
SerialPort
Do not create multiple streams for the same serial port
unless you implement your own synchronization. |
Modifier and Type | Method and Description |
---|---|
int |
available() |
int |
blockingRead(byte[] buf)
Blocks until buf.length bytes are read, an error occurs, or the default timeout is hit (if specified).
|
int |
blockingRead(byte[] buf,
int timeout)
The same contract as
blockingRead(byte[]) except
overrides this stream's default timeout with the given one. |
int |
blockingRead(byte[] buf,
int offset,
int length)
Blocks until length bytes are read, an error occurs, or the default timeout is hit (if specified).
|
int |
blockingRead(byte[] buf,
int offset,
int length,
int timeout)
The same contract as
blockingRead(byte[], int, int) except
overrides this stream's default timeout with the given one. |
int |
read()
Reads the next byte from the port.
|
int |
read(byte[] buf)
Non-blocking read of up to buf.length bytes from the stream.
|
int |
read(byte[] buf,
int offset,
int length)
Non-blocking read of up to length bytes from the stream.
|
int |
read(int timeout)
The same contract as
read() , except overrides
this stream's default timeout with the given
timeout in milliseconds. |
void |
setTimeout(int time)
Set the default timeout (ms) of this SerialInputStream.
|
public SerialInputStream(jssc.SerialPort sp)
SerialPort
Do not create multiple streams for the same serial port
unless you implement your own synchronization.sp
- The serial port to stream.public void setTimeout(int time)
read()
, #blockingRead(int[])
,
and #blockingRead(int[], int, int)
The default timeout can be 'unset' by setting it to 0.time
- The timeout in milliseconds.public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(int timeout) throws java.io.IOException
read()
, except overrides
this stream's default timeout with the given
timeout in milliseconds.timeout
- The timeout in milliseconds.java.io.IOException
- On serial port error or timeoutpublic int read(byte[] buf) throws java.io.IOException
read
in class java.io.InputStream
buf
- The buffer to fill.java.io.IOException
- on error.public int read(byte[] buf, int offset, int length) throws java.io.IOException
read
in class java.io.InputStream
buf
- The buffer to fill.offset
- The offset into the buffer to start copying data.length
- The maximum number of bytes to read.java.io.IOException
- on error.public int blockingRead(byte[] buf) throws java.io.IOException
buf
- The buffer to fill with data.java.io.IOException
- On error or timeout.public int blockingRead(byte[] buf, int timeout) throws java.io.IOException
blockingRead(byte[])
except
overrides this stream's default timeout with the given one.buf
- The buffer to fill.timeout
- The timeout in milliseconds.java.io.IOException
- On error or timeout.public int blockingRead(byte[] buf, int offset, int length) throws java.io.IOException
read(byte[], int, int)
would.buf
- The buffer to fill.offset
- The offset in buffer to save the data.length
- The number of bytes to read.java.io.IOException
- on error or timeout.public int blockingRead(byte[] buf, int offset, int length, int timeout) throws java.io.IOException
blockingRead(byte[], int, int)
except
overrides this stream's default timeout with the given one.buf
- The buffer to fill.offset
- Offset in the buffer to start saving data.length
- The number of bytes to read.timeout
- The timeout in milliseconds.java.io.IOException
- On error or timeout.public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
Copyright © 2019. All rights reserved.