public final class SerialComInByteStream extends InputStream
Represents an input stream of bytes which is received from serial port.
Application design should make sure that the port is not closed if there exist a read method which is blocked (waiting for data byte) on the same port.
Advance applications may fine tune the timing behavior using fineTuneReadBehaviour() API defined in SerialComManager class.
| Constructor and Description |
|---|
SerialComInByteStream(SerialComManager scm,
SerialComPortHandleInfo portHandleInfo,
long handle,
SerialComManager.SMODE streamMode)
Construct and allocates a new SerialComInByteStream object with given details.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns an estimate of the minimum number of bytes that can be read from this input stream
without blocking by the next invocation of a method for this input stream.
|
void |
close()
This method releases the InputStream object associated with the operating handle.
|
void |
mark(int a)
SCM does not support mark and reset of input stream.
|
boolean |
markSupported()
SCM does not support mark and reset of input stream.
|
int |
read()
Reads the next byte of data from the input stream.
|
int |
read(byte[] b)
Reads some number of bytes from the input stream and stores them into the buffer array b.
|
int |
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from the input stream into an array of bytes.
|
void |
reset()
SCM does not support reset.
|
long |
skip(long number)
SCM does not support skip.
|
public SerialComInByteStream(SerialComManager scm, SerialComPortHandleInfo portHandleInfo, long handle, SerialComManager.SMODE streamMode) throws SerialComException
Construct and allocates a new SerialComInByteStream object with given details.
scm - instance of SerialComManager class with which this stream will associate itself.handle - handle of the serial port on which to read data bytes.streamMode - indicates blocking or non-blocking behavior of stream.SerialComException - if the input stream can not be prepared for the specified read behavior.public int available()
throws IOException
Returns an estimate of the minimum number of bytes that can be read from this input stream without blocking by the next invocation of a method for this input stream.
available in class InputStreamIOException - if an I/O error occurs or if stream has been closed already.public void close()
throws IOException
This method releases the InputStream object associated with the operating handle.
To actually close the port closeComPort() method should be used.
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOException - if an I/O error occurs or if stream has been closed already.public void mark(int a)
SCM does not support mark and reset of input stream. If required, it can be developed at application level.
mark in class InputStreampublic boolean markSupported()
SCM does not support mark and reset of input stream. If required, it can be developed at application level.
markSupported in class InputStreampublic int read()
throws IOException
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255.
For blocking mode this method returns the next byte of data. For non-blocking mode this method returns the next byte of data if it is available otherwise -1 if there is no data at serial port.
read in class InputStreamIOException - if an I/O error occurs or if stream has been closed already.public int read(byte[] b)
throws IOException
Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available or an exception 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.
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 for class SerialComInByteStream has the same effect as : read(b, 0, b.length).
read in class InputStreamb - the buffer into which the data is read.IOException - if an I/O error occurs or if input stream has been closed.NullPointerException - if b is null.public int read(byte[] b,
int off,
int len)
throws IOException
Reads up to len bytes of data from the 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. The number of bytes actually read is returned as an integer.
If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte 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.
For blocking mode, this method blocks until input data is available or an exception is thrown. For non-blocking mode it attempts to read data, returns data byte if read. It will return -1 if there is no data at serial port.
read in class InputStreamb - the buffer into which the data is read.off - the start offset in array b at which the data is written.len - the maximum number of bytes to read.IOException - if an I/O error occurs or if input stream has been closed.NullPointerException - if b is null.IllegalArgumentException - if data is not a byte type array.IndexOutOfBoundsException - if off is negative, len is negative, or len is greater
than b.length - off.public void reset()
throws IOException
SCM does not support reset. If required, it can be developed at application level.
reset in class InputStreamIOExceptionpublic long skip(long number)
SCM does not support skip. If required, it can be developed at application level.
skip in class InputStreamnumber - of bytes to skip.Copyright © 2016. All rights reserved.