public synchronized String getMimeType() throws IOException { if (fMimeType == null) { IContentAdapter content = fResource.getAdapter(IContentAdapter.class); if (content.exists()) { fMimeType = getMimeTypeFromProperties(); if (fMimeType == null) { fMimeType = getMimeTypeByFileName(); if (fMimeType == null) { fMimeType = getMimeTypeByContent(); } } } } return fMimeType; }
protected String getMimeTypeByContent() throws IOException { IContentAdapter content = fResource.getAdapter(IContentAdapter.class); InputStream input = content.getContentInput(); try { if (!input.markSupported()) { input = new BufferedInputStream(input); } String mimeType = fDetector.getMimeType(input); if (mimeType != null) { int idx = mimeType.lastIndexOf(';'); if (idx > 0) { mimeType = mimeType.substring(0, idx); } } return mimeType; } finally { input.close(); } }