org.geotools.image.io.text
Class TextImageReader

java.lang.Object
  extended by javax.imageio.ImageReader
      extended by org.geotools.image.io.GeographicImageReader
          extended by org.geotools.image.io.StreamImageReader
              extended by org.geotools.image.io.text.TextImageReader
Direct Known Subclasses:
TextMatrixImageReader, TextRecordImageReader

public abstract class TextImageReader
extends StreamImageReader

Base class for text image decoders. "Text images" are usually ASCII files containing pixel as geophysical values. This base class provides a convenient way to get BufferedReader for reading lines.

TextImageReader accepts many input types, including File, URL, Reader, InputStream and ImageInputStream. The TextImageReader.Spi provider automatically advises those input types. The above cited Spi provided also provides a convenient way to control the character encoding, with the charset field. Developer can gain yet more control on character encoding by overriding the getCharset(java.io.InputStream) method.

Since:
2.4
Version:
$Id: TextImageReader.java 33694 2009-08-06 13:23:57Z aaime $
Author:
Martin Desruisseaux (IRD)

Nested Class Summary
static class TextImageReader.Spi
          Service provider interface (SPI) for TextImageReaders.
 
Field Summary
 
Fields inherited from class org.geotools.image.io.StreamImageReader
closeOnReset
 
Fields inherited from class javax.imageio.ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
 
Constructor Summary
protected TextImageReader(javax.imageio.spi.ImageReaderSpi provider)
          Constructs a new image reader.
 
Method Summary
protected  void close()
          Closes the reader created by getReader().
protected  java.nio.charset.Charset getCharset(java.io.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)
          Deprecated. Should be specified in metadata instead, and implementations should use SampleConverter.
protected  java.lang.String getPositionString(java.lang.String message)
          Returns a string representation of the current stream position.
protected  java.io.BufferedReader getReader()
          Returns the input as an buffered reader.
protected  boolean isComment(java.lang.String line)
          Returns true if the specified line is a comment.
 
Methods inherited from class org.geotools.image.io.StreamImageReader
dispose, finalize, getInputStream, getStreamLength, reset, setInput
 
Methods inherited from class org.geotools.image.io.GeographicImageReader
checkBandIndex, checkImageIndex, collapseNoDataValues, flipVertically, getDefaultReadParam, getDestination, getDimension, getGeographicMetadata, getImageMetadata, getImageTypes, getNumBands, getNumImages, getRawDataType, getRawImageType, getRawImageType, getStreamMetadata, read, warningOccurred
 
Methods inherited from class javax.imageio.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, readAll, readAll, readAsRenderedImage, readerSupportsThumbnails, readRaster, readThumbnail, readTile, readTileRaster, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, setInput, setInput, setLocale
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextImageReader

protected TextImageReader(javax.imageio.spi.ImageReaderSpi provider)
Constructs a new image reader.

Parameters:
provider - The provider that is invoking this constructor, or null if none.
Method Detail

getCharset

protected java.nio.charset.Charset getCharset(java.io.InputStream input)
                                       throws java.io.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:
java.io.IOException - If reading from the input stream failed.
See Also:
TextImageReader.Spi.charset

getLineFormat

protected LineFormat getLineFormat(int imageIndex)
                            throws java.io.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.
Throws:
java.io.IOException - If reading from the input stream failed.
See Also:
TextImageReader.Spi.locale

getPadValue

protected double getPadValue(int imageIndex)
                      throws java.io.IOException
Deprecated. Should be specified in metadata instead, and implementations should use SampleConverter.

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.
Throws:
java.io.IOException - If reading from the input stream failed.
See Also:
TextImageReader.Spi.padValue

getReader

protected java.io.BufferedReader getReader()
                                    throws java.lang.IllegalStateException,
                                           java.io.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:
java.lang.IllegalStateException - if the input is not set.
java.io.IOException - If the input stream can't be created for an other reason.
See Also:
ImageReader.getInput(), StreamImageReader.getInputStream()

isComment

protected boolean isComment(java.lang.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 java.lang.String getPositionString(java.lang.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.

close

protected void close()
              throws java.io.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:
java.io.IOException - if an error occured while closing the stream.
See Also:
StreamImageReader.closeOnReset


Copyright © 1996-2010 Geotools. All Rights Reserved.