Package Torello.Java

Class WritableDirectoryException

  • All Implemented Interfaces:
    java.io.Serializable

    public class WritableDirectoryException
    extends java.lang.RuntimeException
    Used by methods that accept 'target directory' parameters to validate that the parameter's contents actually point to a both valid and writable location on disk.

    This Exception is used to check the "Directory Name" parameters that are passed to classes in this library. It has a check(String dirName) method that will perform a series of tests to ensure that a directory exists on the file-system, and that contents may be written to that directory. When this fails, a consistently worded exception message is provided.
    See Also:
    Serialized Form


    • Method Summary

       
      'static' Exception Check Methods
      Modifier and Type Method
      static void check​(String directory)
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

        🡇    
        public static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.

        Note that Java's java.lang.Exception and java.lang.Error classes implement the Serializable interface, and a warning-free build expects this field be defined here.
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
        public static final long serialVersionUID = 1;
        
      • THROW_ON_ZERO_LENGTH_STRING

        🡅  🡇    
        public static boolean THROW_ON_ZERO_LENGTH_STRING
        This boolean allows a user to decide whether the zero-length String should force an exception throw when passed to this class' check(String) method. When this boolean is set to TRUE, the class will check whether or not the directory named by the String returned by a call to System.getProperty("user.dir") is writable.

        An invocation to method System.getProperty("user.dir") returns a String that contains the current user's home directory. If this directory is writable, then no exception throw shall occur when testing and passing a zero-length String to the 'directory' parameter of the check(String) method.

        When this parameter is set to FALSE, and when a zero-length String is passed to the 'directory' parameter of the 'check(String)' method.

        DEFAULT: The default behavior of method check(String) is to throw an exception whenever the zero-length String is passed.
        Code:
        Exact Field Declaration Expression:
        public static boolean THROW_ON_ZERO_LENGTH_STRING = true;
        
    • Constructor Detail

      • WritableDirectoryException

        🡅  🡇    
        public WritableDirectoryException​(java.lang.String message)
        Constructs a WritableDirectoryException with the specified detail message.
        Parameters:
        message - the detail message.
      • WritableDirectoryException

        🡅  🡇    
        public WritableDirectoryException​(java.lang.String message,
                                          java.lang.Throwable cause)
        Constructs a new exception with the specified detail message and cause.

        NOTE: The detail message associated with cause is not automatically incorporated in this exception's detail message.
        Parameters:
        message - The detail message (which is saved for later retrieval by the Throwable.getMessage() method).
        cause - the cause (which is saved for later retrieval by the Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
      • WritableDirectoryException

        🡅  🡇    
        public WritableDirectoryException​(java.lang.Throwable cause)
        Constructs a new exception with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which typically contains the class and detail message of cause). This constructor is useful for exceptions that are little more than wrappers for other Throwable's.
        Parameters:
        cause - The cause (which is saved for later retrieval by the Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
    • Method Detail

      • check

        🡅    
        public static void check​(java.lang.String directory)
                          throws WritableDirectoryException
        Checks that a directory-name is valid and ready for saving image files.
        Parameters:
        directory - This is the directory-name to be tested.
        Throws:
        java.io.FileNotFoundException - If the named directory does not exist on the file-system.
        java.lang.IllegalArgumentException - If the passed directory exists, but does not name is not the name of an actual directory.
        java.io.IOException - If the JVM is unable to write a temporary file to this directory, then IOException will throw.
        WritableDirectoryException
        Code:
        Exact Method Body:
         if (directory == "")
         {
             if (THROW_ON_ZERO_LENGTH_STRING) throw new WritableDirectoryException(
                 "You have passed the zero-length String to the class " +
                 "WritableDirectoryException's 'check' method.  If this is the desired behavior, " +
                 "there is a configurable, static, boolean named 'THROW_ON_ZERO_LENGTH_STRING' " + 
                 "in this class that should be set to FALSE.  Currently, when the zero-length " +
                 "String is passed here, an exception (this one) is thrown immediately.  If this " +
                 "configuration-boolean were TRUE, the directory checked would be the one " +
                 "returned by a call to System.getProperty(\"user.dir\")"
             );
        
             directory = System.getProperty("user.dir");
         }
        
         File f = new File(directory);
        
         // Make sure that the directory name exists on the file-system.  If not throw exception
         if (! f.exists()) throw new WritableDirectoryException(
             "The directory-name [" + directory + "], that you have passed does not exist, " +
             "or could not be found be the file-system."
         );
        
         // Make sure that the directory-named is actually a directory, not a file, link, etc...
         if (! f.isDirectory()) throw new WritableDirectoryException(
             "The directory-name [" + directory + "], that you have passed was found, but it is " +
             "not a valid directory-name on the file-system."
         );
        
         // Make sure that the directory provided is writable, or throw an exception.
         try
         {
             f = File.createTempFile("test", "tmp", f);
             f.delete();
         }
         catch (IOException ioe)
         {
             throw new WritableDirectoryException(
                 "There was a JavaIOException when attempting to write a file to the directory-name " +
                 '[' + directory + "].  Please see this exception's getCause() throwable for " +
                 "more details.", ioe
             );
         }