FileUtils.java :  » Game » easy-game-client » org » easy » util » Java Open Source

Java Open Source » Game » easy game client 
easy game client » org » easy » util » FileUtils.java
/*
 * 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);
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.