Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/imageio/spi/ImageOutputStreamSpi.java
38830 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.ImageOutputStream;3031/**32* The service provider interface (SPI) for33* <code>ImageOutputStream</code>s. For more information on service34* provider interfaces, see the class comment for the35* <code>IIORegistry</code> class.36*37* <p> This interface allows arbitrary objects to be "wrapped" by38* instances of <code>ImageOutputStream</code>. For example, a39* particular <code>ImageOutputStreamSpi</code> might allow a generic40* <code>OutputStream</code> to be used as a destination; another41* might output to a <code>File</code> or to a device such as a serial42* port.43*44* <p> By treating the creation of <code>ImageOutputStream</code>s as45* a pluggable service, it becomes possible to handle future output46* destinations without changing the API. Also, high-performance47* implementations of <code>ImageOutputStream</code> (for example,48* native implementations for a particular platform) can be installed49* and used transparently by applications.50*51* @see IIORegistry52* @see javax.imageio.stream.ImageOutputStream53*54*/55public abstract class ImageOutputStreamSpi extends IIOServiceProvider {5657/**58* A <code>Class</code> object indicating the legal object type59* for use by the <code>createInputStreamInstance</code> method.60*/61protected Class<?> outputClass;6263/**64* Constructs a blank <code>ImageOutputStreamSpi</code>. It is up65* to the subclass to initialize instance variables and/or66* override method implementations in order to provide working67* versions of all methods.68*/69protected ImageOutputStreamSpi() {70}7172/**73* Constructs an <code>ImageOutputStreamSpi</code> with a given74* set of values.75*76* @param vendorName the vendor name.77* @param version a version identifier.78* @param outputClass a <code>Class</code> object indicating the79* legal object type for use by the80* <code>createOutputStreamInstance</code> method.81*82* @exception IllegalArgumentException if <code>vendorName</code>83* is <code>null</code>.84* @exception IllegalArgumentException if <code>version</code>85* is <code>null</code>.86*/87public ImageOutputStreamSpi(String vendorName,88String version,89Class<?> outputClass) {90super(vendorName, version);91this.outputClass = outputClass;92}9394/**95* Returns a <code>Class</code> object representing the class or96* interface type that must be implemented by an output97* destination in order to be "wrapped" in an98* <code>ImageOutputStream</code> via the99* <code>createOutputStreamInstance</code> method.100*101* <p> Typical return values might include102* <code>OutputStream.class</code> or <code>File.class</code>, but103* any class may be used.104*105* @return a <code>Class</code> variable.106*107* @see #createOutputStreamInstance(Object, boolean, File)108*/109public Class<?> getOutputClass() {110return outputClass;111}112113/**114* Returns <code>true</code> if the <code>ImageOutputStream</code>115* implementation associated with this service provider can116* optionally make use of a cache <code>File</code> for improved117* performance and/or memory footrprint. If <code>false</code>,118* the value of the <code>cacheFile</code> argument to119* <code>createOutputStreamInstance</code> will be ignored.120*121* <p> The default implementation returns <code>false</code>.122*123* @return <code>true</code> if a cache file can be used by the124* output streams created by this service provider.125*/126public boolean canUseCacheFile() {127return false;128}129130/**131* Returns <code>true</code> if the <code>ImageOutputStream</code>132* implementation associated with this service provider requires133* the use of a cache <code>File</code>.134*135* <p> The default implementation returns <code>false</code>.136*137* @return <code>true</code> if a cache file is needed by the138* output streams created by this service provider.139*/140public boolean needsCacheFile() {141return false;142}143144/**145* Returns an instance of the <code>ImageOutputStream</code>146* implementation associated with this service provider. If the147* use of a cache file is optional, the <code>useCache</code>148* parameter will be consulted. Where a cache is required, or149* not applicable, the value of <code>useCache</code> will be ignored.150*151* @param output an object of the class type returned by152* <code>getOutputClass</code>.153* @param useCache a <code>boolean</code> indicating whether a154* cache file should be used, in cases where it is optional.155* @param cacheDir a <code>File</code> indicating where the156* cache file should be created, or <code>null</code> to use the157* system directory.158*159* @return an <code>ImageOutputStream</code> instance.160*161* @exception IllegalArgumentException if <code>output</code> is162* not an instance of the correct class or is <code>null</code>.163* @exception IllegalArgumentException if a cache file is needed,164* but <code>cacheDir</code> is non-<code>null</code> and is not a165* directory.166* @exception IOException if a cache file is needed but cannot be167* created.168*169* @see #getOutputClass170*/171public abstract172ImageOutputStream createOutputStreamInstance(Object output,173boolean useCache,174File cacheDir)175throws IOException;176177/**178* Returns an instance of the <code>ImageOutputStream</code>179* implementation associated with this service provider. A cache180* file will be created in the system-dependent default181* temporary-file directory, if needed.182*183* @param output an object of the class type returned by184* <code>getOutputClass</code>.185*186* @return an <code>ImageOutputStream</code> instance.187*188* @exception IllegalArgumentException if <code>output</code> is189* not an instance of the correct class or is <code>null</code>.190* @exception IOException if a cache file is needed but cannot be191* created.192*193* @see #getOutputClass()194*/195public ImageOutputStream createOutputStreamInstance(Object output)196throws IOException {197return createOutputStreamInstance(output, true, null);198}199}200201202