From a69f5358ff04ba1ebe0a1177d5c25c1d53af1399 Mon Sep 17 00:00:00 2001 From: reger Date: Mon, 29 Sep 2014 07:42:51 +0200 Subject: [PATCH] use javax ImageIO getReader to add supported image extension/mime genericImageParser uses javax ImageIO, supported images depend on available plugins for ImageIO package (this is JDK installation specific). Jpeg, png and gif are availabel by default. Tif and others only on avalable plugin (in classpath). Add supported image type dynamically on startup. --- .../parser/images/genericImageParser.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/source/net/yacy/document/parser/images/genericImageParser.java b/source/net/yacy/document/parser/images/genericImageParser.java index 6b358208e..4ecd7f7af 100644 --- a/source/net/yacy/document/parser/images/genericImageParser.java +++ b/source/net/yacy/document/parser/images/genericImageParser.java @@ -35,6 +35,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -76,19 +77,15 @@ public class genericImageParser extends AbstractParser implements Parser { public static final Set SUPPORTED_MIME_TYPES = new HashSet(); public static final Set SUPPORTED_EXTENSIONS = new HashSet(); static { - SUPPORTED_EXTENSIONS.add("png"); - SUPPORTED_EXTENSIONS.add("gif"); - SUPPORTED_EXTENSIONS.add("jpg"); - SUPPORTED_EXTENSIONS.add("jpeg"); - SUPPORTED_EXTENSIONS.add("jpe"); SUPPORTED_EXTENSIONS.add("bmp"); - SUPPORTED_EXTENSIONS.add("tif"); - SUPPORTED_EXTENSIONS.add("tiff"); - SUPPORTED_MIME_TYPES.add("image/png"); - SUPPORTED_MIME_TYPES.add("image/gif"); - SUPPORTED_MIME_TYPES.add("image/jpeg"); - SUPPORTED_MIME_TYPES.add("image/jpg"); // this is in fact a 'wrong' mime type. We leave it here because that is a common error that occurs in the internet frequently + // by default java ImageIO supports bmp, gif, jpg, jpeg, png, wbmp (tif if jai-imageio is in classpath/registered) + // http://download.java.net/media/jai-imageio/javadoc/1.1/overview-summary.html + SUPPORTED_EXTENSIONS.add("jpe"); // not listed in ImageIO extension but sometimes uses for jpeg + SUPPORTED_EXTENSIONS.addAll(Arrays.asList(ImageIO.getReaderFileSuffixes())); + SUPPORTED_MIME_TYPES.add("image/bmp"); + SUPPORTED_MIME_TYPES.add("image/jpg"); // this is in fact a 'wrong' mime type. We leave it here because that is a common error that occurs in the internet frequently + SUPPORTED_MIME_TYPES.addAll(Arrays.asList(ImageIO.getReaderMIMETypes())); } public genericImageParser() { @@ -309,6 +306,22 @@ public class genericImageParser extends AbstractParser implements Parser { public static void main(final String[] args) { + // list support file extension by java ImageIO + String names[] = ImageIO.getReaderFileSuffixes(); + System.out.print("supported file extension:"); + for (int i = 0; i < names.length; ++i) { + System.out.print(" " + names[i]); + } + System.out.println(); + + // list supported mime types of java ImageIO + String mime[] = ImageIO.getReaderMIMETypes(); + System.out.print("supported mime types: "); + for (int i = 0; i < mime.length; ++i) { + System.out.print(" " + mime[i]); + } + System.out.println(); + final File image = new File(args[0]); final genericImageParser parser = new genericImageParser(); AnchorURL uri;