Buggy code:
crh . setBufferSize ( BUF_SIZE ) ; crh . setPrimaryReader ( in ) ; crh . setFilterChains ( filterChains ) ; crh . setProject ( project ) ; Reader rdr = crh . getAssembledReader ( ) ; in = new BufferedReader ( rdr ) ; } LineTokenizer lineTokenizer = new LineTokenizer ( ) ; lineTokenizer . setIncludeDelims ( true ) ; String newline = null ; String line = lineTokenizer . getToken ( in ) ; while ( line != null ) { if ( ( line . length ( ) ) == 0 ) { out . newLine ( ) ; } else { newline = filters . replaceTokens ( line ) ; out . write ( newline ) ; } line = lineTokenizer . getToken ( in ) ; } } finally { FileUtils . close ( out ) ; FileUtils . close ( in ) ; } } else if ( ( filterChainsAvailable || ( ( inputEncoding != null ) && ( ! ( inputEncoding . equals ( outputEncoding ) ) ) ) ) || ( ( inputEncoding == null ) && ( outputEncoding != null ) ) ) { BufferedReader in = null ; BufferedWriter out = null ; try { InputStreamReader isr = null ; if ( inputEncoding == null ) { isr = new InputStreamReader ( source . getInputStream ( ) ) ; } else { isr = new InputStreamReader ( source . getInputStream ( ) , inputEncoding ) ; } in = new BufferedReader ( isr ) ; OutputStream os = ResourceUtils . getOutputStream ( dest , append , project ) ; OutputStreamWriter osw ; if ( outputEncoding == null ) { osw = new OutputStreamWriter ( os ) ; } else { osw = new OutputStreamWriter ( os , outputEncoding ) ; } out = new BufferedWriter ( osw ) ; if ( filterChainsAvailable ) { ChainReaderHelper crh = new ChainReaderHelper ( ) ; crh . setBufferSize ( BUF_SIZE ) ; crh . setPrimaryReader ( in ) ; crh . setFilterChains ( filterChains ) ; crh . setProject ( project ) ; Reader rdr = crh . getAssembledReader ( ) ; in = new BufferedReader ( rdr ) ; } char [ ] buffer = new char [ FileUtils . BUF_SIZE ] ; while ( true ) { int nRead = in . read ( buffer , 0 , buffer . length ) ; if ( nRead == ( - 1 ) ) { break ; } out . write ( buffer , 0 , nRead ) ; } } finally { FileUtils . close ( out ) ; FileUtils . close ( in ) ; } } else if ( ( ( source . as ( FileProvider . class ) ) != null ) && ( ( dest . as ( FileProvider . class ) ) != null ) ) { File sourceFile = ( ( FileProvider ) ( source . as ( FileProvider . class ) ) ) . getFile ( ) ; File destFile = ( ( FileProvider ) ( dest . as ( FileProvider . class ) ) ) . getFile ( ) ; File parent = destFile . getParentFile ( ) ; if ( ( ( parent != null ) && ( ! ( parent . isDirectory ( ) ) ) ) && ( ! ( destFile . getParentFile ( ) . mkdirs ( ) ) ) ) { throw new IOException ( ( ( "failed<seq2seq4repair_space>to<seq2seq4repair_space>create<seq2seq4repair_space>the<seq2seq4repair_space>parent<seq2seq4repair_space>directory" + "<seq2seq4repair_space>for<seq2seq4repair_space>" ) + destFile ) ) ; } FileInputStream in = null ; FileOutputStream out = null ; FileChannel srcChannel = null ; FileChannel destChannel = null ; try { in = new FileInputStream ( sourceFile ) ; out = new FileOutputStream ( destFile ) ; srcChannel = in . getChannel ( ) ; destChannel = out . getChannel ( ) ; long position = 0 ; long count = srcChannel . size ( ) ; while ( position < count ) { <START_BUG> position += srcChannel . transferTo ( position , BUF_SIZE , destChannel ) ; <END_BUG> } } finally { FileUtils . close ( srcChannel ) ; FileUtils . close ( destChannel ) ; FileUtils . close ( out ) ; FileUtils . close ( in ) ; } } else { InputStream in = null ; OutputStream out = null ; try { in = source . getInputStream ( ) ; out = ResourceUtils . getOutputStream ( dest , append , project ) ; byte [ ] buffer = new byte [ FileUtils . BUF_SIZE ] ; int count = 0 ; do { out . write ( buffer , 0 , count ) ; count = in . read ( buffer , 0 , buffer . length ) ; } while ( count != ( - 1 ) ) ; } finally { FileUtils . close ( out ) ; FileUtils . close ( in ) ; } } if ( preserveLastModified ) { Touchable t = ( ( Touchable ) ( dest . as ( Touchable . class ) ) ) ; if ( t != null ) { ResourceUtils . setLastModified ( t , source . getLastModified ( ) ) ; } } } public static void setLastModified ( Touchable t , long time ) { } public static boolean contentEquals ( Resource r1 , Resource r2 , boolean text ) throws IOException { } public static int compareContent ( Resource r1 , Resource r2 , boolean text ) throws IOException { } public static FileResource asFileResource ( FileProvider fileProvider ) { } private static int binaryCompare ( Resource r1 , Resource r2 ) throws IOException { } private static int textCompare ( Resource r1 , Resource r2 ) throws IOException { } private static void logFuture ( ProjectComponent logTo , ResourceCollection rc , long granularity ) { } private static OutputStream getOutputStream ( Resource resource , boolean append , Project project ) throws IOException { }

Fix:
position += srcChannel . transferTo ( position , ( count - position ) , destChannel ) ;