/**
* @tests java.nio.channels.FileChannel#map(MapMode,long,long)
*/
public void test_map_ReadOnly() throws IOException {
MappedByteBuffer mapped = null;
// try put something to readonly map
writeDataToFile(fileOfReadOnlyFileChannel);
mapped = readOnlyFileChannel.map(MapMode.READ_ONLY, 0, CONTENT_LENGTH);
try {
mapped.put(TEST_BYTES);
fail("should throw ReadOnlyBufferException.");
} catch (ReadOnlyBufferException ex) {
// expected;
}
assertEquals(CONTENT_LENGTH, mapped.limit());
assertEquals(CONTENT_LENGTH, mapped.capacity());
assertEquals(0, mapped.position());
// try to get a readonly map from read/write channel
writeDataToFile(fileOfReadWriteFileChannel);
mapped = readWriteFileChannel.map(MapMode.READ_ONLY, 0, CONTENT
.length());
assertEquals(CONTENT_LENGTH, mapped.limit());
assertEquals(CONTENT_LENGTH, mapped.capacity());
assertEquals(0, mapped.position());
// map not change channel's position
assertEquals(0, readOnlyFileChannel.position());
assertEquals(0, readWriteFileChannel.position());
}