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 溫少的日志 閱讀(267) 評論(0)  編輯  收藏

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


          網站導航:
           
           
          主站蜘蛛池模板: 织金县| 台北市| 阳东县| 大庆市| 武冈市| 洛隆县| 五河县| 达州市| 永修县| 金坛市| 荆门市| 潼南县| 上林县| 子洲县| 太和县| 南丹县| 湘乡市| 滨海县| 唐海县| 容城县| 都匀市| 沭阳县| 英吉沙县| 扎囊县| 吉安县| 子长县| 万年县| 永靖县| 进贤县| 宜君县| 佳木斯市| 西城区| 临江市| 盐亭县| 高雄县| 青冈县| 铜山县| 怀安县| 奉化市| 肇州县| 北辰区|