Error in reading Ubuntu 14.04 mouse event file (/dev/input/event3) with java programmig -


i want handle mouse event in linux terminal via java programming. wrote 2 program via c++ , java same process.

when use c++ programming open , read file ("/dev/input/event3"-mouse event file), there no problem while running executable file. (ubuntu 14.04 terminal , ubuntu server 14.04 ---> no problem).

but when used java programming open , read same file ,there problem while running executable result file "java -jar program.jar" in ubuntu 14.04 "terminal". no error opening file , reading file make error this:

java.io.ioexception: invalid argument     @ java.io.fileinputstream.readbytes(native method)     @ java.io.fileinputstream.read(unknown source)     @ eventfileopen.m.main(m.java:33)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ java.lang.reflect.method.invoke(unknown source)     @ org.eclipse.jdt.internal.jarinjarloader.jarrsrcloader.main(jarrsrcloader.java:58) 

but when run same jar file on ubuntu server 14.04, there no error , program work perfectly. how can resolve problem?(problem = run java program on ubuntu 14.04 no error.) guess problem related ubuntu gui , jdk,but no idea resolving that. java program code:

import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.ioexception; import java.util.arrays;  public class m {      public static void main(string[] args) {          file f = new file("/dev/input/event3");         fileinputstream = null;         try {             = new fileinputstream(f);         } catch (filenotfoundexception e) {             e.printstacktrace();         }         byte[] bytes = new byte[16];         while(true){             try              {                 is.read(bytes);             } catch (ioexception e)              {                 e.printstacktrace();   //-------> error while run on ubuntu 14.04 , no error on ubuntu server             }             system.out.println(arrays.tostring(bytes));         }     } } 

check buffer size correct. in recent linux kernels size of input_event structure dependent on many things, on cpu architecture. here's declaration:

struct input_event {       struct timeval time;       __u16 type;       __u16 code;       __s32 value; }; 

on 32-bit systems it's buffer size accepted(16 bytes).

on 64-bit systems it's buffer should no less 24 bytes. reason timeval struct takes twice space(8 bytes more) on 32-bit systems.

i haven't found reliable way input_event struct size java , use jni that.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -