public boolean copy ( File src , File dst , MP4Edit edit ) throws IOException { SeekableByteChannel fi = null ; SeekableByteChannel fo = null ; try { fi = NIOUtils . readableChannel ( src ) ; fo = NIOUtils . writableChannel ( dst ) ; List < Tuple . _2 < Atom , ByteBuffer > > fragments = doTheFix ( fi , edit ) ; if ( fragments == null ) return false ; List < _2 < Long , ByteBuffer > > fragOffsets = Tuple . _2map0 ( fragments , new Tuple . Mapper < Atom , Long > ( ) { public Long map ( Atom t ) { return t . getOffset ( ) ; } } ) ; // If everything is clean, only then actually start writing file Map < Long , ByteBuffer > rewrite = Tuple . asMap ( fragOffsets ) ; for ( Atom atom : MP4Util . getRootAtoms ( fi ) ) { ByteBuffer byteBuffer = rewrite . get ( atom . getOffset ( ) ) ; if ( byteBuffer != null ) fo . write ( byteBuffer ) ; else atom . copy ( fi , fo ) ; } return true ; } finally { NIOUtils . closeQuietly ( fi ) ; NIOUtils . closeQuietly ( fo ) ; } }
Tries to modify movie header in place according to what s implemented in the edit . Copies modified contents to a new file .