Guest User

Untitled

a guest
May 20th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. static void channelCopy( ReadableByteChannel src, WriteableByteChannel dest ){
  2.    
  3.     ByteBuffer buffer = ByteBuffer.allocateDirect( 16 * 1024 );
  4.  
  5.     while( src.read(buffer) != -1 ){
  6.         //Prepare the buffer to be drained
  7.         buffer.flip();
  8.        
  9.         while(buffer.hasRemaining()){
  10.             dest.write(buffer);
  11.         }
  12.        
  13.         //Make the buffer empty, ready for filling.
  14.         buffer.clear();
  15.  
  16.     }
  17.  
  18.  
  19. }
Add Comment
Please, Sign In to add comment