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.
pull/1/head
reger 11 years ago
parent 8b1ce49ee6
commit a69f5358ff

@ -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<String> SUPPORTED_MIME_TYPES = new HashSet<String>();
public static final Set<String> SUPPORTED_EXTENSIONS = new HashSet<String>();
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;

Loading…
Cancel
Save