org.apache.tika.parser.Parser.getSupportedTypes()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(193)

本文整理了Java中org.apache.tika.parser.Parser.getSupportedTypes()方法的一些代码示例,展示了Parser.getSupportedTypes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.getSupportedTypes()方法的具体详情如下:
包路径:org.apache.tika.parser.Parser
类名称:Parser
方法名:getSupportedTypes

Parser.getSupportedTypes介绍

[英]Returns the set of media types supported by this parser when used with the given parse context.
[中]返回与给定解析上下文一起使用时此解析器支持的媒体类型集。

代码示例

代码示例来源:origin: apache/tika

/**
 * Delegates the method call to the decorated parser. Subclasses should
 * override this method (and use <code>super.getSupportedTypes()</code>
 * to invoke the decorated parser) to implement extra decoration.
 */
public Set<MediaType> getSupportedTypes(ParseContext context) {
  return parser.getSupportedTypes(context);
}

代码示例来源:origin: apache/tika

public Set<MediaType> getSupportedTypes(ParseContext context) {
  return parser.getSupportedTypes(context);
}

代码示例来源:origin: apache/tika

public Set<MediaType> getSupportedTypes(ParseContext context) {
  return parser.getSupportedTypes(context);
}

代码示例来源:origin: apache/tika

public Set<MediaType> getSupportedTypes(ParseContext parseContext) {
  return parser.getSupportedTypes(parseContext);
}

代码示例来源:origin: apache/tika

public Map<MediaType, Parser> getParsers(ParseContext context) {
  Map<MediaType, Parser> map = new HashMap<MediaType, Parser>();
  for (Parser parser : parsers) {
    for (MediaType type : parser.getSupportedTypes(context)) {
      map.put(registry.normalize(type), parser);
    }
  }
  return map;
}

代码示例来源:origin: apache/tika

@Override
public Set<MediaType> getSupportedTypes(ParseContext context) {
  return getWrappedParser().getSupportedTypes(context);
}

代码示例来源:origin: apache/tika

public AbstractMultipleParser(MediaTypeRegistry registry, MetadataPolicy policy,
               Collection<? extends Parser> parsers) {
  this.policy = policy;
  this.parsers = parsers;
  this.registry = registry;
  
  // TODO Only offer those in common to several/all parser
  // TODO Some sort of specialisation / subtype support
  this.offeredTypes = new HashSet<>();
  for (Parser parser : parsers) {
    offeredTypes.addAll(
        parser.getSupportedTypes(new ParseContext())
    );
  }
}

代码示例来源:origin: apache/tika

public Set<MediaType> getSupportedTypes(ParseContext context) {
  return getDelegateParser(context).getSupportedTypes(context);
}

代码示例来源:origin: apache/tika

new HashMap<MediaType, List<Parser>>();
for (Parser parser : parsers) {
  for (MediaType type : parser.getSupportedTypes(context)) {
    MediaType canonicalType = registry.normalize(type);
    if (types.containsKey(canonicalType)) {

代码示例来源:origin: apache/tika

private ParserDetails(Parser p) {
    if (p instanceof ParserDecorator) {
      isDecorated = true;
      decoratedBy = ((ParserDecorator)p).getDecorationName();
      p = ((ParserDecorator)p).getWrappedParser();
    }
    className = p.getClass().getName();
    shortName = className.substring(className.lastIndexOf('.') + 1);
    if (p instanceof CompositeParser) {
      isComposite = true;
      supportedTypes = Collections.emptySet();
      // Get the unique set of child parsers
      Set<Parser> children = new HashSet<Parser>(
          ((CompositeParser) p).getParsers(EMPTY_PC).values());
      // Sort it by class name
      childParsers = new ArrayList<Parser>(children);
      Collections.sort(childParsers, new Comparator<Parser>() {                    @Override
        public int compare(Parser p1, Parser p2) {
          return p1.getClass().getName().compareTo(p2.getClass().getName());
        }
      });
    } else {
      supportedTypes = p.getSupportedTypes(EMPTY_PC);
    }
  }
}

代码示例来源:origin: apache/tika

public boolean isSupported(TikaInputStream input) throws IOException {
  MediaType type = detector.detect(input, new Metadata());
  return parser.getSupportedTypes(new ParseContext()).contains(type);
}

代码示例来源:origin: apache/tika

addedTypes.addAll(types);
for (MediaType type : parser.getSupportedTypes(context)) {
  if (! types.contains(type)) {
    excludedTypes.add(type);
addedTypes.addAll(parser.getSupportedTypes(context));

代码示例来源:origin: apache/tika

@Override
public Map<MediaType, Parser> getParsers(ParseContext context) {
  Map<MediaType, Parser> map = super.getParsers(context);
  if (loader != null) {
    // Add dynamic parser service (they always override static ones)
    MediaTypeRegistry registry = getMediaTypeRegistry();
    List<Parser> parsers =
        loader.loadDynamicServiceProviders(Parser.class);
    Collections.reverse(parsers); // best parser last
    for (Parser parser : parsers) {
      for (MediaType type : parser.getSupportedTypes(context)) {
        map.put(registry.normalize(type), parser);
      }
    }
  }
  return map;
}

代码示例来源:origin: apache/tika

if (apt) System.out.println();
if (includeMimeTypes && !isComposite) {
  for (MediaType mt : p.getSupportedTypes(context)) {
    System.out.println(indent(i + 3) + ((apt) ? "* " : "") + mt);
    if (apt) System.out.println();

代码示例来源:origin: apache/tika

types = p.getSupportedTypes(context);
assertEquals(1, types.size());
assertEquals(types.toString(), true, types.contains(MediaType.TEXT_PLAIN));
types = p.getSupportedTypes(context);
assertEquals(1, types.size());
assertEquals(types.toString(), true, types.contains(MediaType.TEXT_PLAIN));
types = p.getSupportedTypes(context);
assertEquals(0, types.size());
types = p.getSupportedTypes(context);
assertEquals(1, types.size());
assertEquals(types.toString(), true, types.contains(MediaType.OCTET_STREAM));
types = p.getSupportedTypes(context);
assertEquals(1, types.size());
assertEquals(types.toString(), true, types.contains(MediaType.OCTET_STREAM));

代码示例来源:origin: org.apache.tika/tika-core

/**
 * Delegates the method call to the decorated parser. Subclasses should
 * override this method (and use <code>super.getSupportedTypes()</code>
 * to invoke the decorated parser) to implement extra decoration.
 */
public Set<MediaType> getSupportedTypes(ParseContext context) {
  return parser.getSupportedTypes(context);
}

代码示例来源:origin: apache/tika

assertTrue(p.toString(), p instanceof ParserDecorator);
  assertEquals(EmptyParser.class, ((ParserDecorator)p).getWrappedParser().getClass());
  assertEquals("hello/world", p.getSupportedTypes(null).iterator().next().toString());
  assertEquals("fail/world", p.getSupportedTypes(null).iterator().next().toString());
} catch (TikaException e) {
  fail("Unexpected TikaException: " + e);

代码示例来源:origin: apache/tika

assertTrue(p.toString(), p instanceof ParserDecorator);
  assertEquals(EmptyParser.class, ((ParserDecorator)p).getWrappedParser().getClass());
  assertEquals("hello/world", p.getSupportedTypes(null).iterator().next().toString());
} catch (TikaException e) {
  fail("Unexpected TikaException: " + e);

代码示例来源:origin: apache/tika

Set<MediaType> types = p.getSupportedTypes(context);
assertEquals(2, types.size());
assertEquals(types.toString(), true, types.contains(MediaType.TEXT_PLAIN));

代码示例来源:origin: org.apache.tika/tika-core

public Map<MediaType, Parser> getParsers(ParseContext context) {
  Map<MediaType, Parser> map = new HashMap<MediaType, Parser>();
  for (Parser parser : parsers) {
    for (MediaType type : parser.getSupportedTypes(context)) {
      map.put(registry.normalize(type), parser);
    }
  }
  return map;
}

相关文章