Home | History | Annotate | Download | only in spi
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 /**
     18  * @author Rustem V. Rafikov
     19  * @version $Revision: 1.3 $
     20  */
     21 
     22 package javax.imageio.spi;
     23 
     24 import java.io.File;
     25 import java.io.IOException;
     26 import javax.imageio.stream.ImageInputStream;
     27 
     28 /**
     29  * The ImageInputStreamSpi abstract class is a service provider interface (SPI)
     30  * for ImageInputStreams.
     31  *
     32  * @since Android 1.0
     33  */
     34 public abstract class ImageInputStreamSpi extends IIOServiceProvider implements RegisterableService {
     35 
     36     /**
     37      * The input class.
     38      */
     39     protected Class<?> inputClass;
     40 
     41     /**
     42      * Instantiates a new ImageInputStreamSpi.
     43      */
     44     protected ImageInputStreamSpi() {
     45         throw new UnsupportedOperationException("Not supported yet");
     46     }
     47 
     48     /**
     49      * Instantiates a new ImageInputStreamSpi.
     50      *
     51      * @param vendorName
     52      *            the vendor name.
     53      * @param version
     54      *            the version.
     55      * @param inputClass
     56      *            the input class.
     57      */
     58     public ImageInputStreamSpi(String vendorName, String version, Class<?> inputClass) {
     59         super(vendorName, version);
     60         this.inputClass = inputClass;
     61     }
     62 
     63     /**
     64      * Gets an input Class object that represents class or interface that must
     65      * be implemented by an input source.
     66      *
     67      * @return the input class.
     68      */
     69     public Class<?> getInputClass() {
     70         return inputClass;
     71     }
     72 
     73     /**
     74      * Returns true if the ImageInputStream can use a cache file. If this method
     75      * returns false, the value of the useCache parameter of
     76      * createInputStreamInstance will be ignored. The default implementation
     77      * returns false.
     78      *
     79      * @return true, if the ImageInputStream can use a cache file, false
     80      *         otherwise.
     81      */
     82     public boolean canUseCacheFile() {
     83         return false; // -- def
     84     }
     85 
     86     /**
     87      * Returns true if the ImageInputStream implementation requires the use of a
     88      * cache file. The default implementation returns false.
     89      *
     90      * @return true, if the ImageInputStream implementation requires the use of
     91      *         a cache file, false otherwise.
     92      */
     93     public boolean needsCacheFile() {
     94         return false; // def
     95     }
     96 
     97     /**
     98      * Creates the ImageInputStream associated with this service provider. The
     99      * input object should be an instance of the class returned by the
    100      * getInputClass method. This method uses the specified directory for the
    101      * cache file if the useCache parameter is true.
    102      *
    103      * @param input
    104      *            the input Object.
    105      * @param useCache
    106      *            the flag indicating if a cache file is needed or not.
    107      * @param cacheDir
    108      *            the cache directory.
    109      * @return the ImageInputStream.
    110      * @throws IOException
    111      *             if an I/O exception has occurred.
    112      */
    113     public abstract ImageInputStream createInputStreamInstance(Object input, boolean useCache,
    114             File cacheDir) throws IOException;
    115 
    116     /**
    117      * Creates the ImageInputStream associated with this service provider. The
    118      * input object should be an instance of the class returned by getInputClass
    119      * method. This method uses the default system directory for the cache file,
    120      * if it is needed.
    121      *
    122      * @param input
    123      *            the input Object.
    124      * @return the ImageInputStream.
    125      * @throws IOException
    126      *             if an I/O exception has occurred.
    127      */
    128     public ImageInputStream createInputStreamInstance(Object input) throws IOException {
    129         return createInputStreamInstance(input, true, null);
    130     }
    131 }
    132