0N/A/*
2362N/A * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.imageio.spi;
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.IOException;
0N/Aimport javax.imageio.stream.ImageOutputStream;
0N/A
0N/A/**
0N/A * The service provider interface (SPI) for
0N/A * <code>ImageOutputStream</code>s. For more information on service
0N/A * provider interfaces, see the class comment for the
0N/A * <code>IIORegistry</code> class.
0N/A *
0N/A * <p> This interface allows arbitrary objects to be "wrapped" by
0N/A * instances of <code>ImageOutputStream</code>. For example, a
0N/A * particular <code>ImageOutputStreamSpi</code> might allow a generic
0N/A * <code>OutputStream</code> to be used as a destination; another
0N/A * might output to a <code>File</code> or to a device such as a serial
0N/A * port.
0N/A *
0N/A * <p> By treating the creation of <code>ImageOutputStream</code>s as
0N/A * a pluggable service, it becomes possible to handle future output
0N/A * destinations without changing the API. Also, high-performance
0N/A * implementations of <code>ImageOutputStream</code> (for example,
0N/A * native implementations for a particular platform) can be installed
0N/A * and used transparently by applications.
0N/A *
0N/A * @see IIORegistry
0N/A * @see javax.imageio.stream.ImageOutputStream
0N/A *
0N/A */
0N/Apublic abstract class ImageOutputStreamSpi extends IIOServiceProvider {
0N/A
0N/A /**
0N/A * A <code>Class</code> object indicating the legal object type
0N/A * for use by the <code>createInputStreamInstance</code> method.
0N/A */
0N/A protected Class<?> outputClass;
0N/A
0N/A /**
0N/A * Constructs a blank <code>ImageOutputStreamSpi</code>. It is up
0N/A * to the subclass to initialize instance variables and/or
0N/A * override method implementations in order to provide working
0N/A * versions of all methods.
0N/A */
0N/A protected ImageOutputStreamSpi() {
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <code>ImageOutputStreamSpi</code> with a given
0N/A * set of values.
0N/A *
0N/A * @param vendorName the vendor name.
0N/A * @param version a version identifier.
0N/A * @param outputClass a <code>Class</code> object indicating the
0N/A * legal object type for use by the
0N/A * <code>createOutputStreamInstance</code> method.
0N/A *
0N/A * @exception IllegalArgumentException if <code>vendorName</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>version</code>
0N/A * is <code>null</code>.
0N/A */
0N/A public ImageOutputStreamSpi(String vendorName,
0N/A String version,
0N/A Class<?> outputClass) {
0N/A super(vendorName, version);
0N/A this.outputClass = outputClass;
0N/A }
0N/A
0N/A /**
0N/A * Returns a <code>Class</code> object representing the class or
0N/A * interface type that must be implemented by an output
0N/A * destination in order to be "wrapped" in an
0N/A * <code>ImageOutputStream</code> via the
0N/A * <code>createOutputStreamInstance</code> method.
0N/A *
0N/A * <p> Typical return values might include
0N/A * <code>OutputStream.class</code> or <code>File.class</code>, but
0N/A * any class may be used.
0N/A *
0N/A * @return a <code>Class</code> variable.
0N/A *
0N/A * @see #createOutputStreamInstance(Object, boolean, File)
0N/A */
0N/A public Class<?> getOutputClass() {
0N/A return outputClass;
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the <code>ImageOutputStream</code>
0N/A * implementation associated with this service provider can
0N/A * optionally make use of a cache <code>File</code> for improved
0N/A * performance and/or memory footrprint. If <code>false</code>,
0N/A * the value of the <code>cacheFile</code> argument to
0N/A * <code>createOutputStreamInstance</code> will be ignored.
0N/A *
0N/A * <p> The default implementation returns <code>false</code>.
0N/A *
0N/A * @return <code>true</code> if a cache file can be used by the
0N/A * output streams created by this service provider.
0N/A */
0N/A public boolean canUseCacheFile() {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the <code>ImageOutputStream</code>
0N/A * implementation associated with this service provider requires
0N/A * the use of a cache <code>File</code>.
0N/A *
0N/A * <p> The default implementation returns <code>false</code>.
0N/A *
0N/A * @return <code>true</code> if a cache file is needed by the
0N/A * output streams created by this service provider.
0N/A */
0N/A public boolean needsCacheFile() {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns an instance of the <code>ImageOutputStream</code>
0N/A * implementation associated with this service provider. If the
0N/A * use of a cache file is optional, the <code>useCache</code>
0N/A * parameter will be consulted. Where a cache is required, or
0N/A * not applicable, the value of <code>useCache</code> will be ignored.
0N/A *
0N/A * @param output an object of the class type returned by
0N/A * <code>getOutputClass</code>.
0N/A * @param useCache a <code>boolean</code> indicating whether a
0N/A * cache file should be used, in cases where it is optional.
0N/A * @param cacheDir a <code>File</code> indicating where the
0N/A * cache file should be created, or <code>null</code> to use the
0N/A * system directory.
0N/A *
0N/A * @return an <code>ImageOutputStream</code> instance.
0N/A *
0N/A * @exception IllegalArgumentException if <code>output</code> is
0N/A * not an instance of the correct class or is <code>null</code>.
0N/A * @exception IllegalArgumentException if a cache file is needed,
0N/A * but <code>cacheDir</code> is non-<code>null</code> and is not a
0N/A * directory.
0N/A * @exception IOException if a cache file is needed but cannot be
0N/A * created.
0N/A *
0N/A * @see #getOutputClass
0N/A */
0N/A public abstract
0N/A ImageOutputStream createOutputStreamInstance(Object output,
0N/A boolean useCache,
0N/A File cacheDir)
0N/A throws IOException;
0N/A
0N/A /**
0N/A * Returns an instance of the <code>ImageOutputStream</code>
0N/A * implementation associated with this service provider. A cache
0N/A * file will be created in the system-dependent default
0N/A * temporary-file directory, if needed.
0N/A *
0N/A * @param output an object of the class type returned by
0N/A * <code>getOutputClass</code>.
0N/A *
0N/A * @return an <code>ImageOutputStream</code> instance.
0N/A *
0N/A * @exception IllegalArgumentException if <code>output</code> is
0N/A * not an instance of the correct class or is <code>null</code>.
0N/A * @exception IOException if a cache file is needed but cannot be
0N/A * created.
0N/A *
0N/A * @see #getOutputClass()
0N/A */
0N/A public ImageOutputStream createOutputStreamInstance(Object output)
0N/A throws IOException {
0N/A return createOutputStreamInstance(output, true, null);
0N/A }
0N/A}