You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by jv...@apache.org on 2008/02/14 18:02:48 UTC
svn commit: r627802 -
/mina/asyncweb/trunk/examples/src/main/java/org/apache/asyncweb/examples/file/FileHttpService.java
Author: jvermillard
Date: Thu Feb 14 09:02:43 2008
New Revision: 627802
URL: http://svn.apache.org/viewvc?rev=627802&view=rev
Log:
using mmaped files
Modified:
mina/asyncweb/trunk/examples/src/main/java/org/apache/asyncweb/examples/file/FileHttpService.java
Modified: mina/asyncweb/trunk/examples/src/main/java/org/apache/asyncweb/examples/file/FileHttpService.java
URL: http://svn.apache.org/viewvc/mina/asyncweb/trunk/examples/src/main/java/org/apache/asyncweb/examples/file/FileHttpService.java?rev=627802&r1=627801&r2=627802&view=diff
==============================================================================
--- mina/asyncweb/trunk/examples/src/main/java/org/apache/asyncweb/examples/file/FileHttpService.java (original)
+++ mina/asyncweb/trunk/examples/src/main/java/org/apache/asyncweb/examples/file/FileHttpService.java Thu Feb 14 09:02:43 2008
@@ -21,9 +21,11 @@
package org.apache.asyncweb.examples.file;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.RandomAccessFile;
import java.net.URI;
+import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.InvalidParameterException;
import java.util.regex.Pattern;
@@ -168,19 +170,11 @@
response.setStatus(HttpResponseStatus.OK);
- FileChannel fileChannel = (new RandomAccessFile(f, "r"))
- .getChannel();
-
- // TODO : well it's quite explosive on big files, need to change the API
-
- int fileSize = (int) fileChannel.size();
- IoBuffer responseBuffer = IoBuffer.allocate(fileSize);
-
- fileChannel.read(responseBuffer.buf());
- fileChannel.close();
-
- responseBuffer.flip();
- response.setContent(responseBuffer);
+ RandomAccessFile raf = new RandomAccessFile(f, "r");
+ FileChannel fc = raf.getChannel();
+ MappedByteBuffer buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
+ response.setContent(IoBuffer.wrap(buffer));
+ fc.close();
} else {
// the file is not found, we send the famous 404 error