jdk/src/share/classes/javax/imageio/spi/ImageOutputStreamSpi.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.imageio.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.imageio.stream.ImageOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The service provider interface (SPI) for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <code>ImageOutputStream</code>s.  For more information on service
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * provider interfaces, see the class comment for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <code>IIORegistry</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p> This interface allows arbitrary objects to be "wrapped" by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * instances of <code>ImageOutputStream</code>.  For example, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * particular <code>ImageOutputStreamSpi</code> might allow a generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <code>OutputStream</code> to be used as a destination; another
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * might output to a <code>File</code> or to a device such as a serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p> By treating the creation of <code>ImageOutputStream</code>s as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a pluggable service, it becomes possible to handle future output
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * destinations without changing the API.  Also, high-performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * implementations of <code>ImageOutputStream</code> (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * native implementations for a particular platform) can be installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * and used transparently by applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see IIORegistry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see javax.imageio.stream.ImageOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public abstract class ImageOutputStreamSpi extends IIOServiceProvider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * A <code>Class</code> object indicating the legal object type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * for use by the <code>createInputStreamInstance</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected Class<?> outputClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Constructs a blank <code>ImageOutputStreamSpi</code>.  It is up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * to the subclass to initialize instance variables and/or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * override method implementations in order to provide working
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * versions of all methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected ImageOutputStreamSpi() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Constructs an <code>ImageOutputStreamSpi</code> with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * set of values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param vendorName the vendor name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param version a version identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param outputClass a <code>Class</code> object indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * legal object type for use by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * <code>createOutputStreamInstance</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @exception IllegalArgumentException if <code>vendorName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @exception IllegalArgumentException if <code>version</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public ImageOutputStreamSpi(String vendorName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                String version,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                Class<?> outputClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        super(vendorName, version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        this.outputClass = outputClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Returns a <code>Class</code> object representing the class or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * interface type that must be implemented by an output
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * destination in order to be "wrapped" in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <code>ImageOutputStream</code> via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * <code>createOutputStreamInstance</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <p> Typical return values might include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <code>OutputStream.class</code> or <code>File.class</code>, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * any class may be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @return a <code>Class</code> variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see #createOutputStreamInstance(Object, boolean, File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public Class<?> getOutputClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return outputClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Returns <code>true</code> if the <code>ImageOutputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * implementation associated with this service provider can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * optionally make use of a cache <code>File</code> for improved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * performance and/or memory footrprint.  If <code>false</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * the value of the <code>cacheFile</code> argument to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <code>createOutputStreamInstance</code> will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <p> The default implementation returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return <code>true</code> if a cache file can be used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * output streams created by this service provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public boolean canUseCacheFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Returns <code>true</code> if the <code>ImageOutputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * implementation associated with this service provider requires
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * the use of a cache <code>File</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <p> The default implementation returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @return <code>true</code> if a cache file is needed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * output streams created by this service provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public boolean needsCacheFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Returns an instance of the <code>ImageOutputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * implementation associated with this service provider.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * use of a cache file is optional, the <code>useCache</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * parameter will be consulted.  Where a cache is required, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * not applicable, the value of <code>useCache</code> will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param output an object of the class type returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <code>getOutputClass</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param useCache a <code>boolean</code> indicating whether a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * cache file should be used, in cases where it is optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param cacheDir a <code>File</code> indicating where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * cache file should be created, or <code>null</code> to use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * system directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @return an <code>ImageOutputStream</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @exception IllegalArgumentException if <code>output</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * not an instance of the correct class or is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @exception IllegalArgumentException if a cache file is needed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * but <code>cacheDir</code> is non-<code>null</code> and is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @exception IOException if a cache file is needed but cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see #getOutputClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public abstract
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        ImageOutputStream createOutputStreamInstance(Object output,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                                     boolean useCache,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                                     File cacheDir)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Returns an instance of the <code>ImageOutputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * implementation associated with this service provider.  A cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * file will be created in the system-dependent default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * temporary-file directory, if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param output an object of the class type returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * <code>getOutputClass</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @return an <code>ImageOutputStream</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @exception IllegalArgumentException if <code>output</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * not an instance of the correct class or is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @exception IOException if a cache file is needed but cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see #getOutputClass()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public ImageOutputStream createOutputStreamInstance(Object output)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return createOutputStreamInstance(output, true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
}