org.geotoolkit.image.io.plugin
Class TextRecordImageReader.Spi

Object
  extended by IIOServiceProvider
      extended by ImageReaderWriterSpi
          extended by ImageReaderSpi
              extended by SpatialImageReader.Spi
                  extended by StreamImageReader.Spi
                      extended by TextImageReader.Spi
                          extended by TextRecordImageReader.Spi
All Implemented Interfaces:
RegisterableService
Enclosing class:
TextRecordImageReader

public static class TextRecordImageReader.Spi
extends TextImageReader.Spi

Service provider interface (SPI) for TextRecordImageReaders. This SPI provides necessary implementation for creating default TextRecordImageReader using default locale and character set. The default constructor initializes the fields to the values listed below:

FieldValue
 ImageReaderWriterSpi.names   "records" 
 ImageReaderWriterSpi.MIMETypes   "text/plain" 
 ImageReaderWriterSpi.pluginClassName   "org.geotoolkit.image.io.plugin.TextRecordImageReader" 
 IIOServiceProvider.vendorName   "Geotoolkit.org" 
 IIOServiceProvider.version   Version.GEOTOOLKIT 
 xColumn   0 
 yColumn   1 
 gridTolerance   May vary. 
See super-class javadoc for remaining fields

Subclasses can set some fields at construction time in order to tune the reader to a particular environment, e.g.:

public final class CLSImageReaderSpi extends TextRecordImageReader.Spi {
    public CLSImageReaderSpi() {
        names      = new String[] {"CLS"};
        MIMETypes  = new String[] {"text/x-records-CLS"};
        vendorName = "Institut de Recherche pour le Développement";
        version    = "1.0";
        locale     = Locale.US;
        charset    = Charset.forName("ISO-8859-1"); // ISO-LATIN-1
        padValue   = -9999;
    }
}
Note: fields vendorName and version are only informatives.
There is no need to override any method in this example. However, developers can gain more control by creating subclasses of TextRecordImageReader and Spi.

Since:
3.08 (derived from 2.1)
Version:
3.08
Author:
Martin Desruisseaux (IRD, Geomatys)
Module:
coverage/geotk-coverageio (download)    View source code for this class

Field Summary
protected  float gridTolerance
          A tolerance factor during decoding, between 0 and 1.
protected  int xColumn
          0-based column number for x values.
protected  int yColumn
          0-based column number for y values.
 
Fields inherited from class TextImageReader.Spi
charset, locale, padValue
 
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
TextRecordImageReader.Spi()
          Constructs a default TextRecordImageReader.Spi.
 
Method Summary
 ImageReader createReaderInstance(Object extension)
          Returns an instance of the ImageReader implementation associated with this service provider.
 String getDescription(Locale locale)
          Returns a brief, human-readable description of this service provider and its associated implementation.
protected  boolean isValidColumnCount(int count)
          Invoked by isValidColumnCount(int) for determining if the given number of columns is valid.
protected  boolean isValidContent(double[][] rows)
          Returns true if the content of the first few rows seems valid, or false otherwise.
 void onRegistration(ServiceRegistry registry, Class<?> category)
          Invoked when this Service Provider is registered.
 
Methods inherited from class TextImageReader.Spi
canDecodeInput, canDecodeInput, isValidHeader
 
Methods inherited from class SpatialImageReader.Spi
getImageMetadataFormat, getStreamMetadataFormat
 
Methods inherited from class ImageReaderSpi
createReaderInstance, getImageWriterSpiNames, getInputTypes, isOwnReader
 
Methods inherited from class ImageReaderWriterSpi
getExtraImageMetadataFormatNames, getExtraStreamMetadataFormatNames, getFileSuffixes, getFormatNames, getMIMETypes, getNativeImageMetadataFormatName, getNativeStreamMetadataFormatName, getPluginClassName, isStandardImageMetadataFormatSupported, isStandardStreamMetadataFormatSupported
 
Methods inherited from class IIOServiceProvider
getVendorName, getVersion, onDeregistration
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xColumn

protected int xColumn
0-based column number for x values. The default value is 0.

See Also:
TextRecordImageReader.getColumnX(int)

yColumn

protected int yColumn
0-based column number for y values. The default value is 1.

See Also:
TextRecordImageReader.getColumnY(int)

gridTolerance

protected float gridTolerance
A tolerance factor during decoding, between 0 and 1. During decoding, the image reader computes cell's width and height (i.e. the smallest non-null difference between ordinates in a given column: x for cell's width and y for cell's height). Then, it checks if every coordinate points fall on a grid having this cell's size. If a point depart from more than gridTolerance percent of cell's width or height, an exception is thrown.

gridTolerance should be a small number like 1E-5f or 1E-3f. The later is more tolerant than the former.

Constructor Detail

TextRecordImageReader.Spi

public TextRecordImageReader.Spi()
Constructs a default TextRecordImageReader.Spi. The fields are initialized as documented in the class javadoc. Subclasses can modify those values if desired.

For efficiency reasons, the above fields are initialized to shared arrays. Subclasses can assign new arrays, but should not modify the default array content.

Method Detail

getDescription

public String getDescription(Locale locale)
Returns a brief, human-readable description of this service provider and its associated implementation. The resulting string should be localized for the supplied locale, if possible.

Specified by:
getDescription in class IIOServiceProvider
Parameters:
locale - A Locale for which the return value should be localized.
Returns:
A String containing a description of this service provider.

createReaderInstance

public ImageReader createReaderInstance(Object extension)
                                 throws IOException
Returns an instance of the ImageReader implementation associated with this service provider.

Specified by:
createReaderInstance in class ImageReaderSpi
Parameters:
extension - An optional extension object, which may be null.
Returns:
An image reader instance.
Throws:
IOException - if the attempt to instantiate the reader fails.

isValidContent

protected boolean isValidContent(double[][] rows)
Returns true if the content of the first few rows seems valid, or false otherwise. The default implementation performs the same check than the super-class, and additionaly checks if the (x, y) values seem distributed on a regular grid.

Overrides:
isValidContent in class TextImageReader.Spi
Parameters:
rows - The first few rows.
Returns:
true if the given rows seem to have a valid content.

isValidColumnCount

protected boolean isValidColumnCount(int count)
Invoked by isValidColumnCount(int) for determining if the given number of columns is valid. Note that this is the number of columns in the data file, not to be confused with the image width.

Overrides:
isValidColumnCount in class TextImageReader.Spi
Parameters:
count - The number of columns in the first few line of rows.
Returns:
true if the given number of columns seems to be valid.
Since:
3.07

onRegistration

public void onRegistration(ServiceRegistry registry,
                           Class<?> category)
Invoked when this Service Provider is registered. This method sets the ordering of this TextRecordImageReader.Spi before TextMatrixImageReader.Spi, because the later is generic enough for claiming to be able to read records file.

Specified by:
onRegistration in interface RegisterableService
Overrides:
onRegistration in class IIOServiceProvider
Parameters:
registry - The registry where is service is registered.
category - The category for which this service is registered.


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