private static void copyToLocal ( Metadata src , Path dst ) throws IOException { FileChannel dstCh = FileChannel . open ( dst , StandardOpenOption . WRITE , StandardOpenOption . CREATE_NEW ) ; ReadableByteChannel srcCh = FileSystems . open ( src . resourceId ( ) ) ; long srcSize = src . sizeBytes ( ) ; long copied = 0 ; do { copied += dstCh . transferFrom ( srcCh , copied , srcSize - copied ) ; } while ( copied < srcSize ) ; dstCh . close ( ) ; srcCh . close ( ) ; Preconditions . checkState ( copied == srcSize ) ; }
Copy a single file from remote source to local destination