- 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) forImageReader
s. For more information on service provider classes, see the class comment for theIIORegistry
class.Each
ImageReaderSpi
provides several types of information about theImageReader
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
, andgetVersion
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
, andgetMIMETypes
methods. These methods may be used to identify candidateImageReader
s 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
ImageReader
s are likely to be able to parse a particular data stream is provided by thecanDecodeInput
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 thecreateReaderInstance
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
Fields Modifier and Type Field and Description protected Class[]
inputTypes
An array ofClass
objects to be returned fromgetInputTypes
, initiallynull
.static 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 fromgetImageWriterSpiNames
, initiallynull
.-
Fields inherited from class javax.imageio.spi.ImageReaderWriterSpi
extraImageMetadataFormatClassNames, extraImageMetadataFormatNames, extraStreamMetadataFormatClassNames, extraStreamMetadataFormatNames, MIMETypes, names, nativeImageMetadataFormatClassName, nativeImageMetadataFormatName, nativeStreamMetadataFormatClassName, nativeStreamMetadataFormatName, pluginClassName, suffixes, supportsStandardImageMetadataFormat, supportsStandardStreamMetadataFormat
-
Fields inherited from class javax.imageio.spi.IIOServiceProvider
vendorName, version
-
-
Constructor Summary
Constructors Modifier Constructor and Description protected
ImageReaderSpi()
Constructs a blankImageReaderSpi
.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 anImageReaderSpi
with a given set of values.
-
Method Summary
Methods Modifier and Type Method and Description abstract boolean
canDecodeInput(Object source)
Returnstrue
if the supplied source object appears to be of the format supported by this reader.ImageReader
createReaderInstance()
Returns an instance of theImageReader
implementation associated with this service provider.abstract ImageReader
createReaderInstance(Object extension)
Returns an instance of theImageReader
implementation associated with this service provider.String[]
getImageWriterSpiNames()
Returns an array ofString
s containing the fully qualified names of all theImageWriterSpi
classes that can understand the internal metadata representation used by theImageReader
associated with this service provider, ornull
if there are no suchImageWriter
s specified.Class[]
getInputTypes()
Returns an array ofClass
objects indicating what types of objects may be used as arguments to the reader'ssetInput
method.boolean
isOwnReader(ImageReader reader)
Returnstrue
if theImageReader
object passed in is an instance of theImageReader
associated with this service provider.-
Methods inherited from class javax.imageio.spi.ImageReaderWriterSpi
getExtraImageMetadataFormatNames, getExtraStreamMetadataFormatNames, getFileSuffixes, getFormatNames, getImageMetadataFormat, getMIMETypes, getNativeImageMetadataFormatName, getNativeStreamMetadataFormatName, getPluginClassName, getStreamMetadataFormat, isStandardImageMetadataFormatSupported, isStandardStreamMetadataFormatSupported
-
Methods inherited from class javax.imageio.spi.IIOServiceProvider
getDescription, getVendorName, getVersion, onDeregistration, onRegistration
-
-
-
-
Field Detail
-
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 containingImageInputStream.class
, to be returned fromgetInputTypes
.
-
inputTypes
protected Class[] inputTypes
An array ofClass
objects to be returned fromgetInputTypes
, initiallynull
.
-
writerSpiNames
protected String[] writerSpiNames
An array of strings to be returned fromgetImageWriterSpiNames
, initiallynull
.
-
-
Constructor Detail
-
ImageReaderSpi
protected ImageReaderSpi()
Constructs a blankImageReaderSpi
. 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 anImageReaderSpi
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 ofString
s indicating the format names. At least one entry must be present.suffixes
- an array ofString
s indicating the common file suffixes. If no suffixes are defined,null
should be supplied. An array of length 0 will be normalized tonull
.MIMETypes
- an array ofString
s indicating the format's MIME types. If no MIME types are defined,null
should be supplied. An array of length 0 will be normalized tonull
.readerClassName
- the fully-qualified name of the associatedImageReader
class, as a non-null
String
.inputTypes
- a non-null
array ofClass
objects of length at least 1 indicating the legal input types.writerSpiNames
- an arrayString
s naming the classes of all associatedImageWriter
s, ornull
. An array of length 0 is normalized tonull
.supportsStandardStreamMetadataFormat
- aboolean
that indicates whether a stream metadata object can use trees described by the standard metadata format.nativeStreamMetadataFormatName
- aString
, ornull
, to be returned fromgetNativeStreamMetadataFormatName
.nativeStreamMetadataFormatClassName
- aString
, ornull
, to be used to instantiate a metadata format object to be returned fromgetNativeStreamMetadataFormat
.extraStreamMetadataFormatNames
- an array ofString
s, ornull
, to be returned fromgetExtraStreamMetadataFormatNames
. An array of length 0 is normalized tonull
.extraStreamMetadataFormatClassNames
- an array ofString
s, ornull
, to be used to instantiate a metadata format object to be returned fromgetStreamMetadataFormat
. An array of length 0 is normalized tonull
.supportsStandardImageMetadataFormat
- aboolean
that indicates whether an image metadata object can use trees described by the standard metadata format.nativeImageMetadataFormatName
- aString
, ornull
, to be returned fromgetNativeImageMetadataFormatName
.nativeImageMetadataFormatClassName
- aString
, ornull
, to be used to instantiate a metadata format object to be returned fromgetNativeImageMetadataFormat
.extraImageMetadataFormatNames
- an array ofString
s to be returned fromgetExtraImageMetadataFormatNames
. An array of length 0 is normalized tonull
.extraImageMetadataFormatClassNames
- an array ofString
s, ornull
, to be used to instantiate a metadata format object to be returned fromgetImageMetadataFormat
. An array of length 0 is normalized tonull
.- Throws:
IllegalArgumentException
- ifvendorName
isnull
.IllegalArgumentException
- ifversion
isnull
.IllegalArgumentException
- ifnames
isnull
or has length 0.IllegalArgumentException
- ifreaderClassName
isnull
.IllegalArgumentException
- ifinputTypes
isnull
or has length 0.
-
-
Method Detail
-
getInputTypes
public Class[] getInputTypes()
Returns an array ofClass
objects indicating what types of objects may be used as arguments to the reader'ssetInput
method.For most readers, which only accept input from an
ImageInputStream
, a single-element array containingImageInputStream.class
should be returned.- Returns:
- a non-
null
array ofClass
objects of length at least 1.
-
canDecodeInput
public abstract boolean canDecodeInput(Object source) throws IOException
Returnstrue
if the supplied source object appears to be of the format supported by this reader. Returningtrue
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 anImageInputStream
, 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
ImageReaderSpi
s can properly determine whether they are able to decode the object. In particular, if the source is anImageInputStream
, amark
/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 bygetInputTypes
, the method should simply returnfalse
.- Parameters:
source
- the object (typically anImageInputStream
) to be decoded.- Returns:
true
if it is likely that this stream can be decoded.- Throws:
IllegalArgumentException
- ifsource
isnull
.IOException
- if an I/O error occurs while reading the stream.
-
createReaderInstance
public ImageReader createReaderInstance() throws IOException
Returns an instance of theImageReader
implementation associated with this service provider. The returned object will initially be in an initial state as if itsreset
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 theImageReader
implementation associated with this service provider. The returned object will initially be in an initial state as if itsreset
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 benull
.- Returns:
- an
ImageReader
instance. - Throws:
IOException
- if the attempt to instantiate the reader fails.IllegalArgumentException
- if theImageReader
's contructor throws anIllegalArgumentException
to indicate that the extension object is unsuitable.
-
isOwnReader
public boolean isOwnReader(ImageReader reader)
Returnstrue
if theImageReader
object passed in is an instance of theImageReader
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
- anImageReader
instance.- Returns:
true
ifreader
is recognized.- Throws:
IllegalArgumentException
- ifreader
isnull
.
-
getImageWriterSpiNames
public String[] getImageWriterSpiNames()
Returns an array ofString
s containing the fully qualified names of all theImageWriterSpi
classes that can understand the internal metadata representation used by theImageReader
associated with this service provider, ornull
if there are no suchImageWriter
s 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 byImageIO.getImageWriter(ImageReader)
.This mechanism may be used to obtain
ImageWriters
that will understand the internal structure of non-pixel meta-data (seeIIOTreeInfo
) generated by anImageReader
. By obtaining this data from theImageReader
and passing it on to one of theImageWriters
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
String
s of length at least 1 containing names ofImageWriterSpi
, ornull
. - See Also:
ImageIO.getImageWriter(ImageReader)
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
22/12/2024 08:55:40 Cette version de la page est en cache (à la date du 22/12/2024 08:55:40) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 16/09/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/imageio/spi/ImageReaderSpi.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.