Search in sources :

Example 1 with ServiceLoader

use of org.apache.tika.config.ServiceLoader in project tika by apache.

the class ProbabilisticMimeDetectionTestWithTika method setUp.

/** @inheritDoc */
@Before
public void setUp() {
    MimeTypes types = MimeTypes.getDefaultMimeTypes();
    ServiceLoader loader = new ServiceLoader();
    registry = types.getMediaTypeRegistry();
    /*
         * here is an example with the use of the builder to
         * instantiate the object.
         */
    Builder builder = new ProbabilisticMimeDetectionSelector.Builder();
    proSelector = new ProbabilisticMimeDetectionSelector(types, builder.priorMagicFileType(0.5f).priorExtensionFileType(0.5f).priorMetaFileType(0.5f));
    DefaultProbDetector detector = new DefaultProbDetector(proSelector, loader);
    // Use a default Tika, except for our different detector
    tika = new Tika(detector);
}
Also used : ServiceLoader(org.apache.tika.config.ServiceLoader) Builder(org.apache.tika.mime.ProbabilisticMimeDetectionSelector.Builder) DefaultProbDetector(org.apache.tika.detect.DefaultProbDetector) Tika(org.apache.tika.Tika) Before(org.junit.Before)

Example 2 with ServiceLoader

use of org.apache.tika.config.ServiceLoader in project tika by apache.

the class HtmlParserTest method testMultiThreadingEncodingDetection.

@Test
public void testMultiThreadingEncodingDetection() throws Exception {
    List<EncodingDetector> detectors = new ArrayList<>();
    ServiceLoader loader = new ServiceLoader(AutoDetectReader.class.getClassLoader());
    detectors.addAll(loader.loadServiceProviders(EncodingDetector.class));
    for (EncodingDetector detector : detectors) {
        testDetector(detector);
    }
}
Also used : ServiceLoader(org.apache.tika.config.ServiceLoader) EncodingDetector(org.apache.tika.detect.EncodingDetector) AutoDetectReader(org.apache.tika.detect.AutoDetectReader) ArrayList(java.util.ArrayList) Test(org.junit.Test) TikaTest(org.apache.tika.TikaTest)

Aggregations

ServiceLoader (org.apache.tika.config.ServiceLoader)2 ArrayList (java.util.ArrayList)1 Tika (org.apache.tika.Tika)1 TikaTest (org.apache.tika.TikaTest)1 AutoDetectReader (org.apache.tika.detect.AutoDetectReader)1 DefaultProbDetector (org.apache.tika.detect.DefaultProbDetector)1 EncodingDetector (org.apache.tika.detect.EncodingDetector)1 Builder (org.apache.tika.mime.ProbabilisticMimeDetectionSelector.Builder)1 Before (org.junit.Before)1 Test (org.junit.Test)1