/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.easy.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel.MapMode;
/**
*
* @author Administrator
*/
public class FileUtils {
public static ByteBuffer getMapByteBuffer(File file, MapMode mode, long position, long size) throws IOException {
NullArgumentException.check(file);
NullArgumentException.check(mode);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
return fis.getChannel().map(mode, position, size);
} finally {
if (fis != null) {
fis.close();
}
}
}
public static ByteBuffer getMapByteBuffer(File file, MapMode mode) throws IOException {
return getMapByteBuffer(file, mode, 0, file == null ? 0 : file.length());
}
public static ByteBuffer getReadOnlyMapByteBuffer(File file) throws IOException {
return getMapByteBuffer(file, MapMode.READ_ONLY);
}
}
|