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



          溫少 2007-04-14 12:15 發表評論
          posted on 2007-04-14 12:15 溫少的日志 閱讀(268) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
           
          主站蜘蛛池模板: 灵川县| 泽普县| 涞源县| 大连市| 疏附县| 仁布县| 卢龙县| 鹿邑县| 三江| 慈溪市| 巴塘县| 普格县| 织金县| 专栏| 阿克苏市| 蓝山县| 巴塘县| 武穴市| 庐江县| 滨海县| 扎兰屯市| 乌鲁木齐市| 磴口县| 瑞丽市| 集安市| 安龙县| 巴林左旗| 浪卡子县| 曲靖市| 武安市| 枣庄市| 夹江县| 怀仁县| 邵武市| 会东县| 丹寨县| 永善县| 澜沧| 岫岩| 上林县| 泸水县|