...
Code Block | ||||
---|---|---|---|---|
| ||||
public static boolean checkMetaData(File f, String getContentType) { InputStream is = null; try { try (InputStream is = new FileInputStream(f)); { ContentHandler contenthandler = new BodyContentHandler(); Metadata metadata = new Metadata(); metadata.set(Metadata.RESOURCE_NAME_KEY, f.getName()); Parser parser = new AutoDetectParser(); parser.parse(is, contenthandler, metadata, new ParseContext()); if (metadata.get(Metadata.CONTENT_TYPE).equalsIgnoreCase(getContentType)) { return true; } else { return false; } } catch (Exception e) { e.printStackTrace(); return false; } finally { if (is != null) { try { is.close(); } catch (IOException e) { // handle error } }return false; } } |
The AutoDetectParser
selects the best available parser based on the content type of file to be parsed.
...