Help with Serial.readStringUntil()

Hello,

I’m working on a little Java/Arduino project to controll some RGB strips.
Im using the RXTX library to send data to my Arduino Uno.

I programmed a little echo routine to show you my problem.

Java Serial Ouput:

l,0,446264,l,1,fefefe,l,2,fdfbfb,l,3,faf8f7,l,4,b7d8d8,
b,0,d7d8da,b,1,d7d7da,b,2,d8d8da,b,3,abb3b5,b,4,698283,

Arduino output read with my Java programm:

side: l index: 0 color: 446264
side: l index: 1 color: fefefe
side: l index: 2 color: fdfbfb
side: l index: 3 color: faf8f7
side: l index: 4 color: b7d8d8
side: b index: 0 color: d7d8

I’m not reading the complete set of data.
Why is that so? Do I have to clear a buffer?

The Ardunio Code:

void setup()
{
  Serial.begin(9600);
  Serial.setTimeout(50);
  delay(2000);
}

void loop()
{
  if (Serial.available() > 0)
  {
    String side = Serial.readStringUntil(',');
    String index = Serial.readStringUntil(',');
    String hexColor = Serial.readStringUntil(',');

    Serial.print(" side: ");
    Serial.print(side);
    Serial.print(" index: ");
    Serial.print(index);
    Serial.print(" color: ");
    Serial.println(hexColor);
    Serial.flush();
    delay(10);
  }
}

Java Snippet SerialWriter

package application;

import java.io.IOException;
import java.io.OutputStream;

public class SerialWriter {
	public static OutputStream out;

	public static void send(String side, RGB[] data) {
		try {
			RGB color;
			String dataOut = "";

			if (data.length == Data.areas_) {
				for (int i = 0; i < Data.areas_; i++) {
					color = data[Data.areas_ - 1 - i];					
					
					dataOut += side + "," + i + "," + color.toHex().replaceAll("#", "") + ",";							
				}
				out.write(dataOut.getBytes());
				out.flush();
				Thread.sleep(100);
				System.out.println(dataOut.replaceAll("\\r", "") + "\n");
			}
		} catch (InterruptedException | IOException e) {
			e.printStackTrace();
		}
	}

}

Java Snipper SerialReader

package application;

import java.io.IOException;
import java.io.InputStream;

public class SerialReader implements Runnable {
	InputStream in;

	public SerialReader(InputStream in) {
		this.in = in;
	}

	public void run() {
		byte[] buffer = new byte[1024];
		int len = -1;
		try {
			while ((len = this.in.read(buffer)) > -1) {
				System.out.print(new String(buffer, 0, len));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Serial input basics has example code for reading and parsing serial input without Strings. Also how the structure the data sent for reliable reception.

It seems that the Arduino receives all the data.

It's just a console thing.

Serial.readStringUntil() is working for my purpose.