Spec-Zone.ru › OpenJDK 27

Class ImageReaderSpi

java.lang.Object
javax.imageio.spi.IIOServiceProvider
javax.imageio.spi.ImageReaderWriterSpi
javax.imageio.spi.ImageReaderSpi
All Implemented Interfaces:
RegisterableService
public abstract class ImageReaderSpi extends ImageReaderWriterSpi
The service provider interface (SPI) for ImageReaders. For more information on service provider classes, see the class comment for the IIORegistry class.

Each ImageReaderSpi provides several types of information about the ImageReader class with which it is associated.

The name of the vendor who defined the SPI class and a brief description of the class are available via the getVendorName, getDescription, and getVersion methods. These methods may be internationalized to provide locale-specific output. These methods are intended mainly to provide short, human-readable information that might be used to organize a pop-up menu or other list.

Lists of format names, file suffixes, and MIME types associated with the service may be obtained by means of the getFormatNames, getFileSuffixes, and getMIMETypes methods. These methods may be used to identify candidate ImageReaders for decoding a particular file or stream based on manual format selection, file naming, or MIME associations (for example, when accessing a file over HTTP or as an email attachment).

A more reliable way to determine which ImageReaders are likely to be able to parse a particular data stream is provided by the canDecodeInput method. This methods allows the service provider to inspect the actual stream contents.

Finally, an instance of the ImageReader class associated with this service provider may be obtained by calling the createReaderInstance method. Any heavyweight initialization, such as the loading of native libraries or creation of large tables, should be deferred at least until the first invocation of this method.

See Also:
  • IIORegistry
  • ImageReader

Field Summary

Modifier and Type Field Description
protected Class<?>[] inputTypes
An array of Class objects to be returned from getInputTypes, initially null.
static final Class<?>[] STANDARD_INPUT_TYPE
Deprecated.
Instead of using this field, directly create the equivalent array { ImageInputStream.class }.
protected String[] writerSpiNames
An array of strings to be returned from getImageWriterSpiNames, initially null.

Fields declared in class ImageReaderWriterSpi

extraImageMetadataFormatClassNames, extraImageMetadataFormatNames, extraStreamMetadataFormatClassNames, extraStreamMetadataFormatNames, MIMETypes, names, nativeImageMetadataFormatClassName, nativeImageMetadataFormatName, nativeStreamMetadataFormatClassName, nativeStreamMetadataFormatName, pluginClassName, suffixes, supportsStandardImageMetadataFormat, supportsStandardStreamMetadataFormat
Modifier and Type Field Description
protected String[] extraImageMetadataFormatClassNames
An array of Strings containing the class names of any additional image metadata formats supported by this plug-in, initially null.
protected String[] extraImageMetadataFormatNames
An array of Strings containing the names of any additional image metadata formats supported by this plug-in, initially null.
protected String[] extraStreamMetadataFormatClassNames
An array of Strings containing the class names of any additional stream metadata formats supported by this plug-in, initially null.
protected String[] extraStreamMetadataFormatNames
An array of Strings containing the names of any additional stream metadata formats supported by this plug-in, initially null.
protected String[] MIMETypes
An array of strings to be returned from getMIMETypes, initially null.
protected String[] names
An array of strings to be returned from getFormatNames, initially null.
protected String nativeImageMetadataFormatClassName
A String containing the class name of the native stream metadata format supported by this plug-in, initially null.
protected String nativeImageMetadataFormatName
A String containing the name of the native stream metadata format supported by this plug-in, initially null.
protected String nativeStreamMetadataFormatClassName
A String containing the class name of the native stream metadata format supported by this plug-in, initially null.
protected String nativeStreamMetadataFormatName
A String containing the name of the native stream metadata format supported by this plug-in, initially null.
protected String pluginClassName
A String containing the name of the associated plug-in class, initially null.
protected String[] suffixes
An array of strings to be returned from getFileSuffixes, initially null.
protected boolean supportsStandardImageMetadataFormat
A boolean indicating whether this plug-in supports the standard metadata format for image metadata, initially false.
protected boolean supportsStandardStreamMetadataFormat
A boolean indicating whether this plug-in supports the standard metadata format for stream metadata, initially false.

Fields declared in class IIOServiceProvider

vendorName, version
Modifier and Type Field Description
protected String vendorName
A String to be returned from getVendorName, initially null.
protected String version
A String to be returned from getVersion, initially null.

Constructor Summary

ImageReaderSpi()
ImageReaderSpi(String vendorName, String version, String[] names, String[] suffixes, String[] MIMETypes, String readerClassName, Class<?>[] inputTypes, String[] writerSpiNames, boolean supportsStandardStreamMetadataFormat, String nativeStreamMetadataFormatName, String nativeStreamMetadataFormatClassName, String[] extraStreamMetadataFormatNames, String[] extraStreamMetadataFormatClassNames, boolean supportsStandardImageMetadataFormat, String nativeImageMetadataFormatName, String nativeImageMetadataFormatClassName, String[] extraImageMetadataFormatNames, String[] extraImageMetadataFormatClassNames)
Modifier Constructor Description
protected
Constructs a blank ImageReaderSpi.
Constructs an ImageReaderSpi with a given set of values.

Method Summary

Modifier and Type Method Description
abstract boolean canDecodeInput(Object source)
Returns true if the supplied source object appears to be of the format supported by this reader.
ImageReader createReaderInstance()
Returns an instance of the ImageReader implementation associated with this service provider.
abstract ImageReader createReaderInstance(Object extension)
Returns an instance of the ImageReader implementation associated with this service provider.
String[] getImageWriterSpiNames()
Returns an array of Strings containing the fully qualified names of all the ImageWriterSpi classes that can understand the internal metadata representation used by the ImageReader associated with this service provider, or null if there are no such ImageWriters specified.
Class<?>[] getInputTypes()
Returns an array of Class objects indicating what types of objects may be used as arguments to the reader's setInput method.
boolean isOwnReader(ImageReader reader)
Returns true if the ImageReader object passed in is an instance of the ImageReader associated with this service provider.

Methods declared in class ImageReaderWriterSpi

getExtraImageMetadataFormatNames, getExtraStreamMetadataFormatNames, getFileSuffixes, getFormatNames, getImageMetadataFormat, getMIMETypes, getNativeImageMetadataFormatName, getNativeStreamMetadataFormatName, getPluginClassName, getStreamMetadataFormat, isStandardImageMetadataFormatSupported, isStandardStreamMetadataFormatSupported
Modifier and Type Method Description
String[] getExtraImageMetadataFormatNames()
Returns an array of Strings containing the names of additional document formats, other than the native and standard formats, recognized by the getAsTree and setFromTree methods on the image metadata objects produced or consumed by this plug-in.
String[] getExtraStreamMetadataFormatNames()
Returns an array of Strings containing the names of additional document formats, other than the native and standard formats, recognized by the getAsTree and setFromTree methods on the stream metadata objects produced or consumed by this plug-in.
String[] getFileSuffixes()
Returns an array of Strings containing a list of file suffixes associated with the formats that are generally usable by the ImageReader or ImageWriter implementation associated with this service provider.
String[] getFormatNames()
Returns an array of Strings containing human-readable names for the formats that are generally usable by the ImageReader or ImageWriter implementation associated with this service provider.
IIOMetadataFormat getImageMetadataFormat(String formatName)
Returns an IIOMetadataFormat object describing the given image metadata format, or null if no description is available.
String[] getMIMETypes()
Returns an array of Strings containing a list of MIME types associated with the formats that are generally usable by the ImageReader or ImageWriter implementation associated with this service provider.
String getNativeImageMetadataFormatName()
Returns the name of the "native" image metadata format for this plug-in, which typically allows for lossless encoding and transmission of the image metadata stored in the format handled by this plug-in.
String getNativeStreamMetadataFormatName()
Returns the name of the "native" stream metadata format for this plug-in, which typically allows for lossless encoding and transmission of the stream metadata stored in the format handled by this plug-in.
String getPluginClassName()
Returns the fully-qualified class name of the ImageReader or ImageWriter plug-in associated with this service provider.
IIOMetadataFormat getStreamMetadataFormat(String formatName)
Returns an IIOMetadataFormat object describing the given stream metadata format, or null if no description is available.
boolean isStandardImageMetadataFormatSupported()
Returns true if the standard metadata format is among the document formats recognized by the getAsTree and setFromTree methods on the image metadata objects produced or consumed by this plug-in.
boolean isStandardStreamMetadataFormatSupported()
Returns true if the standard metadata format is among the document formats recognized by the getAsTree and setFromTree methods on the stream metadata objects produced or consumed by this plug-in.

Methods declared in class IIOServiceProvider

getDescription, getVendorName, getVersion, onDeregistration, onRegistration
Modifier and Type Method Description
abstract String getDescription(Locale locale)
Returns a brief, human-readable description of this service provider and its associated implementation.
String getVendorName()
Returns the name of the vendor responsible for creating this service provider and its associated implementation.
String getVersion()
Returns a string describing the version number of this service provider and its associated implementation.
void onDeregistration(ServiceRegistry registry, Class<?> category)
A callback that will be whenever the Spi class has been deregistered from a ServiceRegistry.
void onRegistration(ServiceRegistry registry, Class<?> category)
A callback that will be called exactly once after the Spi class has been instantiated and registered in a ServiceRegistry.

Methods declared in class Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Modifier and Type Method Description
protected Object clone()
Creates and returns a copy of this object.
boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
protected void finalize()
Deprecated, for removal: This API element is subject to removal in a future version.
Finalization is deprecated and subject to removal in a future release.
final Class<?> getClass()
Returns the runtime class of this Object.
int hashCode()
Returns a hash code value for this object.
final void notify()
Wakes up a single thread that is waiting on this object's monitor.
final void notifyAll()
Wakes up all threads that are waiting on this object's monitor.
String toString()
Returns a string representation of the object.
final void wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
final void wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
final void wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

Field Details

STANDARD_INPUT_TYPE

@Deprecated public static final Class<?>[] STANDARD_INPUT_TYPE
Deprecated.
Instead of using this field, directly create the equivalent array { ImageInputStream.class }.
A single-element array, initially containing ImageInputStream.class, to be returned from getInputTypes.

inputTypes

protected Class<?>[] inputTypes
An array of Class objects to be returned from getInputTypes, initially null.

writerSpiNames

protected String[] writerSpiNames
An array of strings to be returned from getImageWriterSpiNames, initially null.

Constructor Details

ImageReaderSpi

protected ImageReaderSpi()
Constructs a blank ImageReaderSpi. It is up to the subclass to initialize instance variables and/or override method implementations in order to provide working versions of all methods.

ImageReaderSpi

public ImageReaderSpi(String vendorName, String version, String[] names, String[] suffixes, String[] MIMETypes, String readerClassName, Class<?>[] inputTypes, String[] writerSpiNames, boolean supportsStandardStreamMetadataFormat, String nativeStreamMetadataFormatName, String nativeStreamMetadataFormatClassName, String[] extraStreamMetadataFormatNames, String[] extraStreamMetadataFormatClassNames, boolean supportsStandardImageMetadataFormat, String nativeImageMetadataFormatName, String nativeImageMetadataFormatClassName, String[] extraImageMetadataFormatNames, String[] extraImageMetadataFormatClassNames)
Constructs an ImageReaderSpi with a given set of values.
Parameters:
vendorName - the vendor name, as a non-null String.
version - a version identifier, as a non-null String.
names - a non-null array of Strings indicating the format names. At least one entry must be present.
suffixes - an array of Strings indicating the common file suffixes. If no suffixes are defined, null should be supplied. An array of length 0 will be normalized to null.
MIMETypes - an array of Strings indicating the format's MIME types. If no MIME types are defined, null should be supplied. An array of length 0 will be normalized to null.
readerClassName - the fully-qualified name of the associated ImageReader class, as a non-null String.
inputTypes - a non-null array of Class objects of length at least 1 indicating the legal input types.
writerSpiNames - an array Strings naming the classes of all associated ImageWriters, or null. An array of length 0 is normalized to null.
supportsStandardStreamMetadataFormat - a boolean that indicates whether a stream metadata object can use trees described by the standard metadata format.
nativeStreamMetadataFormatName - a String, or null, to be returned from getNativeStreamMetadataFormatName.
nativeStreamMetadataFormatClassName - a String, or null, to be used to instantiate a metadata format object to be returned from getNativeStreamMetadataFormat.
extraStreamMetadataFormatNames - an array of Strings, or null, to be returned from getExtraStreamMetadataFormatNames. An array of length 0 is normalized to null.
extraStreamMetadataFormatClassNames - an array of Strings, or null, to be used to instantiate a metadata format object to be returned from getStreamMetadataFormat. An array of length 0 is normalized to null.
supportsStandardImageMetadataFormat - a boolean that indicates whether an image metadata object can use trees described by the standard metadata format.
nativeImageMetadataFormatName - a String, or null, to be returned from getNativeImageMetadataFormatName.
nativeImageMetadataFormatClassName - a String, or null, to be used to instantiate a metadata format object to be returned from getNativeImageMetadataFormat.
extraImageMetadataFormatNames - an array of Strings to be returned from getExtraImageMetadataFormatNames. An array of length 0 is normalized to null.
extraImageMetadataFormatClassNames - an array of Strings, or null, to be used to instantiate a metadata format object to be returned from getImageMetadataFormat. An array of length 0 is normalized to null.
Throws:
IllegalArgumentException - if vendorName is null.
IllegalArgumentException - if version is null.
IllegalArgumentException - if names is null or has length 0.
IllegalArgumentException - if readerClassName is null.
IllegalArgumentException - if inputTypes is null or has length 0.

Method Details

getInputTypes

public Class<?>[] getInputTypes()
Returns an array of Class objects indicating what types of objects may be used as arguments to the reader's setInput method.

For most readers, which only accept input from an ImageInputStream, a single-element array containing ImageInputStream.class should be returned.

Returns:
a non-null array of Class objects of length at least 1.

canDecodeInput

public abstract boolean canDecodeInput(Object source) throws IOException
Returns true if the supplied source object appears to be of the format supported by this reader. Returning true from this method does not guarantee that reading will succeed, only that there appears to be a reasonable chance of success based on a brief inspection of the stream contents. If the source is an ImageInputStream, implementations will commonly check the first several bytes of the stream for a "magic number" associated with the format. Once actual reading has commenced, the reader may still indicate failure at any time prior to the completion of decoding.

It is important that the state of the object not be disturbed in order that other ImageReaderSpis can properly determine whether they are able to decode the object. In particular, if the source is an ImageInputStream, a mark/reset pair should be used to preserve the stream position.

Formats such as "raw," which can potentially attempt to read nearly any stream, should return false in order to avoid being invoked in preference to a closer match.

If source is not an instance of one of the classes returned by getInputTypes, the method should simply return false.

Parameters:
source - the object (typically an ImageInputStream) to be decoded.
Returns:
true if it is likely that this stream can be decoded.
Throws:
IllegalArgumentException - if source is null.
IOException - if an I/O error occurs while reading the stream.

createReaderInstance

public ImageReader createReaderInstance() throws IOException
Returns an instance of the ImageReader implementation associated with this service provider. The returned object will initially be in an initial state as if its reset method had been called.

The default implementation simply returns createReaderInstance(null).

Returns:
an ImageReader instance.
Throws:
IOException - if an error occurs during loading, or initialization of the reader class, or during instantiation or initialization of the reader object.

createReaderInstance

public abstract ImageReader createReaderInstance(Object extension) throws IOException
Returns an instance of the ImageReader implementation associated with this service provider. The returned object will initially be in an initial state as if its reset method had been called.

An Object may be supplied to the plug-in at construction time. The nature of the object is entirely plug-in specific.

Typically, a plug-in will implement this method using code such as return new MyImageReader(this).

Parameters:
extension - a plug-in specific extension object, which may be null.
Returns:
an ImageReader instance.
Throws:
IOException - if the attempt to instantiate the reader fails.
IllegalArgumentException - if the ImageReader's constructor throws an IllegalArgumentException to indicate that the extension object is unsuitable.

isOwnReader

public boolean isOwnReader(ImageReader reader)
Returns true if the ImageReader object passed in is an instance of the ImageReader associated with this service provider.

The default implementation compares the fully-qualified class name of the reader argument with the class name passed into the constructor. This method may be overridden if more sophisticated checking is required.

Parameters:
reader - an ImageReader instance.
Returns:
true if reader is recognized.
Throws:
IllegalArgumentException - if reader is null.

getImageWriterSpiNames

public String[] getImageWriterSpiNames()
Returns an array of Strings containing the fully qualified names of all the ImageWriterSpi classes that can understand the internal metadata representation used by the ImageReader associated with this service provider, or null if there are no such ImageWriters specified. If a non-null value is returned, it must have non-zero length.

The first item in the array must be the name of the service provider for the "preferred" writer, as it will be used to instantiate the ImageWriter returned by ImageIO.getImageWriter(ImageReader).

This mechanism may be used to obtain ImageWriters that will understand the internal structure of non-pixel meta-data (see IIOTreeInfo) generated by an ImageReader. By obtaining this data from the ImageReader and passing it on to one of the ImageWriters obtained with this method, a client program can read an image, modify it in some way, and write it back out while preserving all meta-data, without having to understand anything about the internal structure of the meta-data, or even about the image format.

Returns:
an array of Strings of length at least 1 containing names of ImageWriterSpi, or null.
See Also:
  • ImageIO.getImageWriter(ImageReader)

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2026, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API