本文整理汇总了Java中org.apache.tika.parser.AutoDetectParser.getDetector方法的典型用法代码示例。如果您正苦于以下问题:Java AutoDetectParser.getDetector方法的具体用法?Java AutoDetectParser.getDetector怎么用?Java AutoDetectParser.getDetector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tika.parser.AutoDetectParser
的用法示例。
在下文中一共展示了AutoDetectParser.getDetector方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMediaType
import org.apache.tika.parser.AutoDetectParser; //导入方法依赖的package包/类
/**
* Finds media type (through Apache Tika library), based on filename and magic numbers.
* @throws IOException
*/
public static MediaType findMediaType(InputStream is, String fileName) throws IOException {
BufferedInputStream bis = new BufferedInputStream(is);
try {
AutoDetectParser parser = new AutoDetectParser();
Detector detector = parser.getDetector();
Metadata md = new Metadata();
md.add(Metadata.RESOURCE_NAME_KEY, fileName);
MediaType mediaType = detector.detect(bis, md);
return mediaType;
} finally {
try {
bis.close();
} catch (IOException e) {
;
}
}
}
示例2: isImage
import org.apache.tika.parser.AutoDetectParser; //导入方法依赖的package包/类
/**
* Check is input file is image
*
* @param fileContent
*/
public static boolean isImage(byte[] fileContent) {
AutoDetectParser parser = new AutoDetectParser();
Detector detector = parser.getDetector();
MediaType mediaType;
try {
mediaType = detector.detect(TikaInputStream.get(fileContent), new Metadata());
} catch (Exception e) {
logger.error("Unable to read file content.", e);
throw new InternalReportPortalClientException("Unable to read file content.", e);
}
return mediaType.toString().contains(IMAGE_TYPE);
}
示例3: getMimeType
import org.apache.tika.parser.AutoDetectParser; //导入方法依赖的package包/类
private static MediaType getMimeType(InputStream stream, Metadata md) throws IOException {
MediaType mediaType;
try (BufferedInputStream bis = new BufferedInputStream(stream)) {
AutoDetectParser parser = new AutoDetectParser();
Detector detector = parser.getDetector();
mediaType = detector.detect(bis, md);
}
return mediaType;
}
示例4: getType
import org.apache.tika.parser.AutoDetectParser; //导入方法依赖的package包/类
/**
* Returns a data type.
*/
public final MediaType getType(final String alias)
throws StorageIOException{
try (InputStream in = this.getInputStream(alias)) {
AutoDetectParser parser = new AutoDetectParser();
Detector detector = parser.getDetector();
Metadata md = new Metadata();
md.add(Metadata.RESOURCE_NAME_KEY, alias);
return detector.detect(in, md);
} catch (IOException exc) {
throw new StorageIOException(alias, exc);
}
}