zoukankan      html  css  js  c++  java
  • 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的实现,十分期待中!!

  • 相关阅读:
    2012个人总结与展望
    C++Event机制的简单实现
    string与char*比较 ——why use string
    创建型模式学习总结——设计模式学习笔记
    Bridge模式——设计模式学习笔记
    Singleton模式——设计模式学习
    Adapter模式——设计模式学习笔记
    C++ 申请连续的对象内存
    7 个致命的 Linux 命令与个人评论
    关于保存Activity的状态
  • 原文地址:https://www.cnblogs.com/jobs/p/713090.html
Copyright © 2011-2022 走看看