WEB开发网
开发学院WEB开发Jsp 通过零拷贝实现有效数据传输 阅读

通过零拷贝实现有效数据传输

 2009-03-26 20:55:48 来源:WEB开发网   
核心提示:源:http://www.ibm.com/developerworks/cn/java/j-zerocopy/index.html主要看代码就可以了.view plaincopy to clipboardPRint?public void testSendfile() throws IOException { St

源:http://www.ibm.com/developerworks/cn/java/j-zerocopy/index.html

主要看代码就可以了.

view plaincopy to clipboardPRint?
public void testSendfile() throws IOException { 
     String host = "localhost"; 
     int port = 9026; 
     SocketAddress sad = new InetSocketAddress(host, port); 
     SocketChannel sc = SocketChannel.open(); 
     sc.connect(sad); 
     sc.configureBlocking(true); 
 
     String fname = "sendfile/NetworkInterfaces.c"; 
     long fsize = 183678375L, sendzise = 4094; 
     
     // FileProposerExample.stuffFile(fname, fsize); 
     FileChannel fc = new FileInputStream(fname).getChannel(); 
       long start = System.currentTimeMillis(); 
     long nsent = 0, curnset = 0; 
     curnset =  fc.transferTo(0, fsize, sc); 
     System.out.println("total bytes transferred--"+curnset+" and time taken in MS--"+(System.currentTimeMillis() - start)); 
     //fc.close(); 
    } 
public void testSendfile() throws IOException {
   String host = "localhost";
   int port = 9026;
   SocketAddress sad = new InetSocketAddress(host, port);
   SocketChannel sc = SocketChannel.open();
   sc.connect(sad);
   sc.configureBlocking(true);

String fname = "sendfile/NetworkInterfaces.c";
   long fsize = 183678375L, sendzise = 4094;
  
   // FileProposerExample.stuffFile(fname, fsize);
   FileChannel fc = new FileInputStream(fname).getChannel();
       long start = System.currentTimeMillis();
   long nsent = 0, curnset = 0;
   curnset =  fc.transferTo(0, fsize, sc);
   System.out.println("total bytes transferred--"+curnset+" and time taken in MS--"+(System.currentTimeMillis() - start));
   //fc.close();
  }

Tags:通过 拷贝 实现

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接