I am trying to re-write a Python library in Java. I was wondering if any java package was available which is analogous to the select module available in Python.
http://docs.python.org/library/select.html
I have been referred to the nio package but I was wondering if there was a slighly more similar Java implementation.
Not unless you are willing to write a JNI wrapper for select(2) yourself, or can find one on the ‘net. (I looked briefly, and I didn’t find one.) That’s likely to be a fun little challenge, too, if you want to support Java’s notion of an open file (e.g., to map a Java
InputStreaminto a Unix file descriptor).The preferred way to do this in Java is, as you’ve noted, with
java.nio.niodoes have some restrictions, though. The biggest difference betweennioand select(2), aside from the API differences, is thatniowill only multiplex over network sockets. You can’t use it to multiselect open files, for instance.