JSR-000203 More New I/O APIs for the Java Platform-Early Draft Review
Http://jcp.org/aboutJava/communityprocess/edr/jsr203/index.html
The Early Draft Review of the API is coming out, which means it will come out soon !!
The following is a Sample of the document.
Static class IOTransaction {
Public ByteBuffer buffer (){}
Public long position (){}
Public long updatePosition (int transferred ){}
}
Static class WriteHandler implements CompletionHandler <Integer> {
Public WriteHandler (AsynchronousFileChannel ch ){}
Private AsynchronousFileChannel channel (){}
Public void completed (IoFuture <Integer> result ){
Int bytesTransferred;
Try {
BytesTransferred = result. getNow ();
} Catch (ExecutionException x ){}
IOTransaction transaction = (IOTransaction) result. attachment ();
ByteBuffer buffer = transaction. buffer ();
If (buffer. remaining ()> 0 ){
Long position = transaction. updatePosition (bytesTransferred );
Channel (). write (buffer, position, transaction, this );
}
}
}
FileReference file =
List <IOTransaction> transactionList =
AsynchronousFileChannel ch = AsynchronousFileChannel. open (file, OpenFlag. WRITE );
WriteHandler handler = new WriteHandler (ch );
For (IOTransaction transaction: transactionList ){
// Use the transaction as the attachment
Ch. write (transaction. buffer (), transaction. position (), transaction, handler );
}
That's what I need recently. An asynchronous I/O implementation is coming soon !!