@Override
    public void put(ReadableByteChannel source) throws IOException {
        if (source == null || !source.isOpen())
            return;

        WritableByteChannel os = putChannel();
        FileChannel fos = null;

        try {
            if (source instanceof FileChannel) {
                fos = (FileChannel) os;
                FileChannel fis = (FileChannel) source;

                fis.transferTo(0, fis.size(), fos);
            } else {
                ByteBuffer buf = ByteBuffer.allocate(1024);
                int rc;
                while ((rc = source.read(buf)) >= 0) {
                    if (rc == 0)
                        continue;

                    buf.flip(); // flip (position back to 0, limit to amount read)
                    os.write(buf); // copy data into writable channel
                    buf.clear(); // prepare for new read
                }
            }
        } finally {
            if (fos != null)
                fos.close();
            else if (os != null)
                os.close();
        }
    }
@ Override public void put ( ReadableByteChannel source ) throws IOException { if ( source == null || ! source . isOpen ( ) ) return ; WritableByteChannel os = putChannel ( ) ; FileChannel fos = null ; try { if ( source instanceof FileChannel ) { fos = ( FileChannel ) os ; FileChannel fis = ( FileChannel ) source ; fis . transferTo ( 0 , fis . size ( ) , fos ) ; } else { ByteBuffer buf = ByteBuffer . allocate ( 1024 ) ; int rc ; while ( ( rc = source . read ( buf ) ) >= 0 ) { if ( rc == 0 ) continue ; buf . flip ( ) ; os . write ( buf ) ; buf . clear ( ) ; } } } finally { if ( fos != null ) fos . close ( ) ; else if ( os != null ) os . close ( ) ; } }
{@inheritDoc}