org.geotoolkit.image.io
Class TextImageReader.Spi

Object
  extended by IIOServiceProvider
      extended by ImageReaderWriterSpi
          extended by ImageReaderSpi
              extended by SpatialImageReader.Spi
                  extended by StreamImageReader.Spi
                      extended by TextImageReader.Spi
All Implemented Interfaces:
RegisterableService
Direct Known Subclasses:
AsciiGridReader.Spi, TextMatrixImageReader.Spi, TextRecordImageReader.Spi
Enclosing class:
TextImageReader

protected abstract static class TextImageReader.Spi
extends StreamImageReader.Spi

Service provider interface (SPI) for TextImageReaders. This SPI provides additional fields controlling the character encoding (charset), the local to use for parsing numbers, dates or other objects (locale) and the value used in place of missing pixel values (padValue).

By default the charset and locale fields are initialized to null, which stands for the platform-dependent character encoding and locale. In addition the padValue is set to Double.NaN, which means that there is no pad value. If a subclass wants to fix the encoding, locale and pad value to some format-specific values, it shall specify those values at construction time as in the example below:

public Spi() {
    charset  = Charset.forName("ISO-8859-1"); // ISO Latin Alphabet No. 1
    locale   = Locale.US;
    padValue = -9999;
}
The table below summarizes the initial values. Those values can be modified by subclass constructors.

Field Value
 ImageReaderSpi.inputTypes   String, File, URI, URL, URLConnection, Reader, InputStream, ImageInputStream, ReadableByteChannel 
 ImageReaderWriterSpi.suffixes   "txt", "TXT", "asc", "ASC", "dat", "DAT" 
 charset   null (stands for the platform default
 locale   null (stands for the platform default
 padValue   Double.NaN (stands for no pad-value) 
See super-class javadoc for remaining fields

Since:
3.08 (derived from 2.4)
Version:
3.07
Author:
Martin Desruisseaux (IRD, Geomatys)
See Also:
TextImageWriter.Spi
Module:
coverage/geotk-coverageio (download)    View source code for this class

Field Summary
protected  Charset charset
          Character encoding, or null for the default.
protected  Locale locale
          The locale for numbers or dates parsing.
protected  double padValue
          The pad value, or Double.NaN if none.
 
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 TextImageReader.Spi()
          Constructs a quasi-blank TextImageReader.Spi.
 
Method Summary
 boolean canDecodeInput(Object source)
          Returns true if the supplied source object appears to be of the format supported by this reader.
protected  boolean canDecodeInput(Object source, int readAheadLimit)
          Returns true if the supplied source object appears to be of the format supported by this reader.
protected  boolean isValidColumnCount(int count)
          Invoked by isValidContent(double[][]) for determining if the given number of columns is likely to be valid.
protected  boolean isValidContent(double[][] rows)
          Invoked by canDecodeInput(Object, int) for determining if the given rows are likely to be valid.
protected  boolean isValidHeader(Set<String> keywords)
          Invoked by canDecodeInput(Object, int) for determining if the given header is likely to be valid.
 
Methods inherited from class SpatialImageReader.Spi
addExtraMetadataFormat, getImageMetadataFormat, getStreamMetadataFormat
 
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, onRegistration
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

charset

protected Charset charset
Character encoding, or null for the default. This field is initially null, which means to use the platform-dependent encoding. Subclasses shall set a non-null value if the files to be decoded use some specific character encoding.

See Also:
TextImageReader.getCharset(InputStream)

locale

protected Locale locale
The locale for numbers or dates parsing. For example Locale.US means that numbers are expected to use a dot for the decimal separator. This field is initially null, which means that the default locale will be used.

See Also:
TextImageReader.getLineFormat(int)

padValue

protected double padValue
The pad value, or Double.NaN if none. Every occurrences of pixel value equals to this pad value will be replaced by Double.NaN during the read operation. Note that this replacement doesn't apply to non-pixel values (for example x, y coordinates in the format read by TextRecordImageReader).

See Also:
TextImageReader.getPadValue(int)
Constructor Detail

TextImageReader.Spi

protected TextImageReader.Spi()
Constructs a quasi-blank TextImageReader.Spi. This constructor initializes the fields 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 above fields are initialized to shared arrays. Subclasses can assign new arrays, but should not modify the default array content.

Method Detail

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 tries to parse the first few lines up to 2048 characters, as below:
return canDecodeInput(source, 2048);

Specified by:
canDecodeInput in class ImageReaderSpi
Parameters:
source - The object (typically an ImageInputStream) to be decoded.
Returns:
true if the source seems readable.
Throws:
IOException - If an error occurred during reading.

canDecodeInput

protected boolean canDecodeInput(Object source,
                                 int readAheadLimit)
                          throws IOException
Returns true if the supplied source object appears to be of the format supported by this reader. The default implementation tries to parse the first few lines up to the specified number of characters, then gives those lines to the isValidHeader(Set) and isValidContent(double[][]) methods.

The default implementation is suitable for TextMatrixImageReader, i.e. it expects only rows for pixel values (no header) and all rows shall have the same length. If this behavior needs to be changed, consider overriding the isValidHeader and isValidContent methods.

Parameters:
source - The object (typically an ImageInputStream) to be decoded.
readAheadLimit - Maximum number of characters to read. If this amount is reached but this method still unable to make a choice, then it conservatively returns false.
Returns:
true if the source seems readable.
Throws:
IOException - If an error occurred during reading.

isValidHeader

protected boolean isValidHeader(Set<String> keywords)
Invoked by canDecodeInput(Object, int) for determining if the given header is likely to be valid. This method receives in argument a keywords set containing the first word of every header lines (defined below), converted to upper cases using the locale defined in this provider.

A header line is defined as a line which is not a comment line, appears before the first row of pixel values and where the first non-blank character is a Java identifier start.

The default implementation returns true if the given set is empty. In other words, by default no header is allowed in the data file.

Parameters:
keywords - The first word found in every header lines, converted to upper-case.
Returns:
true if the set of keywords is known to this format.
Since:
3.07

isValidContent

protected boolean isValidContent(double[][] rows)
Invoked by canDecodeInput(Object, int) for determining if the given rows are likely to be valid. This method receives in argument a rows array containing the first few lines of data. The number of rows depends on the average row length and the readAheadLimit argument given to canDecodeInput.

The default implementation returns true if there is at least one row and every row have the same number of columns.

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 isValidContent(double[][]) for determining if the given number of columns is likely to be valid. This method receives in argument the length of every rows that were given to isValidContent, when that length is constant.

The default implementation returns true if the number of columns is greater than zero. Subclasses can override this method if they know the expected number of columns.

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


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