stevel 2004/08/03 16:18:35
Modified: src/main/org/apache/tools/ant/util FileUtils.java
Log:
1. some factoring out of the timestamp checks for even more reuse. That way
the granularity logic can all go in one place.
2. a refactoring of close() to ignore exceptions. I made this static because
I want to use it everywhere we close things in a finally clause. NB, note that
all four methods would all be unified if the writer/reader/instream/outstream
classes had a base class "Closeable" with method void close().
No, I have not refactored everything to use these yet.
Revision Changes Path
1.70 +96 -2 ant/src/main/org/apache/tools/ant/util/FileUtils.java
Index: FileUtils.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- FileUtils.java 18 May 2004 08:14:48 -0000 1.69
+++ FileUtils.java 3 Aug 2004 23:18:35 -0000 1.70
@@ -30,6 +30,9 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
@@ -1340,9 +1343,10 @@
}
long sourceTime=source.lastModified();
long destTime=dest.lastModified();
- return destTime>=sourceTime+granularity;
+ return isUpToDate(sourceTime, destTime, granularity);
}
+
/**
* returns true if the source is older than the dest
* @param source source file (should be the older)
@@ -1354,6 +1358,96 @@
return isUpToDate(source, dest, getFileTimestampGranularity());
}
+ /**
+ * compare two timestamps for being up to date, use granularity too.,
+ *
+ * @param sourceTime timestamp of source file
+ * @param destTime timestamp of dest file
+ * @param granularity os/filesys granularity
+ * @return true if the dest file is considered up to date
+ */
+ public boolean isUpToDate(long sourceTime,long destTime, long
granularity) {
+ if(destTime==-1) {
+ return false;
+ }
+ return destTime >= sourceTime + granularity;
+ }
+
+ /**
+ * compare two timestamps for being up to date, use the
+ * current granularity
+ *
+ * @param sourceTime timestamp of source file
+ * @param destTime timestamp of dest file
+ * @return true if the dest file is considered up to date
+ */
+ public boolean isUpToDate(long sourceTime, long destTime) {
+ return isUpToDate(sourceTime,
destTime,getFileTimestampGranularity());
+ }
+
+
+ /**
+ * close a writer without throwing any exception if something went wrong.
+ * Do not attempt to close it if the file is null
+ * @param device output writer, can be null
+ */
+ public static void close(Writer device) {
+ if (device != null) {
+ try {
+ device.close();
+ } catch (IOException ioex) {
+ //ignore
+ }
+ }
+ }
+
+ /**
+ * close a stream without throwing any exception if something went wrong.
+ * Do not attempt to close it if the file is null
+ *
+ * @param device stream, can be null
+ */
+ public static void close(Reader device) {
+ if ( device != null ) {
+ try {
+ device.close();
+ } catch (IOException ioex) {
+ //ignore
+ }
+ }
+ }
+
+ /**
+ * close a stream without throwing any exception if something went wrong.
+ * Do not attempt to close it if the file is null
+ *
+ * @param device stream, can be null
+ */
+ public static void close(OutputStream device) {
+ if ( device != null ) {
+ try {
+ device.close();
+ } catch (IOException ioex) {
+ //ignore
+ }
+ }
+ }
+
+ /**
+ * close a stream without throwing any exception if something went wrong.
+ * Do not attempt to close it if the file is null
+ *
+ * @param device stream, can be null
+ */
+ public static void close(InputStream device) {
+ if ( device != null ) {
+ try {
+ device.close();
+ } catch (IOException ioex) {
+ //ignore
+ }
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]