use of org.apache.tika.config.TikaConfig in project mylyn.docs by eclipse.
the class EPUBFileUtil method getMimeType.
/**
* Attempts to figure out the MIME-type for the file.
*
* @param file
* the file to determine MIME-type for
* @return the MIME-type or <code>application/octet-stream</code>
*/
public static String getMimeType(File file) {
try {
if (tika == null) {
tika = new TikaConfig();
}
Metadata metadata = new Metadata();
metadata.set(TikaMetadataKeys.RESOURCE_NAME_KEY, file.getName());
MediaType detect = tika.getDetector().detect(TikaInputStream.get(file), metadata);
return detect.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (TikaException e) {
throw new RuntimeException(e);
}
}
use of org.apache.tika.config.TikaConfig in project jackrabbit by apache.
the class SearchIndex method createParser.
private Parser createParser() {
URL url = null;
if (tikaConfigPath != null) {
File file = new File(tikaConfigPath);
if (file.exists()) {
try {
url = file.toURI().toURL();
} catch (MalformedURLException e) {
log.warn("Invalid Tika configuration path: " + file, e);
}
} else {
ClassLoader loader = SearchIndex.class.getClassLoader();
url = loader.getResource(tikaConfigPath);
}
}
if (url == null) {
url = SearchIndex.class.getResource("tika-config.xml");
}
TikaConfig config = null;
if (url != null) {
try {
config = new TikaConfig(url);
} catch (Exception e) {
log.warn("Tika configuration not available: " + url, e);
}
}
if (config == null) {
config = TikaConfig.getDefaultConfig();
}
if (forkJavaCommand != null) {
ForkParser forkParser = new ForkParser(SearchIndex.class.getClassLoader(), new AutoDetectParser(config));
forkParser.setJavaCommand(forkJavaCommand);
forkParser.setPoolSize(extractorPoolSize);
return forkParser;
} else {
return new AutoDetectParser(config);
}
}
Aggregations