1 16 package org.apache.commons.vfs.tasks; 17 18 import org.apache.commons.vfs.FileObject; 19 import org.apache.commons.vfs.FileSystemException; 20 import org.apache.commons.vfs.Selectors; 21 22 28 public class MoveTask 29 extends CopyTask 30 { 31 private boolean tryRename = false; 32 33 36 public void setTryRename(boolean tryRename) 37 { 38 this.tryRename = tryRename; 39 } 40 41 44 protected void handleOutOfDateFile(final FileObject srcFile, 45 final FileObject destFile) 46 throws FileSystemException 47 { 48 if (!tryRename || !srcFile.canRenameTo(destFile)) 49 { 50 super.handleOutOfDateFile(srcFile, destFile); 51 52 log("Deleting " + srcFile); 53 srcFile.delete(Selectors.SELECT_SELF); 54 } 55 else 56 { 57 log("Rename " + srcFile + " to " + destFile); 58 srcFile.moveTo(destFile); 59 if (!isPreserveLastModified()) 60 { 61 destFile.getContent().setLastModifiedTime(System.currentTimeMillis()); 62 } 63 } 64 } 65 } 66 | Popular Tags |