@Test public void testOverwrite() throws IOException { File file = TestFileUtils.createTempFile( "testCopy\nasdf" ); for ( int i = 0; i < 5; i++ ) { File target = new File( targetDir, "testCopy.txt" ); fileProcessor.copy( file, target, null ); TestFileUtils.assertContent( "testCopy\nasdf".getBytes( "UTF-8" ), file ); } file.delete(); }
public long copy( File source, File target, ProgressListener listener ) throws IOException { long total = 0; FileInputStream fis = null; OutputStream fos = null; try { fis = new FileInputStream( source ); mkdirs( target.getParentFile() ); fos = new BufferedOutputStream( new FileOutputStream( target ) ); ByteBuffer buffer = ByteBuffer.allocate( 1024 * 32 ); byte[] array = buffer.array(); while ( true ) { int bytes = fis.read( array ); if ( bytes < 0 ) { break; } fos.write( array, 0, bytes ); total += bytes; if ( listener != null && bytes > 0 ) { try { buffer.rewind(); buffer.limit( bytes ); listener.progressed( buffer ); } catch ( Exception e ) { } } } } finally { close( fis ); close( fos ); } return total; }
DefaultFileProcessor implements FileProcessor { public long copy( File source, File target, ProgressListener listener ) throws IOException { long total = 0; FileInputStream fis = null; OutputStream fos = null; try { fis = new FileInputStream( source ); mkdirs( target.getParentFile() ); fos = new BufferedOutputStream( new FileOutputStream( target ) ); ByteBuffer buffer = ByteBuffer.allocate( 1024 * 32 ); byte[] array = buffer.array(); while ( true ) { int bytes = fis.read( array ); if ( bytes < 0 ) { break; } fos.write( array, 0, bytes ); total += bytes; if ( listener != null && bytes > 0 ) { try { buffer.rewind(); buffer.limit( bytes ); listener.progressed( buffer ); } catch ( Exception e ) { } } } } finally { close( fis ); close( fos ); } return total; } }
DefaultFileProcessor implements FileProcessor { public long copy( File source, File target, ProgressListener listener ) throws IOException { long total = 0; FileInputStream fis = null; OutputStream fos = null; try { fis = new FileInputStream( source ); mkdirs( target.getParentFile() ); fos = new BufferedOutputStream( new FileOutputStream( target ) ); ByteBuffer buffer = ByteBuffer.allocate( 1024 * 32 ); byte[] array = buffer.array(); while ( true ) { int bytes = fis.read( array ); if ( bytes < 0 ) { break; } fos.write( array, 0, bytes ); total += bytes; if ( listener != null && bytes > 0 ) { try { buffer.rewind(); buffer.limit( bytes ); listener.progressed( buffer ); } catch ( Exception e ) { } } } } finally { close( fis ); close( fos ); } return total; }  }
DefaultFileProcessor implements FileProcessor { public long copy( File source, File target, ProgressListener listener ) throws IOException { long total = 0; FileInputStream fis = null; OutputStream fos = null; try { fis = new FileInputStream( source ); mkdirs( target.getParentFile() ); fos = new BufferedOutputStream( new FileOutputStream( target ) ); ByteBuffer buffer = ByteBuffer.allocate( 1024 * 32 ); byte[] array = buffer.array(); while ( true ) { int bytes = fis.read( array ); if ( bytes < 0 ) { break; } fos.write( array, 0, bytes ); total += bytes; if ( listener != null && bytes > 0 ) { try { buffer.rewind(); buffer.limit( bytes ); listener.progressed( buffer ); } catch ( Exception e ) { } } } } finally { close( fis ); close( fos ); } return total; }  boolean mkdirs( File directory ); void write( File file, String data ); long copy( File source, File target, ProgressListener listener ); void move( File source, File target ); }
DefaultFileProcessor implements FileProcessor { public long copy( File source, File target, ProgressListener listener ) throws IOException { long total = 0; FileInputStream fis = null; OutputStream fos = null; try { fis = new FileInputStream( source ); mkdirs( target.getParentFile() ); fos = new BufferedOutputStream( new FileOutputStream( target ) ); ByteBuffer buffer = ByteBuffer.allocate( 1024 * 32 ); byte[] array = buffer.array(); while ( true ) { int bytes = fis.read( array ); if ( bytes < 0 ) { break; } fos.write( array, 0, bytes ); total += bytes; if ( listener != null && bytes > 0 ) { try { buffer.rewind(); buffer.limit( bytes ); listener.progressed( buffer ); } catch ( Exception e ) { } } } } finally { close( fis ); close( fos ); } return total; }  boolean mkdirs( File directory ); void write( File file, String data ); long copy( File source, File target, ProgressListener listener ); void move( File source, File target );  }