GeoTools
  1. GeoTools
  2. GEOT-3041

Add Utiltities method to DataUtilities class

    Details

    • Type: Wish Wish
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.6.3
    • Fix Version/s: 2.6.4, 2.7-M0
    • Component/s: main
    • Labels:
      None

      Description

      Some modules involving data I/O usually perform several required checks before performing input/output operations.
      As an instance, they check if a specified file exists/can be read, if a specified path refers to an existing/readable directory, if a specified file is of a specific supported type.
      For this reason it will be useful to add some utilities method to the DataUtilities class:

      public static boolean checkFileReadable(final File file, final Logger logger):
      Checks that a File is a real file, exists and is readable. An optional logger (which can be null) can be specified to get fine logging details.

      public static String checkDirectory(String directoryPath)
      Checks that the provided directory path refers to an existing/readable directory.

      public static IOFileFilter excludeFilters(final IOFileFilter inputFilter, IOFileFilter... filters)
      Returns a IOFileFilter obtained by excluding from the first input filter argument, the additional filter rguments.

      public static IOFileFilter includeFilters(final IOFileFilter inputFilter, IOFileFilter... filters)
      Returns a IOFileFilter obtained by adding to the first input filter argument, the additional filter arguments.

      Note that some of these new methods leverage on commons-io and then that dependency should be added to the pom.

      The attached patch will allow to add the methods and dependency.

      1. gt-main.patch
        6 kB
        Daniele Romagnoli
      2. gt-main-2.patch
        30 kB
        Jody Garnett

        Activity

        Hide
        Jody Garnett added a comment -
        That seems fine; what is the commons-io dependency used for?
        Show
        Jody Garnett added a comment - That seems fine; what is the commons-io dependency used for?
        Hide
        Daniele Romagnoli added a comment -
        Hi Jody,
        these methods use:

        import org.apache.commons.io.FilenameUtils;
        it allows Path extraction and normalization (/test/path/to/../../folder/ -->NORMALIZE--> /test/folder/)
        http://commons.apache.org/io/api-1.2/org/apache/commons/io/FilenameUtils

        import org.apache.commons.io.filefilter.FileFilterUtils;
        import org.apache.commons.io.filefilter.IOFileFilter;
        They allow to leverage on File Filters. Once you defined a custom file filter by excluding/including (not/and/or) FileFilters, you can scan a folder in order to get only the files satisfying the filtering rules. (As an instance, exclude *.TXT, *.svn, *.lock, include *.tif, *.JPG, ...)
        Show
        Daniele Romagnoli added a comment - Hi Jody, these methods use: import org.apache.commons.io.FilenameUtils; it allows Path extraction and normalization (/test/path/to/../../folder/ -->NORMALIZE--> /test/folder/) http://commons.apache.org/io/api-1.2/org/apache/commons/io/FilenameUtils import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.commons.io.filefilter.IOFileFilter; They allow to leverage on File Filters. Once you defined a custom file filter by excluding/including (not/and/or) FileFilters, you can scan a folder in order to get only the files satisfying the filtering rules. (As an instance, exclude *.TXT, *.svn, *.lock, include *.tif, *.JPG, ...)
        Hide
        Jody Garnett added a comment -
        Here is the list of things using commons-io:
        gt-coveragetools
        gt-directory
        gt-gmlparsing
        gt-imagemosaic
        gt-imagepyramid
        gt-jp2k
        gt-xsd-gml3

        So nothing "core", but still a fair number.

        Note the Commons-IO path handling code was deprecated; resulting in a us creating a few of the methods already existing in DataUtilities; if we could isolate your use of commons io perhaps we could lose a dependency.

        So while I cannot accept your patch without a test case; adding utility methods is a good idea and I don't see a problem with the suggested methods.
        Show
        Jody Garnett added a comment - Here is the list of things using commons-io: gt-coveragetools gt-directory gt-gmlparsing gt-imagemosaic gt-imagepyramid gt-jp2k gt-xsd-gml3 So nothing "core", but still a fair number. Note the Commons-IO path handling code was deprecated; resulting in a us creating a few of the methods already existing in DataUtilities; if we could isolate your use of commons io perhaps we could lose a dependency. So while I cannot accept your patch without a test case; adding utility methods is a good idea and I don't see a problem with the suggested methods.
        Hide
        Jody Garnett added a comment -
        Created some test cases; and do not find the use of commons-io to be useful; have a look at the attached patch and let me know what you think.
        Show
        Jody Garnett added a comment - Created some test cases; and do not find the use of commons-io to be useful; have a look at the attached patch and let me know what you think.
        Hide
        Jody Garnett added a comment -
        added test cases; removed commons-io dependency.
        Show
        Jody Garnett added a comment - added test cases; removed commons-io dependency.

          People

          • Assignee:
            Jody Garnett
            Reporter:
            Daniele Romagnoli
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: