int max = 100;
String path = "/tmp/test.txt";
FileOutputStream fos = new FileOutputStream( path );
fos.write( new byte[max] );
fos.close();
FileInputStream fis = new FileInputStream( path );
FileChannel channel = fis.getChannel();
MappedByteBuffer buff = channel.map( FileChannel.MapMode.READ_ONLY, 0, max );
assertEquals( 0, buff.getInt() );
fos = new FileOutputStream( path );
fos.write( new byte[0] );
fos.close();
assertEquals( 0, buff.getInt() );
Exception in thread "main" java.lang.InternalError: a fault occurred in a recent unsafe memory access operation in compiled Java code
SIGBUS
Attempted access to a portion of the buffer that does not correspond to the file (for example, beyond the end of the file, including the case where another process has truncated the file).
Many of the details of memory-mapped files are inherently dependent upon the underlying operating system and are therefore unspecified. The behavior of this method when the requested region is not completely contained within this channel's file is unspecified. Whether changes made to the content or size of the underlying file, by this program or another, are propagated to the buffer is unspecified. The rate at which changes to the buffer are propagated to the file is unspecified.
Which OS version do you have? I have found these sort of edge cases dissappear with newer kernel versions. ;)
--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.