From 78e8c6f3e5d3f3b0928b7c5ce1253dad934f1345 Mon Sep 17 00:00:00 2001 From: reger Date: Sun, 11 Oct 2015 01:23:52 +0200 Subject: [PATCH] refactor special handling (static override) of SUPPORTED_EXTENSIONS/MIME_TYPES not used for genericImageParser --- .../parser/images/genericImageParser.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/source/net/yacy/document/parser/images/genericImageParser.java b/source/net/yacy/document/parser/images/genericImageParser.java index c6370f00b..74e04f779 100644 --- a/source/net/yacy/document/parser/images/genericImageParser.java +++ b/source/net/yacy/document/parser/images/genericImageParser.java @@ -65,30 +65,25 @@ import com.drew.metadata.Metadata; import com.drew.metadata.Tag; import com.drew.metadata.exif.GpsDirectory; +/** + * Parser for images, bmp and jpeg and all supported by the Java Image I/O API + * 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 + */ public class genericImageParser extends AbstractParser implements Parser { - /** - * a list of mime types that are supported by this parser class - * @see #getSupportedMimeTypes() - */ - public static final Set SUPPORTED_MIME_TYPES = new HashSet(); - public static final Set SUPPORTED_EXTENSIONS = new HashSet(); - static { + public genericImageParser() { + super("Generic Image Parser"); + SUPPORTED_EXTENSIONS.add("bmp"); - // 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.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() { - super("Generic Image Parser"); - } - @Override public Document[] parse( final AnchorURL location, @@ -130,7 +125,8 @@ public class genericImageParser extends AbstractParser implements Parser { try { b = FileUtils.read(source); // check jpeg file signature (magic number FF D8 FF) - if ((b[0] != (byte) 0xFF) // cast to signed byte (-1) + if (b.length < 3 + || (b[0] != (byte) 0xFF) // cast to signed byte (-1) || (b[1] != (byte) 0xD8) //cast to signed byte (-40) || (b[2] != (byte) 0xFF)) { throw new Parser.Failure("File has no jpeg signature", location); @@ -232,7 +228,7 @@ public class genericImageParser extends AbstractParser implements Parser { return SUPPORTED_EXTENSIONS; } - public static ImageInfo parseJavaImage( + private ImageInfo parseJavaImage( final AnchorURL location, final InputStream sourceStream) throws Parser.Failure { BufferedImage image = null; @@ -247,7 +243,7 @@ public class genericImageParser extends AbstractParser implements Parser { return parseJavaImage(location, image); } - public static ImageInfo parseJavaImage( + private ImageInfo parseJavaImage( final AnchorURL location, final BufferedImage image) { final ImageInfo ii = new ImageInfo(location); @@ -284,7 +280,7 @@ public class genericImageParser extends AbstractParser implements Parser { return ii; } - public static class ImageInfo { + private class ImageInfo { public AnchorURL location; public BufferedImage image; public StringBuilder info;