/**
* @tests java.nio.channels.FileChannel#map(MapMode,long,long)
*/
public void test_map_ReadWrite() throws IOException {
MappedByteBuffer mapped = null;
writeDataToFile(fileOfReadWriteFileChannel);
mapped = readWriteFileChannel.map(MapMode.READ_WRITE, 0, CONTENT
.length());
// put something will change its channel
ByteBuffer returnByPut = mapped.put(TEST_BYTES);
assertSame(returnByPut, mapped);
String checkString = "test" + CONTENT.substring(4);
ByteBuffer checkBuffer = ByteBuffer.allocate(CONTENT_LENGTH);
mapped.force();
readWriteFileChannel.position(0);
readWriteFileChannel.read(checkBuffer);
assertEquals(checkString, new String(checkBuffer.array(), "iso8859-1"));
try {
mapped.put(("test" + CONTENT).getBytes("iso8859-1"));
fail("should throw BufferOverflowException.");
} catch (BufferOverflowException ex) {
// expected;
}
}