當前位置: 首頁>>代碼示例>>Java>>正文


Java AutoDetectParser.getDetector方法代碼示例

本文整理匯總了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) {
            ;
        }
    }
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:22,代碼來源:TikaUtil.java

示例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);
}
 
開發者ID:reportportal,項目名稱:client-java-core,代碼行數:19,代碼來源:ImageConverter.java

示例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;
}
 
開發者ID:U-QASAR,項目名稱:u-qasar.platform,代碼行數:10,代碼來源:FileUploadUtil.java

示例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);
	}
}
 
開發者ID:SHAF-WORK,項目名稱:shaf,代碼行數:16,代碼來源:AbstractStorageDriver.java


注:本文中的org.apache.tika.parser.AutoDetectParser.getDetector方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。