31 import java.io.FileNotFoundException; 32 33 public class FileImageSource extends InputStreamImageSource { 34 String imagefile; 35 36 public FileImageSource(String filename) { 37 SecurityManager security = System.getSecurityManager(); 38 if (security != null) { 39 security.checkRead(filename); 40 } 41 imagefile = filename; 42 } 43 44 final boolean checkSecurity(Object context, boolean quiet) { 45 // File based images only ever need to be checked statically 46 // when the image is retrieved from the cache. 47 return true; 48 } 49 50 protected ImageDecoder getDecoder() { 51 InputStream is; 52 try { 53 is = new BufferedInputStream(new FileInputStream(imagefile)); 54 } catch (FileNotFoundException e) { 55 return null; 56 } 57 // Don't believe the file suffix - many users don't know what 58 // kind of image they have and guess wrong... 59 /* 60 int suffixpos = imagefile.lastIndexOf('.'); 61 if (suffixpos >= 0) { 62 String suffix = imagefile.substring(suffixpos+1).toLowerCase(); 63 if (suffix.equals("gif")) { 64 return new GifImageDecoder(this, is); 65 } else if (suffix.equals("jpeg") || suffix.equals("jpg") || 66 suffix.equals("jpe") || suffix.equals("jfif")) { 67 return new JPEGImageDecoder(this, is); 68 } else if (suffix.equals("xbm")) { 69 return new XbmImageDecoder(this, is); 70 } | 31 import java.io.FileNotFoundException; 32 33 public class FileImageSource extends InputStreamImageSource { 34 String imagefile; 35 36 public FileImageSource(String filename) { 37 SecurityManager security = System.getSecurityManager(); 38 if (security != null) { 39 security.checkRead(filename); 40 } 41 imagefile = filename; 42 } 43 44 final boolean checkSecurity(Object context, boolean quiet) { 45 // File based images only ever need to be checked statically 46 // when the image is retrieved from the cache. 47 return true; 48 } 49 50 protected ImageDecoder getDecoder() { 51 if (imagefile == null) { 52 return null; 53 } 54 55 InputStream is; 56 try { 57 is = new BufferedInputStream(new FileInputStream(imagefile)); 58 } catch (FileNotFoundException e) { 59 return null; 60 } 61 // Don't believe the file suffix - many users don't know what 62 // kind of image they have and guess wrong... 63 /* 64 int suffixpos = imagefile.lastIndexOf('.'); 65 if (suffixpos >= 0) { 66 String suffix = imagefile.substring(suffixpos+1).toLowerCase(); 67 if (suffix.equals("gif")) { 68 return new GifImageDecoder(this, is); 69 } else if (suffix.equals("jpeg") || suffix.equals("jpg") || 70 suffix.equals("jpe") || suffix.equals("jfif")) { 71 return new JPEGImageDecoder(this, is); 72 } else if (suffix.equals("xbm")) { 73 return new XbmImageDecoder(this, is); 74 } |