Here you can find the source of toMappedBuffer(File file)
public static ByteBuffer toMappedBuffer(File file) throws IOException
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.channels.FileChannel.MapMode; public class Main { public static ByteBuffer toMappedBuffer(File file) throws IOException { RandomAccessFile raf = null; try {// ww w . jav a 2s .co m raf = new RandomAccessFile(file, "r"); return raf.getChannel().map(MapMode.READ_ONLY, 0, raf.length()); } finally { if (raf != null) { raf.close(); } } } /** Get remaining from null checked buffer * @param buffer The buffer to get the remaining from, in flush mode. * @return 0 if the buffer is null, else the bytes remaining in the buffer. */ public static int length(ByteBuffer buffer) { return buffer == null ? 0 : buffer.remaining(); } }