How can I create a java RandomAccessFile on the jimfs filesystem?
Kalin-Rudnicki opened this issue · 1 comments
Kalin-Rudnicki commented
- 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 issuesRandomAccessFile
takes only aFile
, and not aPath
(Path)
.toFile
raises anUnsupportedOperationException
whenPath
is created onjimfs FileSystem
- new File(
(Path)
.toURI
) throws an exception sayingURI scheme is not "file"
- Is there a way to get around any of these, and mock a
RandomAccessFile
onjimfs
, just like it has been working file for me with normal files?
nick-someone commented
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()