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) {
      }
    }
  }
}

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 ) { } } } }
helper method to copy from one byte channel to another .
