Class Stream

Direct Known Subclasses:
Serial

public class Stream extends PrintFormatter
Port of the Arduino Stream API
  • Constructor Details

    • Stream

      public Stream()
  • Method Details

    • write

      public void write(String writeMe)
      Specified by:
      write in class PrintFormatter
    • write

      public void write(byte[] writeMe, int pos, int len)
    • write

      public void write(int writeMe)
      Specified by:
      write in class PrintFormatter
    • available

      public int available()
      available() gets the number of bytes available in the stream. This is only for bytes that have already arrived.
      Returns:
      the number of bytes available to read
    • read

      public int read()
      read() reads characters from an incoming stream to the buffer.
      Returns:
      the first byte of incoming data available (or -1 if no data is available)
    • readExisting

      public String readExisting()
    • readBytes

      public int readBytes(byte[] buffer, int offset, int len)
      Reads up to len bytes of data from the stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.

      This method blocks until input data is available or times out after timeout milliseconds.

      Parameters:
      buffer - the buffer into which the data is read.
      offset - the start offset in array b at which the data is written.
      len - the maximum number of bytes to read.
      Returns:
      the total number of bytes read into the buffer
      See Also:
      • setTimeout()
    • readBytes

      public int readBytes(byte[] buffer, int len)
    • readBytesUntil

      public int readBytesUntil(byte eol, byte[] buffer, int len)
      Reads up to len bytes of data from the stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.

      This method blocks until input data is available, eol character is detected, or times out after timeout milliseconds. If

      Parameters:
      eol -
      buffer -
      len -
      Returns:
    • peek

      public int peek()
      Returns the next byte of of incoming stream without removing it from the internal buffer. That is, successive calls to peek() will return the same byte, as will the next call to read().
      Returns:
      the next byte of stream, returns -1 if the buffer is empty.
    • flush

      public void flush()
      Waits for up timeout milliseconds for the output buffer to be cleared before clearing any unsent data from from the buffer.
    • find

      public boolean find(String findMe)
      find() reads data from the stream until the target string of given length is found
      Returns:
      true if target string is found, false if timed out.
    • findUntil

      public boolean findUntil(String findMe, String terminal)
    • nextToken

      public String nextToken(String[] tokens)
      Searches the stream for the first matching token in an array of tokens.
      Parameters:
      tokens - is an array of tokens to search the stream for
      Returns:
      the matching token else null if timed out
    • setTimeout

      public void setTimeout(long timeout)
    • parseFloat

      public float parseFloat()
      parseFloat() returns the first valid floating point number from the Stream buffer. Characters that are not digits (or the minus sign) are skipped. parseFloat() is terminated by the first character that is not a floating point number.
      Returns:
    • parseDouble

      public double parseDouble()
    • parseInt

      public int parseInt()
    • parseLong

      public long parseLong()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • readln

      public String readln()