org.geotoolkit.image.io
Class ImageReaderAdapter.Spi

Object
  extended by IIOServiceProvider
      extended by ImageReaderWriterSpi
          extended by ImageReaderSpi
              extended by SpatialImageReader.Spi
                  extended by ImageReaderAdapter.Spi
All Implemented Interfaces:
RegisterableService
Direct Known Subclasses:
WorldFileImageReader.Spi
Enclosing class:
ImageReaderAdapter

public abstract static class ImageReaderAdapter.Spi
extends SpatialImageReader.Spi

Service provider interface (SPI) for ImageReaderAdapters. The constructor of this class initializes the ImageReaderSpi.inputTypes field to types that can represent a filename, like File or URL, rather than the usual standard input type. The names and MIMETypes fields are set to the values of the wrapped provider, suffixed with the string given at construction time.

Example: An ImageReaderAdapter wrapping the "tiff" image reader with the "-wf" suffix will have the "tiff-wf" format name and the "image/x-tiff-wf" MIME type.

The table below summarizes the initial values. Those values can be modified by subclass constructors.

Field Value
 ImageReaderWriterSpi.names   Same values than the main provider, suffixed by the given string. 
 ImageReaderWriterSpi.suffixes   Same values than the main provider. 
 ImageReaderWriterSpi.MIMETypes   Same values than the main provider, suffixed by the given string. 
 ImageReaderAdapter.inputTypes   String, File, URI, URL 

It is up to subclass constructors to initialize all other instance variables in order to provide working versions of every methods.

Since:
3.07
Version:
3.20
Author:
Martin Desruisseaux (Geomatys)
See Also:
ImageWriterAdapter.Spi
Module:
coverage/geotk-coverageio (download)    View source code for this class

Field Summary
protected  ImageReaderSpi main
          The provider of the readers to use for reading the pixel values.
 
Fields inherited from class ImageReaderSpi
inputTypes, STANDARD_INPUT_TYPE, writerSpiNames
 
Fields inherited from class ImageReaderWriterSpi
extraImageMetadataFormatClassNames, extraImageMetadataFormatNames, extraStreamMetadataFormatClassNames, extraStreamMetadataFormatNames, MIMETypes, names, nativeImageMetadataFormatClassName, nativeImageMetadataFormatName, nativeStreamMetadataFormatClassName, nativeStreamMetadataFormatName, pluginClassName, suffixes, supportsStandardImageMetadataFormat, supportsStandardStreamMetadataFormat
 
Fields inherited from class IIOServiceProvider
vendorName, version
 
Constructor Summary
protected ImageReaderAdapter.Spi(ImageReaderSpi main)
          Deprecated. Specify a suffix.
protected ImageReaderAdapter.Spi(ImageReaderSpi main, String formatNameSuffix)
          Creates an ImageReaderAdapter.Spi wrapping the given provider.
protected ImageReaderAdapter.Spi(String format)
          Deprecated. Specify a suffix.
protected ImageReaderAdapter.Spi(String format, String suffix)
          Creates a provider which will use the given format for reading pixel values.
 
Method Summary
 boolean canDecodeInput(Object source)
          Returns true if the supplied source object appears to be of the format supported by this reader.
 IIOMetadataFormat getImageMetadataFormat(String formatName)
          Returns a description of the image metadata of the given name.
 Set<InformationType> getModifiedInformation(Object source)
          Returns the kind of information that this wrapper will add or modify compared to the main reader.
 IIOMetadataFormat getStreamMetadataFormat(String formatName)
          Returns a description of the stream metadata of the given name.
 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.
static ImageReaderSpi unwrap(ImageReaderSpi spi)
          If the given provider is an instance of ImageReaderAdapter.Spi, returns the underlying main provider.
 
Methods inherited from class ImageReaderSpi
createReaderInstance, createReaderInstance, getImageWriterSpiNames, getInputTypes, isOwnReader
 
Methods inherited from class ImageReaderWriterSpi
getExtraImageMetadataFormatNames, getExtraStreamMetadataFormatNames, getFileSuffixes, getFormatNames, getMIMETypes, getNativeImageMetadataFormatName, getNativeStreamMetadataFormatName, getPluginClassName, isStandardImageMetadataFormatSupported, isStandardStreamMetadataFormatSupported
 
Methods inherited from class IIOServiceProvider
getDescription, getVendorName, getVersion, onDeregistration
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

main

protected final ImageReaderSpi main
The provider of the readers to use for reading the pixel values. This is the provider specified at the construction time.

Constructor Detail

ImageReaderAdapter.Spi

@Deprecated
protected ImageReaderAdapter.Spi(ImageReaderSpi main)
Deprecated. Specify a suffix.


ImageReaderAdapter.Spi

@Deprecated
protected ImageReaderAdapter.Spi(String format)
Deprecated. Specify a suffix.


ImageReaderAdapter.Spi

protected ImageReaderAdapter.Spi(ImageReaderSpi main,
                                 String formatNameSuffix)
Creates an ImageReaderAdapter.Spi wrapping the given provider. The fields are initialized as documented in the class javadoc. It is up to the subclass to initialize all other instance variables in order to provide working versions of all methods.

For efficiency reasons, the inputTypes field is initialized to a shared array. Subclasses can assign new arrays, but should not modify the default array content.

Parameters:
main - The provider of the readers to use for reading the pixel values.
formatNameSuffix - The suffix to append to format names and MIME types.
Since:
3.20

ImageReaderAdapter.Spi

protected ImageReaderAdapter.Spi(String format,
                                 String suffix)
                          throws IllegalArgumentException
Creates a provider which will use the given format for reading pixel values. This is a convenience constructor for the above constructor with a provider fetched from the given format name.

Parameters:
format - The name of the provider to use for reading the pixel values.
suffix - The suffix to append to format names and MIME types.
Throws:
IllegalArgumentException - If no provider is found for the given format.
Since:
3.20
Method Detail

getStreamMetadataFormat

public IIOMetadataFormat getStreamMetadataFormat(String formatName)
Returns a description of the stream metadata of the given name. If no description is available, then this method returns null.

Overrides:
getStreamMetadataFormat in class SpatialImageReader.Spi
Parameters:
formatName - The desired stream metadata format.
Returns:
The stream metadata format of the given name.

getImageMetadataFormat

public IIOMetadataFormat getImageMetadataFormat(String formatName)
Returns a description of the image metadata of the given name. If no description is available, then this method returns null.

Overrides:
getImageMetadataFormat in class SpatialImageReader.Spi
Parameters:
formatName - The desired image metadata format.
Returns:
The image metadata format of the given name.

canDecodeInput

public boolean canDecodeInput(Object source)
                       throws IOException
Returns true if the supplied source object appears to be of the format supported by this reader. The default implementation checks if the given source is an instance of one of the inputTypes, then delegates to the provider given at construction time. A temporary ImageInputStream is created if needed.

Specified by:
canDecodeInput in class ImageReaderSpi
Parameters:
source - The input (typically a File) to be decoded.
Returns:
true if it is likely that the file can be decoded.
Throws:
IOException - If an error occurred while reading the file.

getModifiedInformation

public Set<InformationType> getModifiedInformation(Object source)
                                            throws IOException
Returns the kind of information that this wrapper will add or modify compared to the main reader. If this method returns an empty set, then there is no raison to use this adapter instead than the main reader.

The default implementation conservatively returns all of the InformationType enum values. Subclasses should return more accurate information when possible.

Parameters:
source - The input (typically a File) to be decoded.
Returns:
The set of information to be read or modified by this adapter.
Throws:
IOException - If an error occurred while reading the file.
Since:
3.20

onRegistration

public 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. The default implementation conservatively gives precedence to the main provider, using the code below:
registry.setOrdering(category, main, this);
The plugin order matter when an image reader is selected by file suffix, because the file suffixes of this adapter are the same than the file suffixes of the main provider by default.

Specified by:
onRegistration in interface RegisterableService
Overrides:
onRegistration in class IIOServiceProvider
See Also:
ServiceRegistry.setOrdering(Class, Object, Object)

unwrap

public static ImageReaderSpi unwrap(ImageReaderSpi spi)
If the given provider is an instance of ImageReaderAdapter.Spi, returns the underlying main provider. Otherwise returns the given provider unchanged.

This method is convenient when the caller is not interested in spatial metadata, in order to ensure that the cost of parsing TFW, PRJ or similar files is avoided.

Parameters:
spi - An image reader provider, or null.
Returns:
The wrapped image reader provider, or null.
Since:
3.14


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.