KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > util > FileChannelUtils


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.media.util;
9
10 import java.io.FileInputStream JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.nio.MappedByteBuffer JavaDoc;
13 import java.nio.channels.FileChannel JavaDoc;
14
15 /**
16  * FileChannel utils.
17  *
18  * @version <tt>$Revision: 1.1 $</tt>
19  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo Argüello</a>
20  */

21 public class FileChannelUtils
22 {
23    public MappedByteBuffer JavaDoc getMappedByte(String JavaDoc fileName) throws IOException JavaDoc
24    {
25       FileChannel JavaDoc fileChannel = new FileInputStream JavaDoc(fileName).getChannel();
26       int fileSize = (int) fileChannel.size();
27       MappedByteBuffer JavaDoc mappedfile =
28          fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);
29       mappedfile.load();
30       return mappedfile;
31    }
32 }
33
Popular Tags