@@ -48,6 +48,7 @@ public class FilesystemEntry implements Serializable {
4848 private boolean exists ;
4949 private boolean directory ;
5050 private long lastModified ;
51+ private long length ;
5152
5253 /**
5354 * Construct a new monitor for a specified {@link File}.
@@ -74,18 +75,39 @@ public FilesystemEntry(FilesystemEntry parent, File file) {
7475 }
7576
7677 /**
77- * Refresh the attributes from the underlying {@link File}.
78+ * Refresh the attributes from the {@link File}, indicating
79+ * whether the file has changed.
7880 * <p>
79- * This implementation refreshes the <code>name</code>, <code>exists</code>
80- * <code>directory</code> and <code>lastModified</code> properties.
81- */
82- public void refresh (File file ) {
83- name = file .getName ();
84- exists = file .exists ();
85- if (exists ) {
86- directory = file .isDirectory ();
87- lastModified = file .lastModified ();
88- }
81+ * This implementation refreshes the <code>name</code>, <code>exists</code>,
82+ * <code>directory</code>, <code>lastModified</code> and <code>length</code>
83+ * properties.
84+ * <p>
85+ * The <code>exists</code>, <code>directory</code>, <code>lastModified</code>
86+ * and <code>length</code> properties are compared for changes
87+ *
88+ * @param file the file instance to compare to
89+ * @return <code>true</code> if the file has changed, otherwise <code>false</code>
90+ */
91+ public boolean refresh (File file ) {
92+
93+ // cache original values
94+ boolean origExists = exists ;
95+ long origLastModified = lastModified ;
96+ boolean origDirectory = directory ;
97+ long origLength = length ;
98+
99+ // refresh the values
100+ name = file .getName ();
101+ exists = file .exists ();
102+ directory = (exists ? file .isDirectory () : false );
103+ lastModified = (exists ? file .lastModified () : 0 );
104+ length = (exists && !directory ? file .length () : 0 );
105+
106+ // Return if there are changes
107+ return (exists != origExists ||
108+ lastModified != origLastModified ||
109+ directory != origDirectory ||
110+ length != origLength );
89111 }
90112
91113 /**
@@ -101,18 +123,6 @@ public FilesystemEntry newChildInstance(File file) {
101123 return new FilesystemEntry (this , file );
102124 }
103125
104- /**
105- * Indicate whether the file has changed or not.
106- * <p>
107- * This implementation compares the <code>lastModified<code>
108- * value of the {@link File} with the stored value.
109- *
110- * @return whether the file has changed or not
111- */
112- public boolean hasChanged (File file ) {
113- return (lastModified != file .lastModified ());
114- }
115-
116126 /**
117127 * Return the parent entry.
118128 *
@@ -198,6 +208,24 @@ public void setLastModified(long lastModified) {
198208 this .lastModified = lastModified ;
199209 }
200210
211+ /**
212+ * Return the length.
213+ *
214+ * @return the length
215+ */
216+ public long getLength () {
217+ return length ;
218+ }
219+
220+ /**
221+ * Set the length.
222+ *
223+ * @param length the length
224+ */
225+ public void setLength (long length ) {
226+ this .length = length ;
227+ }
228+
201229 /**
202230 * Indicate whether the file existed the last time it
203231 * was checked.
0 commit comments