private static void copyToRemote ( Path src , URI dst ) throws IOException { ResourceId dstId = FileSystems . matchNewResource ( dst . toString ( ) , false ) ; WritableByteChannel dstCh = FileSystems . create ( dstId , MimeTypes . BINARY ) ; FileChannel srcCh = FileChannel . open ( src , StandardOpenOption . READ ) ; long srcSize = srcCh . size ( ) ; long copied = 0 ; do { copied += srcCh . transferTo ( copied , srcSize - copied , dstCh ) ; } while ( copied < srcSize ) ; dstCh . close ( ) ; srcCh . close ( ) ; Preconditions . checkState ( copied == srcSize ) ; }
Copy a single file from local source to remote destination