question: protected static void channelCopy ( ReadableByteChannel from , WritableByteChannel to ) throws IOException { ByteBuffer buffer = ByteBuffer . allocateDirect ( 16 * 1024 ) ; try { while ( from . read ( buffer ) != - 1 ) { buffer . flip ( ) ; to . write ( buffer ) ; buffer . compact ( ) ; } buffer . flip ( ) ; while ( buffer . hasRemaining ( ) ) { to . write ( buffer ) ; } } finally { if ( from != null ) { try { from . close ( ) ; } catch ( Exception ex ) { } } if ( to != null ) { try { to . close ( ) ; } catch ( Exception ex ) { } } } }
target:  Helper Method to Copy from one Byte Channel to another.