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的实现,十分期待中!!

  • 相关阅读:
    找水王
    用户体验评价
    人件集阅读笔记01
    第十四周学习进度
    第十三周学习进度
    第十二周学习进度
    第十一周学习进度
    梦断代码阅读笔记03
    团队项目-第一阶段冲刺-10
    Shell按行读取文件的3种方法
  • 原文地址:https://www.cnblogs.com/jobs/p/713090.html
Copyright © 2011-2022 走看看