From dd3f1b3d3a2f10f963aa96ddb8e378ae3f0f9d81 Mon Sep 17 00:00:00 2001
From: brinn <brinn>
Date: Tue, 12 Aug 2008 19:41:55 +0000
Subject: [PATCH] add: methods for checking whether files, directories or paths
 are accessible (from FileUtilities) [LMS-472] Solve performance problem of
 BDS dataset creation and process triggering on trunk merged from branch
 8.04.x, improvements for 8.04.3

SVN: 7832
---
 .../common/filesystem/FileOperations.java     | 30 ++++++++++
 .../common/filesystem/IFileOperations.java    | 55 +++++++++++++++++++
 2 files changed, 85 insertions(+)

diff --git a/common/source/java/ch/systemsx/cisd/common/filesystem/FileOperations.java b/common/source/java/ch/systemsx/cisd/common/filesystem/FileOperations.java
index 16341d67ab2..0242ce5e5cc 100644
--- a/common/source/java/ch/systemsx/cisd/common/filesystem/FileOperations.java
+++ b/common/source/java/ch/systemsx/cisd/common/filesystem/FileOperations.java
@@ -310,6 +310,36 @@ public class FileOperations implements IFileOperations
         return FileUtilities.listFilesAndDirectories(directory, recursive, observerOrNull);
     }
 
+    public String checkPathFullyAccessible(File path, String kindOfPath)
+    {
+        return FileUtilities.checkPathFullyAccessible(path, kindOfPath);
+    }
+
+    public String checkPathReadAccessible(File path, String kindOfPath)
+    {
+        return FileUtilities.checkPathReadAccessible(path, kindOfPath);
+    }
+
+    public String checkDirectoryFullyAccessible(File directory, String kindOfDirectory)
+    {
+        return FileUtilities.checkDirectoryFullyAccessible(directory, kindOfDirectory);
+    }
+
+    public String checkDirectoryReadAccessible(File directory, String kindOfDirectory)
+    {
+        return FileUtilities.checkDirectoryReadAccessible(directory, kindOfDirectory);
+    }
+
+    public String checkFileFullyAccessible(File file, String kindOfFile)
+    {
+        return FileUtilities.checkFileFullyAccessible(file, kindOfFile);
+    }
+
+    public String checkFileReadAccessible(File file, String kindOfFile)
+    {
+        return FileUtilities.checkFileReadAccessible(file, kindOfFile);
+    }
+
     public void touch(File file) throws WrappedIOException
     {
         try
diff --git a/common/source/java/ch/systemsx/cisd/common/filesystem/IFileOperations.java b/common/source/java/ch/systemsx/cisd/common/filesystem/IFileOperations.java
index 7a8695fc067..458d304bf5d 100644
--- a/common/source/java/ch/systemsx/cisd/common/filesystem/IFileOperations.java
+++ b/common/source/java/ch/systemsx/cisd/common/filesystem/IFileOperations.java
@@ -189,6 +189,61 @@ public interface IFileOperations extends IFileRemover
      */
     public List<File> listFilesAndDirectories(File directory, boolean recursive);
 
+    /**
+     * Checks whether a <var>path</var> of some <var>kind</var> is fully accessible to the program.
+     * 
+     * @param kindOfPath description of given <var>path</var>. Mainly used for error messages.
+     * @return <code>null</code> if the <var>directory</var> is fully accessible and an error
+     *         message describing the problem with the <var>directory</var> otherwise.
+     */
+    public String checkPathFullyAccessible(final File path, final String kindOfPath);
+
+    /**
+     * Checks whether a <var>path</var> of some <var>kind</var> is accessible for reading to the
+     * program.
+     * 
+     * @param kindOfPath description of given <var>path</var>. Mainly used for error messages.
+     * @return <code>null</code> if the <var>directory</var> is fully accessible and an error
+     *         message describing the problem with the <var>directory</var> otherwise.
+     */
+    public String checkPathReadAccessible(final File path, final String kindOfPath);
+
+    /**
+     * Checks whether a <var>directory</var> of some <var>kind</var> is fully accessible to the
+     * program (it's a directory, you can read and write in it)
+     * 
+     * @return <code>null</code> if the <var>directory</var> is fully accessible and an error
+     *         message describing the problem with the <var>directory</var> otherwise.
+     */
+    public String checkDirectoryFullyAccessible(final File directory, final String kindOfDirectory);
+
+    /**
+     * Checks whether a <var>directory</var> of some <var>kind</var> is accessible for reading to
+     * the program (it's a directory, you can read and write in it)
+     * 
+     * @return <code>null</code> if the <var>directory</var> is accessible for reading and an error
+     *         message describing the problem with the <var>directory</var> otherwise.
+     */
+    public String checkDirectoryReadAccessible(final File directory, final String kindOfDirectory);
+
+    /**
+     * Checks whether a <var>file</var> of some <var>kindOfFile</var> is accessible for reading to
+     * the program (so it's a file and you can read it)
+     * 
+     * @return <code>null</code> if the <var>file</var> is accessible to reading and an error
+     *         message describing the problem with the <var>file</var> otherwise.
+     */
+    public String checkFileReadAccessible(final File file, final String kindOfFile);
+
+    /**
+     * Checks whether a <var>file</var> of some <var>kindOfFile</var> is accessible for reading and
+     * writing to the program (so it's a file and you can read and write it)
+     * 
+     * @return <code>null</code> if the <var>file</var> is fully accessible and an error message
+     *         describing the problem with the <var>file</var> otherwise.
+     */
+    public String checkFileFullyAccessible(final File file, final String kindOfFile);
+
     /**
      * Sets the file's last modification time to the current time without changing the content. If
      * the file does not exist, create it empty.
-- 
GitLab