Module com.pi4j
Package com.pi4j.io

Interface IODataReader

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default InputStream getInputStream()
      Get an InputStream to read data from the I/O device.
      default InputStream in()
      Get an InputStream to read data from the I/O device.
      int read()
      Read a single raw byte (8-bit) value from the I/O device.
      default int read​(byte[] buffer)
      Read data from the I/O device into the provided byte array starting at the zero index (first byte) and up to the available space in the buffer/array.
      default int read​(byte[] buffer, int length)
      Read data from the I/O device into the provided byte array starting at the zero index (first byte) and up to the specified data length (number of bytes).
      int read​(byte[] buffer, int offset, int length)
      Read data from the I/O device into the provided byte array at the given offset and up to the specified data length (number of bytes).
      default int read​(char[] buffer)
      Read ASCII data from the I/O device into the provided character array starting at the zero index (first byte) and up to the available space in the buffer/array.
      default int read​(char[] buffer, int length)
      Read ASCII data from the I/O device into the provided character array starting with the first byte in the array up to the provided length.
      default int read​(char[] buffer, int offset, int length)
      Read ASCII character data from the I/O device into the provided character array at the given offset and up to the specified data length (number of characters).
      default int read​(ByteBuffer buffer)
      Read data from the I/O device into the provided byte buffer starting with the first byte in the array up to available space remaining in the buffer.
      default int read​(ByteBuffer buffer, int length)
      Read data from the I/O device into the provided byte buffer starting with the first byte in the array up to the provided length.
      default int read​(ByteBuffer buffer, int offset, int length)
      Read data from the I/O device into the provided byte buffer at the given offset and up to the specified data length (number of bytes).
      default int read​(CharBuffer buffer)
      Read ASCII character data from the I/O device into the provided character buffer starting at the zero index (first position) up to available space remaining in the buffer.
      default int read​(CharBuffer buffer, int length)
      Read ASCII character data from the I/O device into the provided character buffer starting at the zero index (first position) up to the specified data length (number of characters).
      default int read​(CharBuffer buffer, int offset, int length)
      Read ASCII character data from the I/O device into the provided character buffer at the given offset and up to the specified data length (number of characters).
      default int read​(Charset charset, char[] buffer)
      Read data from the I/O device into the provided character array starting at the zero index (first byte) and up to the available space in the buffer/array.
      default int read​(Charset charset, char[] buffer, int length)
      Read data from the I/O device into the provided character array starting with the first byte in the array up to the provided length.
      default int read​(Charset charset, char[] buffer, int offset, int length)
      Read character data from the I/O device into the provided character array at the given offset and up to the specified data length (number of characters).
      default int read​(Charset charset, CharBuffer buffer)
      Read character data from the I/O device into the provided character buffer starting at the zero index (first position) up to available space remaining in the buffer.
      default int read​(Charset charset, CharBuffer buffer, int length)
      Read character data from the I/O device into the provided character buffer starting at the zero index (first position) up to the specified data length (number of characters).
      default int read​(Charset charset, CharBuffer buffer, int offset, int length)
      Read character data from the I/O device into the provided character buffer at the given offset and up to the specified data length (number of characters).
      default byte readByte()
      Read a single raw byte (8-bit) value from the I/O device.
      default ByteBuffer readByteBuffer​(int length)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new ByteBuffer.
      default ByteBuffer readByteBuffer​(int offset, int length)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new ByteBuffer.
      default char[] readCharArray​(int numberOfBytes)
      Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new character buffer.
      default char[] readCharArray​(int offset, int numberOfBytes)
      Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new character array.
      default char[] readCharArray​(Charset charset, int numberOfBytes)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new character array.
      default char[] readCharArray​(Charset charset, int offset, int numberOfBytes)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new character array.
      default CharBuffer readCharBuffer​(int numberOfBytes)
      Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new CharBuffer instance.
      default CharBuffer readCharBuffer​(int offset, int numberOfBytes)
      Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new CharBuffer instance.
      default CharBuffer readCharBuffer​(Charset charset, int numberOfBytes)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new CharBuffer instance.
      default CharBuffer readCharBuffer​(Charset charset, int offset, int numberOfBytes)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new CharBuffer instance.
      default byte[] readNBytes​(int length)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new byte array.
      default byte[] readNBytes​(int offset, int length)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new byte array.
      default String readString​(int numberOfBytes)
      Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new String instance.
      default String readString​(int offset, int numberOfBytes)
      Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new String instance.
      default String readString​(Charset charset, int numberOfBytes)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new String instance.
      default String readString​(Charset charset, int offset, int numberOfBytes)
      Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new String instance.
    • Method Detail

      • read

        int read()
        Read a single raw byte (8-bit) value from the I/O device.
        Returns:
        If successful, a zero or positive integer value representing the byte value (0-255) is returned. If a read error was encountered, a negative error code may be returned.
      • read

        int read​(byte[] buffer,
                 int offset,
                 int length)
        Read data from the I/O device into the provided byte array at the given offset and up to the specified data length (number of bytes).
        Parameters:
        buffer - the byte array/buffer the read data will be copied/inserted into
        offset - the offset index in the data buffer to start copying read data
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(byte[] buffer,
                         int length)
        Read data from the I/O device into the provided byte array starting at the zero index (first byte) and up to the specified data length (number of bytes).
        Parameters:
        buffer - the byte array/buffer the read data will be copied/inserted into
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(byte[] buffer)
        Read data from the I/O device into the provided byte array starting at the zero index (first byte) and up to the available space in the buffer/array.
        Parameters:
        buffer - the byte array/buffer the read data will be copied/inserted into
        Returns:
        If successful, return the number of bytes read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(ByteBuffer buffer,
                         int offset,
                         int length)
        Read data from the I/O device into the provided byte buffer at the given offset and up to the specified data length (number of bytes). NOTE: The buffer's internal position tracking is not used but rather only the explicit offset and length provided. If the requested length is greater than the buffers capacity (minus offset) then the specified length will be ignored and this function will only write the number of bytes up to the buffers' available space.
        Parameters:
        buffer - the byte buffer the read data will be copied/inserted into
        offset - the offset index in the data buffer to start copying read data
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(ByteBuffer buffer,
                         int length)
        Read data from the I/O device into the provided byte buffer starting with the first byte in the array up to the provided length. NOTE: The data bytes read from the I/O device are copied/ inserted into the byte buffer starting at the current position index up to the length requested or up to the buffer's remaining limit; whichever is is lower . If the buffer's current position is already at the buffer's limit, then we will automatically rewind the buffer to begin writing data from the zero position up to the buffer's limit.
        Parameters:
        buffer - the byte buffer the read data will be copied/inserted into
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(ByteBuffer buffer)
        Read data from the I/O device into the provided byte buffer starting with the first byte in the array up to available space remaining in the buffer. NOTE: The data bytes read from the I/O device are copied/ inserted into the byte buffer starting at the current position index up to the buffer's remaining limit. If the buffer's current position is already at the buffer's limit, then we will automatically rewind the buffer to begin writing data from the zero position up to the buffer's limit.
        Parameters:
        buffer - byte buffer of data where data read from the I/O device will be copied (from current position to limit)
        Returns:
        If successful, return the number of bytes read from the I2C device register; else on a read error, return a negative error code.
      • read

        default int read​(Charset charset,
                         char[] buffer,
                         int offset,
                         int length)
        Read character data from the I/O device into the provided character array at the given offset and up to the specified data length (number of characters). Specify the character set to be used to decode the bytes into chars.
        Parameters:
        charset - character set to use for byte decoding
        buffer - the character array the read data will be copied/inserted into
        offset - the offset index in the character array to start copying read data
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(Charset charset,
                         char[] buffer,
                         int length)
        Read data from the I/O device into the provided character array starting with the first byte in the array up to the provided length. Specify the character set to be used to decode the bytes into chars.
        Parameters:
        charset - character set to use for byte decoding
        buffer - the character array the read data will be copied/inserted into
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(Charset charset,
                         char[] buffer)
        Read data from the I/O device into the provided character array starting at the zero index (first byte) and up to the available space in the buffer/array. Specify the character set to be used to decode the bytes into chars.
        Parameters:
        charset - character set to use for byte decoding
        buffer - the character array the read data will be copied/inserted into
        Returns:
        If successful, return the number of bytes read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(char[] buffer,
                         int offset,
                         int length)
        Read ASCII character data from the I/O device into the provided character array at the given offset and up to the specified data length (number of characters). ASCII is the internal character set used to decode the bytes into chars.
        Parameters:
        buffer - the character array the read data will be copied/inserted into
        offset - the offset index in the character array to start copying read data
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(char[] buffer,
                         int length)
        Read ASCII data from the I/O device into the provided character array starting with the first byte in the array up to the provided length. ASCII is the internal character set used to decode the bytes into chars.
        Parameters:
        buffer - the character array the read data will be copied/inserted into
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(char[] buffer)
        Read ASCII data from the I/O device into the provided character array starting at the zero index (first byte) and up to the available space in the buffer/array. ASCII is the internal character set used to decode the bytes into chars.
        Parameters:
        buffer - the character array the read data will be copied/inserted into
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(Charset charset,
                         CharBuffer buffer,
                         int offset,
                         int length)
        Read character data from the I/O device into the provided character buffer at the given offset and up to the specified data length (number of characters). Specify the character set to be used to decode the bytes into chars. NOTE: The buffer's internal position tracking is not used but rather only the explicit offset and length provided. If the requested length is greater than the buffers capacity (minus offset) then the specified length will be ignored and this function will only write the number of characters up to the buffers' available space.
        Parameters:
        charset - character set to use for byte decoding
        buffer - the character array the read data will be copied/inserted into
        offset - the offset index in the character buffer to start copying read data
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(Charset charset,
                         CharBuffer buffer,
                         int length)
        Read character data from the I/O device into the provided character buffer starting at the zero index (first position) up to the specified data length (number of characters). Specify the character set to be used to decode the bytes into chars. NOTE: The data characters read and decoded from the I/O device are copied/inserted into the character buffer starting at the current position index up to the length requested or up to the buffer's remaining limit; whichever is is lower . If the buffer's current position is already at the buffer's limit, then we will automatically rewind the buffer to begin writing data from the zero position up to the buffer's limit.
        Parameters:
        charset - character set to use for byte decoding
        buffer - the character array the read data will be copied/inserted into
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(Charset charset,
                         CharBuffer buffer)
        Read character data from the I/O device into the provided character buffer starting at the zero index (first position) up to available space remaining in the buffer. Specify the character set to be used to decode the bytes into chars. NOTE: The data characters read from the I/O device are copied/ inserted into the character buffer starting at the current position index up to the buffer's remaining limit. If the buffer's current position is already at the buffer's limit, then we will automatically rewind the buffer to begin writing data from the zero position up to the buffer's limit.
        Parameters:
        charset - character set to use for byte decoding
        buffer - the character array the read data will be copied/inserted into
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(CharBuffer buffer,
                         int offset,
                         int length)
        Read ASCII character data from the I/O device into the provided character buffer at the given offset and up to the specified data length (number of characters). ASCII is the internal character set used to decode the bytes into chars. NOTE: The buffer's internal position tracking is not used but rather only the explicit offset and length provided. If the requested length is greater than the buffers capacity (minus offset) then the specified length will be ignored and this function will only write the number of characters up to the buffers' available space.
        Parameters:
        buffer - the character array the read data will be copied/inserted into
        offset - the offset index in the character buffer to start copying read data
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(CharBuffer buffer,
                         int length)
        Read ASCII character data from the I/O device into the provided character buffer starting at the zero index (first position) up to the specified data length (number of characters). ASCII is the internal character set used to decode the bytes into chars. NOTE: The data characters read and decoded from the I/O device are copied/inserted into the character buffer starting at the current position index up to the length requested or up to the buffer's remaining limit; whichever is is lower . If the buffer's current position is already at the buffer's limit, then we will automatically rewind the buffer to begin writing data from the zero position up to the buffer's limit.
        Parameters:
        buffer - the character array the read data will be copied/inserted into
        length - the number of bytes to read
        Returns:
        If successful, return the number of bytes (not characters) read from the I/O device; else on a read error, return a negative error code.
      • read

        default int read​(CharBuffer buffer)
        Read ASCII character data from the I/O device into the provided character buffer starting at the zero index (first position) up to available space remaining in the buffer. ASCII is the internal character set used to decode the bytes into chars. NOTE: The data characters read from the I/O device are copied/ inserted into the character buffer starting at the current position index up to the buffer's remaining limit. If the buffer's current position is already at the buffer's limit, then we will automatically rewind the buffer to begin writing data from the zero position up to the buffer's limit.
        Specified by:
        read in interface Readable
      • readByte

        default byte readByte()
        Read a single raw byte (8-bit) value from the I/O device.
        Returns:
        The 8-bit byte value
      • readNBytes

        default byte[] readNBytes​(int offset,
                                  int length)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new byte array. The 'offset' parameter allows you to skip a certain number of bytes in the read data an excludes them from the returned data byte array. Note: the resulting byte array size will be at most the 'length' - 'offset'.
        Parameters:
        offset - the offset index in the data read to start copying read data
        length - the number of bytes to read
        Returns:
        a new byte array containing the data bytes read from the I/O device.
        Throws:
        IllegalArgumentException - An java.lang.IllegalArgumentException is thrown if one of the method parameters are invalid.
      • readNBytes

        default byte[] readNBytes​(int length)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new byte array.
        Parameters:
        length - the number of bytes to read
        Returns:
        a new byte array containing the data bytes read from the I/O device.
      • readByteBuffer

        default ByteBuffer readByteBuffer​(int offset,
                                          int length)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new ByteBuffer. The 'offset' parameter allows you to skip a certain number of bytes in the read data and excludes them from the returned data ByteBuffer. Note: the resulting byte buffer size will be at most the 'length' - 'offset'.
        Parameters:
        offset - the offset index in the data read to start copying read data
        length - the number of bytes to read
        Returns:
        a new ByteBuffer containing the data bytes read from the I/O device.
        Throws:
        IllegalArgumentException - An java.lang.IllegalArgumentException is thrown if one of the method parameters are invalid.
      • readByteBuffer

        default ByteBuffer readByteBuffer​(int length)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new ByteBuffer. The 'offset' parameter allows you to skip a certain number of bytes in the read data and excludes them from the returned data ByteBuffer.
        Parameters:
        length - the number of bytes to read
        Returns:
        a new ByteBuffer containing the data bytes read from the I/O device.
        Throws:
        IllegalArgumentException - An java.lang.IllegalArgumentException is thrown if one of the method parameters are invalid.
      • readCharArray

        default char[] readCharArray​(Charset charset,
                                     int offset,
                                     int numberOfBytes)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new character array. The 'offset' parameter allows you to skip a certain number of bytes in the read data and excludes them from the returned character array.
        Parameters:
        charset - character set to use for byte decoding
        offset - the offset index in the raw bytes read to start from
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character array containing the decoded character data read from the I/O device.
        Throws:
        IllegalArgumentException - An java.lang.IllegalArgumentException is thrown if one of the method parameters are invalid.
      • readCharArray

        default char[] readCharArray​(Charset charset,
                                     int numberOfBytes)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new character array. ASCII is the internal character set used to decode the bytes into chars.
        Parameters:
        charset - character set to use for byte decoding
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character array containing the decoded character data read from the I/O device.
      • readCharArray

        default char[] readCharArray​(int offset,
                                     int numberOfBytes)
        Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new character array. The 'offset' parameter allows you to skip a certain number of bytes in the read data and excludes them from the returned character buffer. ASCII is the internal character set used to decode the bytes into chars.
        Parameters:
        offset - the offset index in the raw bytes read to start from
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character array containing the decoded character data read from the I/O device.
      • readCharArray

        default char[] readCharArray​(int numberOfBytes)
        Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new character buffer.
        Parameters:
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character array containing the decoded character data read from the I/O device.
      • readCharBuffer

        default CharBuffer readCharBuffer​(Charset charset,
                                          int offset,
                                          int numberOfBytes)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new CharBuffer instance. The 'offset' parameter allows you to skip a certain number of bytes in the read data and excludes them from the returned character buffer.
        Parameters:
        charset - character set to use for byte decoding
        offset - the offset index in the raw bytes read to start from
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character buffer (CharBuffer) containing the decoded character data read from the I/O device.
        Throws:
        IllegalArgumentException - An java.lang.IllegalArgumentException is thrown if one of the method parameters are invalid.
      • readCharBuffer

        default CharBuffer readCharBuffer​(Charset charset,
                                          int numberOfBytes)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new CharBuffer instance.
        Parameters:
        charset - character set to use for byte decoding
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character buffer (CharBuffer) containing the decoded character data read from the I/O device.
      • readCharBuffer

        default CharBuffer readCharBuffer​(int offset,
                                          int numberOfBytes)
        Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new CharBuffer instance. The 'offset' parameter allows you to skip a certain number of bytes in the read data and excludes them from the returned character buffer. ASCII is the internal character set used to decode the bytes into chars.
        Parameters:
        offset - the offset index in the raw bytes read to start from
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character buffer (CharBuffer) containing the decoded character data read from the I/O device.
      • readCharBuffer

        default CharBuffer readCharBuffer​(int numberOfBytes)
        Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new CharBuffer instance. ASCII is the internal character set used to decode the bytes into chars.
        Parameters:
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character buffer (CharBuffer) containing the decoded character data read from the I/O device.
      • readString

        default String readString​(Charset charset,
                                  int offset,
                                  int numberOfBytes)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new String instance. The 'offset' parameter allows you to skip a certain number of bytes in the read data and excludes them from the returned string.
        Parameters:
        charset - character set to use for byte decoding
        offset - the offset index in the raw bytes read to start from
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character buffer (CharBuffer) containing the decoded character data read from the I/O device.
      • readString

        default String readString​(Charset charset,
                                  int numberOfBytes)
        Read data from the I/O device up to a specified length (number of bytes) and return the data read in a new String instance.
        Parameters:
        charset - character set to use for byte decoding
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character buffer (CharBuffer) containing the decoded character data read from the I/O device.
      • readString

        default String readString​(int offset,
                                  int numberOfBytes)
        Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new String instance. The 'offset' parameter allows you to skip a certain number of bytes in the read data and excludes them from the returned string. ASCII is the internal character set used to decode the bytes into chars.
        Parameters:
        offset - the offset index in the raw bytes read to start from
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character buffer (CharBuffer) containing the decoded character data read from the I/O device.
      • readString

        default String readString​(int numberOfBytes)
        Read ASCII data from the I/O device up to a specified length (number of bytes) and return the data read in a new String instance. ASCII is the internal character set used to decode the bytes into chars.
        Parameters:
        numberOfBytes - the number of bytes to read (not number of characters)
        Returns:
        a new character buffer (CharBuffer) containing the decoded character data read from the I/O device.
      • getInputStream

        default InputStream getInputStream()
        Get an InputStream to read data from the I/O device.
        Returns:
        InputStream instance
      • in

        default InputStream in()
        Get an InputStream to read data from the I/O device.
        Returns:
        InputStream instance