When trying to read input_events from /dev/input/event16
I noticed that the size of the buffer I'm reading into may cause an exception. Here is the code I wrote:
public static void main(String[] args) throws IOException{
FileInputStream is = new FileInputStream("/dev/input/event16");
byte[] three_bytes = new byte[3];
byte[] twentyfour_bytes = new byte[24];
is.read(three_bytes); // fails
is.read(twentyfour_bytes); // does not fail
}
My initial experiments suggest that the buffer needs capacity for at least one full input_event
struct. But I could not find out why.
The problem is the line is.read(three_bytes);
causes the follwoing exception:
Exception in thread "main" java.io.IOException: Invalid argument
at java.base/java.io.FileInputStream.readBytes(Native Method)
at java.base/java.io.FileInputStream.read(FileInputStream.java:249)
at main.Test.main(Test.java:11)
I would like to figure out why the line is.read(three_bytes);
throws the exception while is.read(twentyfour_bytes);
reads the data as expected