Is there a programmatical way to implement the method “isFileMapped” which satisfy the following:
ByteBuffer aa = ByteBuffer.allocateDirect(12);
assertFalse(isFileMapped(aa));
FileChannel fc = new RandomAccessFile(File.createTempFile("mmap", "test"), "rw").getChannel();
ByteBuffer bb = fc.map(FileChannel.MapMode.READ_WRITE, 0, 10);
assertTrue(isFileMapped(bb));
fc.close();
// and of course:
assertFalse(isFileMapped(ByteBuffer.allocate(12)));
Both instances are of type MappedByteBuffer and are direct.
Use
MappedByteBuffer.isLoaded(). For really mapped buffers it returns true or false, for those returned byByteBuffer.allocateDirect(), it throws UnsupportedOperationException.But I am not sure if it would still throw UnsupportedOperationException after participating in an I/O operation.