org.geotoolkit.image.io
Class TextImageReader

Object
  extended by ImageReader
      extended by SpatialImageReader
          extended by StreamImageReader
              extended by TextImageReader
All Implemented Interfaces:
WarningProducer, Disposable, Localized
Direct Known Subclasses:
AsciiGridReader, TextMatrixImageReader, TextRecordImageReader

public abstract class TextImageReader
extends StreamImageReader

Base class for image readers that expect a BufferedReader input source. "Text images" are usually ASCII files where pixels values are actually the geophysical values. This base class provides the following conveniences:

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

Nested Class Summary
protected static class TextImageReader.Spi
          Service provider interface (SPI) for TextImageReaders.
 
Field Summary
 
Fields inherited from class StreamImageReader
closeOnReset
 
Fields inherited from class ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
 
Fields inherited from interface WarningProducer
LOGGER
 
Constructor Summary
protected TextImageReader(TextImageReader.Spi provider)
          Constructs a new image reader.
 
Method Summary
protected  void close()
          Closes the reader created by getReader().
protected  Charset getCharset(InputStream input)
          Returns the character set to use for decoding the string from the input stream.
protected  LineFormat getLineFormat(int imageIndex)
          Returns the line format to use for parsing every lines in the input stream.
protected  double getPadValue(int imageIndex)
          Returns the pad value for missing data, or Double.NaN if none.
protected  String getPositionString(String message)
          Returns a string representation of the current stream position.
protected  BufferedReader getReader()
          Returns the input as an buffered reader.
protected  boolean isComment(String line)
          Returns true if the specified line is a comment.
 
Methods inherited from class StreamImageReader
finalize, getChannel, getInputStream, getStreamLength, setInput
 
Methods inherited from class SpatialImageReader
checkBandIndex, checkImageIndex, collapseNoDataValues, createMetadata, dispose, flipVertically, getDefaultReadParam, getDestination, getDimension, getGridEnvelope, getImageMetadata, getImageType, getImageTypes, getNumBands, getNumImages, getRawDataType, getRawImageType, getStreamMetadata, hasColors, warningOccurred
 
Methods inherited from class ImageReader
abort, abortRequested, addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, canReadRaster, checkReadParamBandSettings, clearAbortRequest, computeRegions, getAspectRatio, getAvailableLocales, getDestination, getFormatName, getHeight, getImageMetadata, getInput, getLocale, getMinIndex, getNumThumbnails, getOriginatingProvider, getSourceRegion, getStreamMetadata, getThumbnailHeight, getThumbnailWidth, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getWidth, hasThumbnails, isIgnoringMetadata, isImageTiled, isRandomAccessEasy, isSeekForwardOnly, processImageComplete, processImageProgress, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, processWarningOccurred, read, read, readAll, readAll, readAsRenderedImage, readerSupportsThumbnails, readRaster, readThumbnail, readTile, readTileRaster, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, reset, setInput, setInput, setLocale
 
Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface Localized
getLocale
 

Constructor Detail

TextImageReader

protected TextImageReader(TextImageReader.Spi provider)
Constructs a new image reader.

Parameters:
provider - The ImageReaderSpi that is constructing this object, or null.
Method Detail

getCharset

protected Charset getCharset(InputStream input)
                      throws IOException
Returns the character set to use for decoding the string from the input stream. The default implementation returns the character set specified to the TextImageReader.Spi object given to this TextImageReader constructor. Subclasses can override this method if they want to detect the character encoding in some other way.

Parameters:
input - The input stream.
Returns:
The character encoding, or null for the platform default encoding.
Throws:
IOException - If reading from the input stream failed.
See Also:
TextImageReader.Spi.charset

getLineFormat

protected LineFormat getLineFormat(int imageIndex)
                            throws IOException
Returns the line format to use for parsing every lines in the input stream. The default implementation creates a new LineFormat instance using the locale specified by TextImageReader.Spi.locale. Subclasses should override this method if they want more control on the parser to be created.

Parameters:
imageIndex - the index of the image to be queried.
Returns:
The object to use for parsing lines of text.
Throws:
IOException - If reading from the input stream failed.
See Also:
TextImageReader.Spi.locale

getPadValue

protected double getPadValue(int imageIndex)
                      throws IOException
Returns the pad value for missing data, or Double.NaN if none. The pad value will applies to all columns except the one for x and y values, if any.

The default implementation returns the pad value specified to the TextImageReader.Spi object given to this TextImageReader constructor. Subclasses can override this method if they want to detect the pad value in some other way.

Parameters:
imageIndex - the index of the image to be queried.
Returns:
The pad value, or Double.NaN if none.
Throws:
IOException - If reading from the input stream failed.
See Also:
TextImageReader.Spi.padValue

getReader

protected BufferedReader getReader()
                            throws IllegalStateException,
                                   IOException
Returns the input as an buffered reader. If the input is already a buffered reader, it is returned unchanged. Otherwise this method creates a new line number reader from various input types including File, URL, URLConnection, Reader, InputStream and ImageInputStream.

This method creates a new reader only when first invoked. All subsequent calls will returns the same instance. Consequently, the returned reader should never be closed by the caller. It may be closed automatically when setInput(...), reset() or dispose() methods are invoked.

Returns:
ImageReader.getInput() as a BufferedReader.
Throws:
IllegalStateException - if the input is not set.
IOException - If the input stream can't be created for an other reason.
See Also:
ImageReader.getInput(), StreamImageReader.getInputStream()

isComment

protected boolean isComment(String line)
Returns true if the specified line is a comment. This method is invoked automatically during a read operation. The default implementation returns true if the line is empty or if the first non-whitespace character is '#', and false otherwise. Override this method if comment lines should be determined in a different way.

Parameters:
line - A line to be parsed.
Returns:
true if the line is a comment and should be ignored, or false if it should be parsed.

getPositionString

protected String getPositionString(String message)
Returns a string representation of the current stream position. For example this method may returns something like "Line 14 in file HUV18204.asc". This method returns null if the stream position is unknown.

Parameters:
message - An optional message to append to the stream position, or null if none.
Returns:
A string representation of current stream position.

close

protected void close()
              throws IOException
Closes the reader created by getReader(). This method does nothing if the reader is the input instance given by the user rather than a reader created by this class from a File or URL input.

Overrides:
close in class StreamImageReader
Throws:
IOException - If an error occurred while closing the reader.
See Also:
StreamImageReader.closeOnReset


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