src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java

Print this page

        

@@ -507,6 +507,30 @@
                 return null;
             }
         };
     }
 
+    /**
+     * It accepts a list of file type detectors as the parameter, and return
+     * the first {@code FileTypeDetector} that can find a file's MIME type.
+     * If no detectors can find the MIME type, null is returned.
+     *
+     * @param detectors List of file type detectors.
+     * @return The first detector that finds the file type or null.
+     */
+    final FileTypeDetector chain(final AbstractFileTypeDetector... detectors) {
+        return new AbstractFileTypeDetector() {
+            @Override
+            protected String implProbeContentType(Path file)
+                    throws IOException
+            {
+                for (AbstractFileTypeDetector detector : detectors) {
+                    String result = detector.implProbeContentType(file);
+                    if (result != null && !result.isEmpty()) {
+                        return result;
+                    }
+                }
+                return null;
+            }
+        };
+    }
 }