001/* ImageOutputStreamSpi.java -- Service provider for image output streams. 002 Copyright (C) 2004, 2005 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package javax.imageio.spi; 040 041import java.io.File; 042import java.io.IOException; 043 044import javax.imageio.stream.ImageOutputStream; 045 046/** 047 * An abstract superclass for service providers that create 048 * {@linkplain javax.imageio.stream.ImageOutputStream image output 049 * streams} for a file, URL, byte array or any other target. 050 * 051 * @since 1.4 052 * 053 * @author Sascha Brawer (brawer@dandelis.ch) 054 */ 055public abstract class ImageOutputStreamSpi 056 extends IIOServiceProvider 057{ 058 /** 059 * Indicates which kind of output is produced by the streams 060 * created by {@link #createOutputStreamInstance(Object)}. 061 */ 062 protected Class<?> outputClass; 063 064 065 /** 066 * Constructs a service provider for image output streams, given no 067 * parameters. It is up to the sub-class to set {@link #vendorName}, 068 * {@link #version} and {@link #outputClass} to non-null values. 069 */ 070 protected ImageOutputStreamSpi() 071 { 072 } 073 074 075 /** 076 * Constructs a service provider for image output streams, given the 077 * vendor name, a version string and the kind of producable output. 078 * 079 * @throws IllegalArgumentException if <code>vendorName</code> 080 * or <code>version</code> is <code>null</code>. 081 */ 082 public ImageOutputStreamSpi(String vendorName, String version, 083 Class<?> outputClass) 084 { 085 super(vendorName, version); 086 this.outputClass = outputClass; 087 } 088 089 090 /** 091 * Determines which kind of output is produced by the streams 092 * created by {@link #createOutputStreamInstance(Object)}. 093 */ 094 public Class<?> getOutputClass() 095 { 096 return outputClass; 097 } 098 099 100 /** 101 * Determines whether <code>ImageOutputStreams</code> created 102 * by this service provider benefit from using a cache file. 103 * 104 * <p>The default behavior is to return <code>false</code>. 105 * 106 * @return <code>true</code> if the created streams are faster or 107 * need less memory when a cache file is being used; 108 * <code>false</code> if no positive effect results from the cache 109 * file. 110 */ 111 public boolean canUseCacheFile() 112 { 113 return false; 114 } 115 116 117 /** 118 * Determines whether <code>ImageOutputStreams</code> created 119 * by this service provider require the use of a cache file. 120 * 121 * <p>The default behavior is to return <code>false</code>. 122 * 123 * @return <code>true</code> if the created streams can only work 124 * when a cache file is being used; <code>false</code> if no cache 125 * file is needed. 126 */ 127 public boolean needsCacheFile() 128 { 129 return false; 130 } 131 132 133 public abstract ImageOutputStream createOutputStreamInstance( 134 Object output, boolean useCache, File cacheDir) 135 throws IOException; 136 137 138 public ImageOutputStream createOutputStreamInstance(Object output) 139 throws IOException 140 { 141 return createOutputStreamInstance(output, canUseCacheFile(), null); 142 } 143}