org.geotools.image.io
Class StreamImageReader

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

public abstract class StreamImageReader
extends GeographicImageReader

Base class for simple image decoders. This class provides a getInputStream() method, which returns the input as an InputStream for convenience. Different kinds of input like File or URL are automatically handled.

Since:
2.4
Version:
$Id: StreamImageReader.java 30679 2008-06-13 10:19:41Z acuster $
Author:
Martin Desruisseaux (IRD)

Nested Class Summary
static class StreamImageReader.Spi
          Service provider interface (SPI) for StreamImageReaders.
 
Field Summary
protected  java.io.Closeable closeOnReset
          The stream to close on setInput(...), reset() or dispose() method invocation.
 
Fields inherited from class javax.imageio.ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
 
Constructor Summary
protected StreamImageReader(javax.imageio.spi.ImageReaderSpi provider)
          Constructs a new image reader.
 
Method Summary
protected  void close()
          Closes the input stream created by getInputStream().
 void dispose()
          Allows any resources held by this reader to be released.
protected  void finalize()
          Closes the streams.
protected  java.io.InputStream getInputStream()
          Returns the input as an input stream object.
protected  long getStreamLength()
          Returns the stream length in bytes, or -1 if unknown.
 void reset()
          Restores the StreamImageReader to its initial state.
 void setInput(java.lang.Object input, boolean seekForwardOnly, boolean ignoreMetadata)
          Sets the input source to use.
 
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
 

Field Detail

closeOnReset

protected java.io.Closeable closeOnReset
The stream to close on setInput(...), reset() or dispose() method invocation. This stream is typically an input stream or a reader created by getInputStream() or similar methods in subclasses.

This field is never equals to the user-specified input, since the usual ImageReader contract is to not close the user-provided stream. It is set to a non-null value only if a stream has been created from an other user object like File or URL.

See Also:
getInputStream(), TextImageReader.getReader(), close()
Constructor Detail

StreamImageReader

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

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

setInput

public void setInput(java.lang.Object input,
                     boolean seekForwardOnly,
                     boolean ignoreMetadata)
Sets the input source to use. Input may be one of the following object: File, URL, Reader (for ASCII data), InputStream or ImageInputStream. If input is null, then any currently set input source will be removed.

Overrides:
setInput in class GeographicImageReader
Parameters:
input - The input object to use for future decoding.
seekForwardOnly - If true, images and metadata may only be read in ascending order from this input source.
ignoreMetadata - If true, metadata may be ignored during reads.
See Also:
ImageReader.getInput(), getInputStream()

getStreamLength

protected long getStreamLength()
                        throws java.io.IOException
Returns the stream length in bytes, or -1 if unknown. This method checks the input type and invokes one of File.length(), ImageInputStream.length() ou URLConnection.getContentLength() method accordingly.

Returns:
The stream length, or -1 is unknown.
Throws:
java.io.IOException - if an I/O error occured.

getInputStream

protected java.io.InputStream getInputStream()
                                      throws java.lang.IllegalStateException,
                                             java.io.IOException
Returns the input as an input stream object. If the input is already an input stream, it is returned unchanged. Otherwise this method creates a new input stream (usually not buffered) from File, URL, URLConnection or ImageInputStream inputs.

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

Returns:
ImageReader.getInput() as an InputStream. This input stream is usually not buffered.
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(), TextImageReader.getReader()

close

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

This method is invoked automatically by setInput(...), reset(), dispose() or finalize() methods and doesn't need to be invoked explicitly. It has protected access only in order to allow overriding by subclasses.

Throws:
java.io.IOException - if an error occured while closing the stream.
See Also:
closeOnReset

reset

public void reset()
Restores the StreamImageReader to its initial state. If an input stream were created by a previous call to getInputStream(), it will be closed before to reset this reader.

Overrides:
reset in class javax.imageio.ImageReader

dispose

public void dispose()
Allows any resources held by this reader to be released. If an input stream were created by a previous call to getInputStream(), it will be closed before to dispose this reader.

Overrides:
dispose in class javax.imageio.ImageReader

finalize

protected void finalize()
                 throws java.lang.Throwable
Closes the streams. This method is automatically invoked by the garbage collector.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable


Copyright © 1996-2010 Geotools. All Rights Reserved.