public MimeTypesImpl() { MimeUtil.registerMimeDetector(MagicMimeMimeDetector.class.getName()); Collection<String> encodings = new HashSet<String>(); encodings.add(StringPool.UTF8); encodings.add(System.getProperty("file.encoding")); EncodingGuesser.setSupportedEncodings(encodings); }
Collection getMimeTypes(final File file) throws MimeException { Collection mimeTypes = new ArrayList(); try { if (!EncodingGuesser.getSupportedEncodings().isEmpty()) { mimeTypes = TextMimeDetector.getMimeTypes(file); } } catch (UnsupportedOperationException ignore) { // The TextMimeDetector will throw this if it decides // the content is not text } for (Iterator it = mimeDetectors.values().iterator(); it.hasNext(); ) { try { MimeDetector md = (MimeDetector) it.next(); mimeTypes.addAll(md.getMimeTypes(file)); } catch (UnsupportedOperationException usoe) { // We ignore this as it indicates that this MimeDetector does not support // Getting mime types from streams } catch (Exception e) { log.error(e.getLocalizedMessage(), e); } } return mimeTypes; }