home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / awt / image / FileImageSource.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  2.2 KB  |  66 lines

  1. /*
  2.  * @(#)FileImageSource.java    1.9 95/12/14 Jim Graham
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.awt.image;
  21.  
  22. import java.io.InputStream;
  23. import java.io.FileInputStream;
  24. import java.io.BufferedInputStream;
  25. import java.io.FileNotFoundException;
  26.  
  27. public class FileImageSource extends InputStreamImageSource {
  28.     String imagefile;
  29.  
  30.     public FileImageSource(String filename) {
  31.     SecurityManager security = System.getSecurityManager();
  32.     if (security != null) {
  33.         security.checkRead(filename);
  34.     }
  35.     imagefile = filename;
  36.     }
  37.  
  38.     final boolean checkSecurity(Object context, boolean quiet) {
  39.     // File based images only ever need to be checked statically
  40.     // when the image is retrieved from the cache.
  41.     return true;
  42.     }
  43.  
  44.     protected ImageDecoder getDecoder() {
  45.     InputStream is;
  46.     try {
  47.         is = new BufferedInputStream(new FileInputStream(imagefile));
  48.     } catch (FileNotFoundException e) {
  49.         return null;
  50.     }
  51.     int suffixpos = imagefile.lastIndexOf('.');
  52.     if (suffixpos >= 0) {
  53.         String suffix = imagefile.substring(suffixpos+1).toLowerCase();
  54.         if (suffix.equals("gif")) {
  55.         return new GifImageDecoder(this, is);
  56.         } else if (suffix.equals("jpeg") || suffix.equals("jpg") ||
  57.                suffix.equals("jpe") || suffix.equals("jfif")) {
  58.         return new JPEGImageDecoder(this, is);
  59.         } else if (suffix.equals("xbm")) {
  60.         return new XbmImageDecoder(this, is);
  61.         }
  62.     }
  63.     return getDecoder(is);
  64.     }
  65. }
  66.