use of org.codelibs.fess.crawler.exception.MimeTypeException in project fess-crawler by codelibs.
the class MimeTypeHelperImplTest method test_getContentType_null.
public void test_getContentType_null() {
final MimeTypeHelper mimeTypeHelper = container.getComponent("mimeTypeHelper");
final InputStream is = ResourceUtil.getResourceAsStream("test/text1.txt");
try {
mimeTypeHelper.getContentType(null, "");
fail();
} catch (final MimeTypeException e) {
}
try {
mimeTypeHelper.getContentType(is, "");
fail();
} catch (final MimeTypeException e) {
}
assertEquals("text/plain", mimeTypeHelper.getContentType(is, " "));
}
use of org.codelibs.fess.crawler.exception.MimeTypeException in project fess-crawler by codelibs.
the class MimeTypeHelperImpl method getContentType.
@Override
public String getContentType(final InputStream is, final Map<String, String> params) {
final String filename = params.get(TikaMetadataKeys.RESOURCE_NAME_KEY);
if (StringUtil.isEmpty(filename) && is == null) {
throw new MimeTypeException("The filename or input stream is empty.");
}
final Metadata metadata = new Metadata();
metadata.add(TikaMetadataKeys.RESOURCE_NAME_KEY, normalizeFilename(filename));
try {
final MediaType mediaType = mimeTypes.detect(is == null || is.markSupported() ? is : new BufferedInputStream(is), metadata);
return mediaType.getType() + "/" + mediaType.getSubtype();
} catch (final IOException e) {
throw new MimeTypeException("Could not detect a content type.", e);
}
}
Aggregations