directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Directory Wiki] Update of "JavaAIO" by MikeHeath
Date Fri, 24 Nov 2006 20:15:34 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Directory Wiki" for change notification.

The following page has been changed by MikeHeath:
http://wiki.apache.org/directory/JavaAIO

------------------------------------------------------------------------------
- Java AIO is a framework created by me, MikeHeath, because I got tired of waiting for [http://jcp.org/en/jsr/detail?id=203
JSR 203] and IBM's [http://alphaworks.ibm.com/tech/aio4j AIO4J] doesn't have support for asynchronous
file access with Linux.  The framework is still in very early development.  It currently only
supports Linux.  The API is in flux.  And the framework hasn't received a great deal of testing.
 I expect all this to change for the better in the near future.  I've make the project available
so that others can help with testing and hopefully there are others out there who would like
to contribute to the project.  I will try to post examples and additional documentation here
as the framework progresses.
+ [http://cwiki.apache.org/confluence/display/MINA/Asynchronous+File+IO+in+Java The contents
of this page have moved to the Mina project.]
  
- The source code for the project can be found in my subversion sandbox as part of the Apache
Directory project [https://svn.apache.org/repos/asf/directory/sandbox/mheath/aio].
- 
- To build the project use Maven 2 and run "mvn package".  This will produce two artifacts.
 A Java .jar file containing the Java classes and libjavaaio.so which contains the the native
binaries necessary to do asynchronous file IO in Java.
- 
- Below is a simple example of how to use Java AIO.
- 
- {{{
- import java.io.FileInputStream;
- import java.nio.ByteBuffer;
- 
- import org.apache.aio.AioFutureListener;
- import org.apache.aio.AioFutureReadWrite;
- import org.apache.aio.AsynchronousFileChannel;
- 
- public class AIOTest {
- 
- 	public static void main(String[] args) throws Exception {
- 		FileInputStream in = new FileInputStream("/etc/passwd");
- 
- 		AsynchronousFileChannel achannel = new AsynchronousFileChannel(in.getFD());
- 		
- 		
- 		AioFutureListener<AioFutureReadWrite> listener = new AioFutureListener<AioFutureReadWrite>()
{
- 					public void onCompletion(AioFutureReadWrite ioFuture) {
- 						System.out.println("In callback");
- 						byte[] data = new byte[ioFuture.getBuffer().limit() - ioFuture.getBuffer().position()];
- 						ioFuture.getBuffer().get(data);
- 						System.out.println("  Buffer contains: " + new String(data));
- 					}
- 				};
- 		ByteBuffer buffer = ByteBuffer.allocateDirect(4096);
- 		AioFutureReadWrite future = achannel.read(buffer, 0);
- 		future.addListener(listener);
- 		future.join();
- 	}
- 		
- }
- 
- }}}
- 

Mime
View raw message