On Mon, Feb 9, 2015, at 06:52 PM, Nick Burch wrote:
> Would you anticipate adding these additional mimetypes once, when getting
> your Tika Config object, or do you forsee wanting to add them on the fly?
>
For my use case, adding once at startup is fine.
> I'm not sure that'll work, I'm not sure the detectors list can be
> modified
> that. What happens if you get a default TikaConfig object, grab the
> normal
> detectors from that, build your custom one, then create a
> CompositeDetector from that list + new one, and use that
> CompositeDetector
> from then on?
That worked great! Thanks for the tip. I didn't use the TikaConfig
because I couldn't see how to get a list of detectors from the config.
Here's the code:
final byte[] magicBytes = {'a', 'b', 'c'};
MediaType customType = new MediaType("application", "custom");
Detector customDetector = new MagicDetector(customType, magicBytes);
DefaultDetector defaultDetector = new DefaultDetector();
List<Detector> detectors = defaultDetectors.getDetectors();
detectors.add(customDetector);
CompositeDetector detector = new CompositeDetector(detectors);
Metadata metadata = new Metadata();
MediaType mediaType = detector.detect(stream, metadata);
System.out.println(mediaType.toString());
Thanks!
silverchange