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 CopyTask 29 extends AbstractSyncTask 30 { 31 private boolean overwrite = false; 32 private boolean preserveLastModified = true; 33 34 37 public void setOverwrite(boolean overwrite) 38 { 39 this.overwrite = overwrite; 40 } 41 42 45 public void setPreserveLastModified(boolean preserveLastModified) 46 { 47 this.preserveLastModified = preserveLastModified; 48 } 49 50 53 public boolean isOverwrite() 54 { 55 return overwrite; 56 } 57 58 61 public boolean isPreserveLastModified() 62 { 63 return preserveLastModified; 64 } 65 66 69 protected void handleOutOfDateFile(final FileObject srcFile, 70 final FileObject destFile) 71 throws FileSystemException 72 { 73 log("Copying " + srcFile + " to " + destFile); 74 destFile.copyFrom(srcFile, Selectors.SELECT_SELF); 75 if (preserveLastModified) 76 { 77 final long lastModTime = srcFile.getContent().getLastModifiedTime(); 78 destFile.getContent().setLastModifiedTime(lastModTime); 79 } 80 } 81 82 85 protected void handleUpToDateFile(final FileObject srcFile, 86 final FileObject destFile) 87 throws FileSystemException 88 { 89 if (overwrite) 90 { 91 handleOutOfDateFile(srcFile, destFile); 93 } 94 } 95 } 96 | Popular Tags |