Search in sources :

Example 1 with FileTypeDetector

use of java.nio.file.spi.FileTypeDetector in project tika by apache.

the class TikaFileTypeDetectorTest method testMetaInfServicesLoad.

@Test
public final void testMetaInfServicesLoad() throws Exception {
    ServiceLoader<FileTypeDetector> serviceLoader = ServiceLoader.load(FileTypeDetector.class);
    Iterator<FileTypeDetector> iterator = serviceLoader.iterator();
    assertTrue(iterator.hasNext());
    while (iterator.hasNext()) {
        FileTypeDetector fileTypeDetector = iterator.next();
        assertNotNull(fileTypeDetector);
        assertTrue(fileTypeDetector instanceof TikaFileTypeDetector);
    }
}
Also used : FileTypeDetector(java.nio.file.spi.FileTypeDetector) Test(org.junit.Test)

Example 2 with FileTypeDetector

use of java.nio.file.spi.FileTypeDetector in project mycore by MyCoRe-Org.

the class MCRContentTypes method probeContentType.

/**
 * Probes the content type of a file.
 *
 * Same as {@link Files#probeContentType(Path)} but uses context class loader.
 * @param path
 *              the path to the file to probe
 * @return The content type of the file, or null if the content type cannot be determined
 * @throws IOException if an I/O error occurs
 */
public static String probeContentType(Path path) throws IOException {
    LOGGER.debug("Probing content type: {}", path);
    for (FileTypeDetector fileTypeDetector : fileTypeDetectors) {
        LOGGER.debug("Using type detector: {}", fileTypeDetector.getClass());
        String contentType = fileTypeDetector.probeContentType(path);
        if (contentType != null) {
            LOGGER.debug("Content type: {}", contentType);
            return contentType;
        }
    }
    return Files.probeContentType(path);
}
Also used : FileTypeDetector(java.nio.file.spi.FileTypeDetector)

Example 3 with FileTypeDetector

use of java.nio.file.spi.FileTypeDetector in project mycore by MyCoRe-Org.

the class MCRContentTypes method getInstalledDetectors.

private static List<FileTypeDetector> getInstalledDetectors() {
    ArrayList<FileTypeDetector> detectors = new ArrayList<>();
    ServiceLoader<FileTypeDetector> serviceLoader = ServiceLoader.load(FileTypeDetector.class);
    for (FileTypeDetector fileTypeDetector : serviceLoader) {
        LOGGER.info("Adding content type detector: {}", fileTypeDetector.getClass());
        detectors.add(fileTypeDetector);
    }
    return detectors;
}
Also used : FileTypeDetector(java.nio.file.spi.FileTypeDetector) ArrayList(java.util.ArrayList)

Aggregations

FileTypeDetector (java.nio.file.spi.FileTypeDetector)3 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1