google/jimfs

How can I create a java RandomAccessFile on the jimfs filesystem?

Kalin-Rudnicki opened this issue · 1 comments

  • I have been trying to create/read/write normal files using jimfs, and it has been working just great
  • When I try to create a RandomAccessFile, I run into a few issues
    • RandomAccessFile takes only a File, and not a Path
    • (Path).toFile raises an UnsupportedOperationException when Path is created on jimfs FileSystem
    • new File((Path).toURI) throws an exception saying URI scheme is not "file"
  • Is there a way to get around any of these, and mock a RandomAccessFile on jimfs, just like it has been working file for me with normal files?

Unfortunately, I'm not sure we would be able to support RandomAccessFile directly, but it looks like there are some tutorials on using SeekableByteChannel, which looks to provided similar "write-anywhere" functionality (https://docs.oracle.com/javase/tutorial/essential/io/rafs.html).

JimFS supports this: https://github.com/google/jimfs#whats-supported, and it looks like you can convert from a RandomAccessFile to a SeekableByteChannel with raf.getChannel()