TikaFileTypeDetector extends FileTypeDetector { @Override public String probeContentType(Path path) throws IOException { String fileNameDetect = tika.detect(path.toString()); if(!fileNameDetect.equals(MimeTypes.OCTET_STREAM)) { return fileNameDetect; } String fileContentDetect = tika.detect(path); if(!fileContentDetect.equals(MimeTypes.OCTET_STREAM)) { return fileContentDetect; } return null; } TikaFileTypeDetector(); @Override String probeContentType(Path path);  }
@Test public final void testDirectAccess() throws Exception { String contentType = new TikaFileTypeDetector().probeContentType(testDirectory.resolve(TEST_HTML)); assertNotNull(contentType); assertEquals("text/html", contentType); }
@Test public final void testFilesProbeContentTypePathExtension() throws Exception { String contentType = Files.probeContentType(testDirectory.resolve(TEST_HTML)); assertNotNull(contentType); assertEquals("text/html", contentType); }
@Test public final void testFilesProbeContentTypePathUnrecognised() throws Exception { String contentType = Files.probeContentType(testDirectory.resolve(TEST_UNRECOGNISED_EXTENSION)); assertNotNull(contentType); assertEquals("text/html", contentType); }