温少的日志

我希望我所作的事情对别人有所帮助!
随笔 - 184, 文章 - 1, 评论 - 1094, 引用 - 11
数据加载中……

JSR 203终于要出来啦

JSR-000203 More New I/O APIs for the Java Platform - Early Draft Review

http://jcp.org/aboutJava/communityprocess/edr/jsr203/index.html


API的Early Draft Review出来了,就意味很快就要真的出来啦!!

以下是其文档的一个Sample

 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);
  }


就是我最近很需要的东西,一个异步I/O的实现,十分期待中!!

posted on 2007-04-14 12:15 温少 阅读(1180) 评论(1)  编辑 收藏 网摘

评论

#1楼   回复  引用    

偶然的机会来到此地。是啊,人活着就是要实现自己的价值。谢谢你的资料。
2008-08-18 19:45 | 赵庶娟[未注册用户]



发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 713090




历史上的今天:
2006-04-14 为Berkeley DB写一个SQL前端
2005-04-14 使用bcel动态创建class

相关文章:

相关链接: