Scanner works in "spurts" when piping

I’m making a project where I’m taking in data from another program via the command line

If my JAR is called “project.jar”, and the data-maker program is called “program” I am taking in data like this:


program | java -jar project.jar

When I did this, I noticed that there was a significant amount of lag in my program. Not in the framerate at all, but rather in the rate at which the lines generated by “program” were fed into “project.jar” at an inconsistent rate. To see if this was a problem with “project.jar”, I made a new JAR which is literally this:


import java.util.Scanner;

public class Printer {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			System.out.println(sc.nextLine());
		}
	}

}

Now, “program” generates data very quickly, maybe 10 lines a second. But when I set up


program | java -jar printer.jar

then THIS prints out data in the same spurts! There would be 3 or 4 seconds before a massive chunk of lines would be printed out. Why should this happen? If I pipe “program” into “printer”, I should see it printing everything out continuously at the same rate “program” does.

Is this a problem with piping, or with the Scanner class, or what? How can I fix this so Scanner reads things more continuously?

Thanks