home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / sun / awt / image / FileImageSource.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  1.8 KB  |  47 lines

  1. package sun.awt.image;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.InputStream;
  7.  
  8. public class FileImageSource extends InputStreamImageSource {
  9.    String imagefile;
  10.  
  11.    public FileImageSource(String filename) {
  12.       System.getSecurityManager().checkRead(filename);
  13.       this.imagefile = filename;
  14.    }
  15.  
  16.    final boolean checkSecurity(Object context, boolean quiet) {
  17.       return true;
  18.    }
  19.  
  20.    protected ImageDecoder getDecoder() {
  21.       InputStream is;
  22.       try {
  23.          is = new BufferedInputStream(new FileInputStream(this.imagefile));
  24.       } catch (FileNotFoundException var4) {
  25.          return null;
  26.       }
  27.  
  28.       int suffixpos = this.imagefile.lastIndexOf(46);
  29.       if (suffixpos >= 0) {
  30.          String suffix = this.imagefile.substring(suffixpos + 1).toLowerCase();
  31.          if (suffix.equals("gif")) {
  32.             return new GifImageDecoder(this, is);
  33.          }
  34.  
  35.          if (suffix.equals("jpeg") || suffix.equals("jpg") || suffix.equals("jpe") || suffix.equals("jfif")) {
  36.             return new JPEGImageDecoder(this, is);
  37.          }
  38.  
  39.          if (suffix.equals("xbm")) {
  40.             return new XbmImageDecoder(this, is);
  41.          }
  42.       }
  43.  
  44.       return ((InputStreamImageSource)this).getDecoder(is);
  45.    }
  46. }
  47.