Path: blob/master/src/java.desktop/share/classes/javax/imageio/spi/ImageInputStreamSpi.java
41155 views
/*1* Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.imageio.spi;2627import java.io.File;28import java.io.IOException;29import javax.imageio.stream.ImageInputStream;3031/**32* The service provider interface (SPI) for33* {@code ImageInputStream}s. For more information on service34* provider interfaces, see the class comment for the35* {@code IIORegistry} class.36*37* <p> This interface allows arbitrary objects to be "wrapped" by38* instances of {@code ImageInputStream}. For example,39* a particular {@code ImageInputStreamSpi} might allow40* a generic {@code InputStream} to be used as an input source;41* another might take input from a {@code URL}.42*43* <p> By treating the creation of {@code ImageInputStream}s as a44* pluggable service, it becomes possible to handle future input45* sources without changing the API. Also, high-performance46* implementations of {@code ImageInputStream} (for example,47* native implementations for a particular platform) can be installed48* and used transparently by applications.49*50* @see IIORegistry51* @see javax.imageio.stream.ImageInputStream52*53*/54public abstract class ImageInputStreamSpi extends IIOServiceProvider {5556/**57* A {@code Class} object indicating the legal object type58* for use by the {@code createInputStreamInstance} method.59*/60protected Class<?> inputClass;6162/**63* Constructs a blank {@code ImageInputStreamSpi}. It is up64* to the subclass to initialize instance variables and/or65* override method implementations in order to provide working66* versions of all methods.67*/68protected ImageInputStreamSpi() {69}7071/**72* Constructs an {@code ImageInputStreamSpi} with a given set73* of values.74*75* @param vendorName the vendor name.76* @param version a version identifier.77* @param inputClass a {@code Class} object indicating the78* legal object type for use by the79* {@code createInputStreamInstance} method.80*81* @exception IllegalArgumentException if {@code vendorName}82* is {@code null}.83* @exception IllegalArgumentException if {@code version}84* is {@code null}.85*/86public ImageInputStreamSpi(String vendorName,87String version,88Class<?> inputClass) {89super(vendorName, version);90this.inputClass = inputClass;91}9293/**94* Returns a {@code Class} object representing the class or95* interface type that must be implemented by an input source in96* order to be "wrapped" in an {@code ImageInputStream} via97* the {@code createInputStreamInstance} method.98*99* <p> Typical return values might include100* {@code InputStream.class} or {@code URL.class}, but101* any class may be used.102*103* @return a {@code Class} variable.104*105* @see #createInputStreamInstance(Object, boolean, File)106*/107public Class<?> getInputClass() {108return inputClass;109}110111/**112* Returns {@code true} if the {@code ImageInputStream}113* implementation associated with this service provider can114* optionally make use of a cache file for improved performance115* and/or memory footrprint. If {@code false}, the value of116* the {@code useCache} argument to117* {@code createInputStreamInstance} will be ignored.118*119* <p> The default implementation returns {@code false}.120*121* @return {@code true} if a cache file can be used by the122* input streams created by this service provider.123*/124public boolean canUseCacheFile() {125return false;126}127128/**129* Returns {@code true} if the {@code ImageInputStream}130* implementation associated with this service provider requires131* the use of a cache {@code File}. If {@code true},132* the value of the {@code useCache} argument to133* {@code createInputStreamInstance} will be ignored.134*135* <p> The default implementation returns {@code false}.136*137* @return {@code true} if a cache file is needed by the138* input streams created by this service provider.139*/140public boolean needsCacheFile() {141return false;142}143144/**145* Returns an instance of the {@code ImageInputStream}146* implementation associated with this service provider. If the147* use of a cache file is optional, the {@code useCache}148* parameter will be consulted. Where a cache is required, or149* not applicable, the value of {@code useCache} will be ignored.150*151* @param input an object of the class type returned by152* {@code getInputClass}.153* @param useCache a {@code boolean} indicating whether a154* cache file should be used, in cases where it is optional.155* @param cacheDir a {@code File} indicating where the156* cache file should be created, or {@code null} to use the157* system directory.158*159* @return an {@code ImageInputStream} instance.160*161* @exception IllegalArgumentException if {@code input} is162* not an instance of the correct class or is {@code null}.163* @exception IllegalArgumentException if a cache file is needed164* but {@code cacheDir} is non-{@code null} and is not a165* directory.166* @exception IOException if a cache file is needed but cannot be167* created.168*169* @see #getInputClass170* @see #canUseCacheFile171* @see #needsCacheFile172*/173public abstract ImageInputStream174createInputStreamInstance(Object input,175boolean useCache,176File cacheDir) throws IOException;177178/**179* Returns an instance of the {@code ImageInputStream}180* implementation associated with this service provider. A cache181* file will be created in the system-dependent default182* temporary-file directory, if needed.183*184* @param input an object of the class type returned by185* {@code getInputClass}.186*187* @return an {@code ImageInputStream} instance.188*189* @exception IllegalArgumentException if {@code input} is190* not an instance of the correct class or is {@code null}.191* @exception IOException if a cache file is needed but cannot be192* created.193*194* @see #getInputClass()195*/196public ImageInputStream createInputStreamInstance(Object input)197throws IOException {198return createInputStreamInstance(input, true, null);199}200}201202203