Class AbstractSerialDataReader
- java.lang.Object
-
- com.pi4j.io.serial.impl.AbstractSerialDataReader
-
- All Implemented Interfaces:
SerialDataReader
public abstract class AbstractSerialDataReader extends Object implements SerialDataReader
-
-
Constructor Summary
Constructors Constructor Description AbstractSerialDataReader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract intavailable()Get the number of bytes available in the serial data receive buffer.voiddiscardData()discard/drain all available bytes from the serial port/device.abstract byte[]read()Reads all available bytes bytes from the port/serial device.abstract byte[]read(int length)Reads a length of bytes from the port/serial device.voidread(int length, OutputStream stream)Reads a length bytes from the serial port/device into a provided OutputStream.voidread(int length, ByteBuffer buffer)Reads a length bytes from the serial port/device into a provided ByteBuffer.CharBufferread(int length, Charset charset)Reads a length of bytes from the port/serial device and returns a CharBuffer from the decoded bytes.voidread(int length, Charset charset, Writer writer)Reads a length bytes from the serial port/device into a provided Writer.voidread(int length, Collection<ByteBuffer> collection)Reads a length of bytes from the serial port/device into a provided collection of ByteBuffer objects.voidread(OutputStream stream)Reads all available bytes from the serial device into a provided OutputStream.voidread(ByteBuffer buffer)Reads all available bytes from the serial device into a provided ByteBuffer.CharBufferread(Charset charset)Reads all available bytes from the port/serial device and returns a CharBuffer from the decoded bytes.voidread(Charset charset, Writer writer)Reads all available bytes from the serial port/device into a provided Writer.voidread(Collection<ByteBuffer> collection)Reads all available bytes from the serial port/device into a provided collection of ByteBuffer objects.
-
-
-
Method Detail
-
available
public abstract int available() throws IllegalStateException, IOExceptionGet the number of bytes available in the serial data receive buffer.
- Specified by:
availablein interfaceSerialDataReader- Returns:
- Returns number of bytes available.
- Throws:
IllegalStateExceptionIOException
-
read
public abstract byte[] read() throws IllegalStateException, IOExceptionReads all available bytes bytes from the port/serial device.
- Specified by:
readin interfaceSerialDataReader- Returns:
- Returns a byte array with the data read from the serial port.
- Throws:
IllegalStateExceptionIOException
-
discardData
public void discardData() throws IllegalStateException, IOExceptiondiscard/drain all available bytes from the serial port/device.
- Specified by:
discardDatain interfaceSerialDataReader- Throws:
IllegalStateExceptionIOException
-
read
public abstract byte[] read(int length) throws IllegalStateException, IOExceptionReads a length of bytes from the port/serial device.
- Specified by:
readin interfaceSerialDataReader- Parameters:
length- The number of bytes to get from the serial port/device. This number must not be higher than the number of available bytes.- Returns:
- Returns a byte array with the data read from the serial port.
- Throws:
IllegalStateExceptionIOException
-
read
public void read(ByteBuffer buffer) throws IllegalStateException, IOException
Reads all available bytes from the serial device into a provided ByteBuffer.
- Specified by:
readin interfaceSerialDataReader- Parameters:
buffer- The ByteBuffer object to write to.- Throws:
IllegalStateExceptionIOException
-
read
public void read(int length, ByteBuffer buffer) throws IllegalStateException, IOExceptionReads a length bytes from the serial port/device into a provided ByteBuffer.
- Specified by:
readin interfaceSerialDataReader- Parameters:
length- The number of bytes to get from the serial port/device. This number must not be higher than the number of available bytes.buffer- The ByteBuffer object to write to.- Throws:
IllegalStateExceptionIOException
-
read
public void read(OutputStream stream) throws IllegalStateException, IOException
Reads all available bytes from the serial device into a provided OutputStream.
- Specified by:
readin interfaceSerialDataReader- Parameters:
stream- The OutputStream object to write to.- Throws:
IllegalStateExceptionIOException
-
read
public void read(int length, OutputStream stream) throws IllegalStateException, IOExceptionReads a length bytes from the serial port/device into a provided OutputStream.
- Specified by:
readin interfaceSerialDataReader- Parameters:
length- The number of bytes to get from the serial port/device. This number must not be higher than the number of available bytes.stream- The OutputStream object to write to.- Throws:
IllegalStateExceptionIOException
-
read
public void read(Collection<ByteBuffer> collection) throws IllegalStateException, IOException
Reads all available bytes from the serial port/device into a provided collection of ByteBuffer objects.
- Specified by:
readin interfaceSerialDataReader- Parameters:
collection- The collection of CharSequence objects to append to.- Throws:
IllegalStateExceptionIOException
-
read
public void read(int length, Collection<ByteBuffer> collection) throws IllegalStateException, IOExceptionReads a length of bytes from the serial port/device into a provided collection of ByteBuffer objects.
- Specified by:
readin interfaceSerialDataReader- Parameters:
length- The number of bytes to get from the serial port/device. This number must not be higher than the number of available bytes.collection- The collection of CharSequence objects to append to.- Throws:
IllegalStateExceptionIOException
-
read
public CharBuffer read(Charset charset) throws IllegalStateException, IOException
Reads all available bytes from the port/serial device and returns a CharBuffer from the decoded bytes.
- Specified by:
readin interfaceSerialDataReader- Parameters:
charset- The character set to use for encoding/decoding bytes to/from text characters- Returns:
- Returns a character set with the data read from the serial port.
- Throws:
IllegalStateExceptionIOException
-
read
public CharBuffer read(int length, Charset charset) throws IllegalStateException, IOException
Reads a length of bytes from the port/serial device and returns a CharBuffer from the decoded bytes.
- Specified by:
readin interfaceSerialDataReader- Parameters:
length- The number of bytes to get from the serial port/device. This number must not be higher than the number of available bytes.charset- The character set to use for encoding/decoding bytes to/from text characters- Returns:
- Returns a character set with the data read from the serial port.
- Throws:
IllegalStateExceptionIOException
-
read
public void read(Charset charset, Writer writer) throws IllegalStateException, IOException
Reads all available bytes from the serial port/device into a provided Writer.
- Specified by:
readin interfaceSerialDataReader- Parameters:
charset- The character set to use for encoding/decoding bytes to/from text characterswriter- The Writer object to write to.- Throws:
IllegalStateExceptionIOException
-
read
public void read(int length, Charset charset, Writer writer) throws IllegalStateException, IOExceptionReads a length bytes from the serial port/device into a provided Writer.
- Specified by:
readin interfaceSerialDataReader- Parameters:
length- The number of bytes to get from the serial port/device. This number must not be higher than the number of available bytes.charset- The character set to use for encoding/decoding bytes to/from text characterswriter- The Writer object to write to.- Throws:
IllegalStateExceptionIOException
-
-