Java has two different APIs for accessing the file system: java.io and java.nio.
java.io is the older of the two, and optimistically uses objects and abstractions for everything. Thus, it has a FileDescriptor abstraction that encapsulates a Unix file descriptor. Only our native code ever touches it.
java.nio is pessimistic about abstraction, and goes the opposite way. It reads and writes C strings directly into the native heap so it can pass them to native OS interfaces. It passes around file descriptors as numbers.
Naturally, Java contains some internal, trusted conversion functions that create FileDescriptor objects from raw file descriptors, and vice versa.
Since Java exposes an API for retrieving a file descriptor's position and Node.js does not, we manually track a file descriptor's file position... in a FileDescriptor object. Which poses an issue: when converted into a raw file descriptor (or created from a raw file descriptor), we do not know the descriptor's position.
Instead, we should maintain a simple map from open descriptors to positions. We can update this map whenever we manipulate a file descriptor.
Java has two different APIs for accessing the file system:
java.io
andjava.nio
.java.io
is the older of the two, and optimistically uses objects and abstractions for everything. Thus, it has aFileDescriptor
abstraction that encapsulates a Unix file descriptor. Only our native code ever touches it.java.nio
is pessimistic about abstraction, and goes the opposite way. It reads and writes C strings directly into the native heap so it can pass them to native OS interfaces. It passes around file descriptors as numbers.Naturally, Java contains some internal, trusted conversion functions that create
FileDescriptor
objects from raw file descriptors, and vice versa.Since Java exposes an API for retrieving a file descriptor's position and Node.js does not, we manually track a file descriptor's file position... in a
FileDescriptor
object. Which poses an issue: when converted into a raw file descriptor (or created from a raw file descriptor), we do not know the descriptor's position.Instead, we should maintain a simple map from open descriptors to positions. We can update this map whenever we manipulate a file descriptor.
This will fix our currently-failing NioPathsTest.