From 5c8ce1c95131804eb425ba2a62475159b3635655 Mon Sep 17 00:00:00 2001
From: tpylak <tpylak>
Date: Mon, 30 Jun 2008 09:47:56 +0000
Subject: [PATCH] DMV-21 error handling in IFileStore for exists() and
 lastChanged*()

SVN: 6912
---
 .../cisd/common/utilities/FileUtilities.java  | 28 +++++++--------
 .../FileUtilitiesLastChangedTest.java         |  1 +
 .../UnknownLastChangedException.java          | 34 +++++++++++++++++++
 3 files changed, 49 insertions(+), 14 deletions(-)
 create mode 100644 common/sourceTest/java/ch/systemsx/cisd/common/utilities/UnknownLastChangedException.java

diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java b/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java
index 39adafb3f28..2f29b7838d8 100644
--- a/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java
+++ b/common/source/java/ch/systemsx/cisd/common/utilities/FileUtilities.java
@@ -534,7 +534,7 @@ public final class FileUtilities
         private boolean terminated;
 
         LastChangedWorker(final File root, final boolean subDirectoriesOnly, final long reference,
-                final boolean referenceIsRelative)
+                final boolean referenceIsRelative) throws UnknownLastChangedException
         {
             assert root != null;
 
@@ -550,15 +550,15 @@ public final class FileUtilities
             }
         }
 
-        private void updateLastChanged(final File path)
+        private void updateLastChanged(final File path) throws UnknownLastChangedException
         {
             assert path != null;
 
             final long lastModified = path.lastModified();
             if (lastModified == 0)
             {
-                throw new CheckedExceptionTunnel(new IOException(String.format(
-                        "Cannot get the last modification date of '%s'.", path.getPath())));
+                throw new UnknownLastChangedException(String.format(
+                        "Cannot get the last modification date of '%s'.", path.getPath()));
             }
 
             lastChanged = Math.max(lastModified, lastChanged);
@@ -579,7 +579,7 @@ public final class FileUtilities
             }
         }
 
-        private void traverse(final File path)
+        private void traverse(final File path) throws UnknownLastChangedException
         {
             assert path != null;
 
@@ -642,12 +642,12 @@ public final class FileUtilities
      *            entry, but only, if there are entries that are "young enough".
      * @return The time when any file in (or below) <var>path</var> has last been changed in the
      *         file system.
-     * @throws CheckedExceptionTunnel of an {@link IOException} if the <var>path</var> does not
-     *             exist or is not readable.
+     * @throws UnknownLastChangedException if the <var>path</var> does not exist or is not
+     *             readable.
      * @throws StopException if the thread that the method runs in gets interrupted.
      */
     public static long lastChanged(final File path, final boolean subDirectoriesOnly,
-            final long stopWhenFindYounger)
+            final long stopWhenFindYounger) throws UnknownLastChangedException
     {
         return (new LastChangedWorker(path, subDirectoriesOnly, stopWhenFindYounger, false))
                 .getLastChanged();
@@ -669,12 +669,12 @@ public final class FileUtilities
      *            there are entries that are "young enough".
      * @return The time when any file in (or below) <var>path</var> has last been changed in the
      *         file system.
-     * @throws CheckedExceptionTunnel of an {@link IOException} if the <var>path</var> does not
-     *             exist or is not readable.
+     * @throws UnknownLastChangedException if the <var>path</var> does not exist or is not
+     *             readable.
      * @throws StopException if the thread that the method runs in gets interrupted.
      */
     public static long lastChangedRelative(final File path, final boolean subDirectoriesOnly,
-            final long stopWhenFindYoungerRelative)
+            final long stopWhenFindYoungerRelative) throws UnknownLastChangedException
     {
         return (new LastChangedWorker(path, subDirectoriesOnly, stopWhenFindYoungerRelative, true))
                 .getLastChanged();
@@ -683,11 +683,11 @@ public final class FileUtilities
     /**
      * @return The time when any file in (or below) <var>path</var> has last been changed in the
      *         file system.
-     * @throws CheckedExceptionTunnel of an {@link IOException} if the <var>path</var> does not
-     *             exist or is not readable.
+     * @throws UnknownLastChangedException if the <var>path</var> does not exist or is not
+     *             readable.
      * @throws StopException if the thread that the method runs in gets interrupted.
      */
-    public static long lastChanged(final File path)
+    public static long lastChanged(final File path) throws UnknownLastChangedException
     {
         return lastChanged(path, false, 0L);
     }
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesLastChangedTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesLastChangedTest.java
index 0712747537b..4d0dc4679a0 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesLastChangedTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesLastChangedTest.java
@@ -82,6 +82,7 @@ public class FileUtilitiesLastChangedTest
     @Test(groups =
         { "slow" }, dataProvider = "testLastChanged")
     public void testLastChanged(String dirToCheck, String dirToCreate)
+            throws UnknownLastChangedException
     {
         final File testDir = new File(workingDirectory, dirToCheck);
         testDir.deleteOnExit();
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/UnknownLastChangedException.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/UnknownLastChangedException.java
new file mode 100644
index 00000000000..c02beca7f22
--- /dev/null
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/UnknownLastChangedException.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2008 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.common.utilities;
+
+import java.io.IOException;
+
+/**
+ * Used to signal the error of getting last modification time of a store item
+ * 
+ * @author Tomasz Pylak
+ */
+public class UnknownLastChangedException extends IOException
+{
+    private static final long serialVersionUID = 1L;
+
+    public UnknownLastChangedException(String errorMsg)
+    {
+        super(errorMsg);
+    }
+}
-- 
GitLab