Question

As a java guru, what would you suggest to abstract random access so that a code can be agnostic to whether the data its accessing is in memory or in a file on the harddrive?

(The files in question could be several gigabytes in size. Having random access is the most important feature.)

Was it helpful?

Solution

This is what Java NIO is for.

See Random Access Files and Memory-mapped files.

OTHER TIPS

I can offer memory mapping of files. Those give you a java.nio.ByteBuffer. And you can also make those as ordinary in-memory objects, so there you go, perfect agnosis, if not perfect ignorance.

And we've had them since 1.4.

The question is in some respects unclear. If you want file-style access, you are rather out of luck, since a RandomAccessFile can't be constructed over any in-memory resource.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top