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.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; import java.nio.file.StandardOpenOption; public class Main { public static ByteBuffer toMappedBuffer(File file) throws IOException { try (FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.READ)) { return channel.map(MapMode.READ_ONLY, 0, file.length()); }/*from w w w . j a va 2s. c o m*/ } /** 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(); } }