001    /* ImageInputStreamSpi.java -- Service provider for image input streams.
002       Copyright (C) 2004, 2005  Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package javax.imageio.spi;
040    
041    import java.io.File;
042    import java.io.IOException;
043    
044    import javax.imageio.stream.ImageInputStream;
045    
046    /**
047     * An abstract superclass for service providers that create
048     * {@linkplain javax.imageio.stream.ImageInputStream image input
049     * streams} for a file, URL, byte array or any other source.
050     *
051     * @since 1.4
052     *
053     * @author Sascha Brawer (brawer@dandelis.ch)
054     */
055    public abstract class ImageInputStreamSpi
056      extends IIOServiceProvider
057    {
058      /**
059       * Indicates which kind of input is processable by the streams
060       * created by {@link #createInputStreamInstance(Object)}.
061       */
062      protected Class<?> inputClass;
063    
064    
065      /**
066       * Constructs a service provider for image input streams, given no
067       * parameters. It is up to the sub-class to set {@link #vendorName},
068       * {@link #version} and {@link #inputClass} to non-null values.
069       */
070      protected ImageInputStreamSpi()
071      {
072      }
073    
074    
075      /**
076       * Constructs a service provider for image input streams, given the
077       * vendor name and a version string.
078       *
079       * @throws IllegalArgumentException if <code>vendorName</code>
080       * or <code>version</code> is <code>null</code>.
081       */
082      public ImageInputStreamSpi(String vendorName, String version,
083                                 Class<?> inputClass)
084      {
085        super(vendorName, version);
086        this.inputClass = inputClass;
087      }
088    
089    
090      /**
091       * Determines which kind of input is processable by the streams
092       * created by {@link #createInputStreamInstance(Object)}.
093       */
094      public Class<?> getInputClass()
095      {
096        return inputClass;
097      }
098    
099    
100      /**
101       * Determines whether <code>ImageInputStreams</code> created
102       * by this service provider benefit from using a cache file.
103       *
104       * <p>The default behavior is to return <code>false</code>.
105       *
106       * @return <code>true</code> if the created streams are faster or
107       * need less memory when a cache file is being used;
108       * <code>false</code> if no positive effect results from the cache
109       * file.
110       */
111      public boolean canUseCacheFile()
112      {
113        return false;
114      }
115    
116    
117      /**
118       * Determines whether <code>ImageInputStreams</code> created
119       * by this service provider require the use of a cache file.
120       *
121       * <p>The default behavior is to return <code>false</code>.
122       *
123       * @return <code>true</code> if the created streams can only work
124       * when a cache file is being used; <code>false</code> if no cache
125       * file is needed.
126       */
127      public boolean needsCacheFile()
128      {
129        return false;
130      }
131    
132    
133      public abstract ImageInputStream createInputStreamInstance(Object input,
134                                                                 boolean useCache,
135                                                                 File cacheDir)
136        throws IOException;
137    
138    
139      public ImageInputStream createInputStreamInstance(Object input)
140        throws IOException
141      {
142        return createInputStreamInstance(input, canUseCacheFile(), null);
143      }
144    }