28
28
import java .net .URLConnection ;
29
29
import java .util .Arrays ;
30
30
import java .util .Collections ;
31
+ import java .util .Comparator ;
31
32
import java .util .Enumeration ;
32
33
import java .util .LinkedHashSet ;
33
34
import java .util .Set ;
@@ -783,15 +784,7 @@ protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> r
783
784
logger .debug ("Searching directory [" + dir .getAbsolutePath () +
784
785
"] for files matching pattern [" + fullPattern + "]" );
785
786
}
786
- File [] dirContents = dir .listFiles ();
787
- if (dirContents == null ) {
788
- if (logger .isWarnEnabled ()) {
789
- logger .warn ("Could not retrieve contents of directory [" + dir .getAbsolutePath () + "]" );
790
- }
791
- return ;
792
- }
793
- Arrays .sort (dirContents );
794
- for (File content : dirContents ) {
787
+ for (File content : listDirectory (dir )) {
795
788
String currPath = StringUtils .replace (content .getAbsolutePath (), File .separator , "/" );
796
789
if (content .isDirectory () && getPathMatcher ().matchStart (fullPattern , currPath + "/" )) {
797
790
if (!content .canRead ()) {
@@ -810,6 +803,25 @@ protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> r
810
803
}
811
804
}
812
805
806
+ /**
807
+ * Determine a sorted list of files in the given directory.
808
+ * @param dir the directory to introspect
809
+ * @return the sorted list of files (by default in alphabetical order)
810
+ * @since 5.1
811
+ * @see File#listFiles()
812
+ */
813
+ protected File [] listDirectory (File dir ) {
814
+ File [] files = dir .listFiles ();
815
+ if (files == null ) {
816
+ if (logger .isWarnEnabled ()) {
817
+ logger .warn ("Could not retrieve contents of directory [" + dir .getAbsolutePath () + "]" );
818
+ }
819
+ return new File [0 ];
820
+ }
821
+ Arrays .sort (files , Comparator .comparing (File ::getName ));
822
+ return files ;
823
+ }
824
+
813
825
814
826
/**
815
827
* Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
0 commit comments