1 package org.oddjob.io; 2 3 import java.io.File ; 4 import java.io.Serializable ; 5 6 7 17 18 public class RenameJob implements Runnable , Serializable { 19 private static final long serialVersionUID = 20060117; 20 21 26 private String name; 27 28 33 private File from; 34 35 40 private File to; 41 42 47 public String getName() { 48 return name; 49 } 50 51 56 public void setName(String name) { 57 this.name = name; 58 } 59 60 65 public File getFrom() { 66 return from; 67 } 68 69 74 public void setFrom(File file) { 75 this.from = file; 76 } 77 78 83 public File getTo() { 84 return to; 85 } 86 87 92 public void setTo(File file) { 93 this.to = file; 94 } 95 96 97 101 public void run() { 102 if (from == null) { 103 throw new NullPointerException ("From file must be specified."); 104 } 105 if (to == null) { 106 throw new NullPointerException ("To file must be specified."); 107 } 108 if (!from.exists()) { 109 throw new RuntimeException ("[" + from + "], no such file or directory."); 110 } 111 if (!from.renameTo(to)) { 112 throw new RuntimeException ("Rename failed."); 113 } 114 } 115 116 120 public String toString() { 121 if (name == null) { 122 return "Rename"; 123 } 124 return name; 125 } 126 } 127 | Popular Tags |