org.geotools.image.io
Class StreamImageWriter

java.lang.Object
  extended by javax.imageio.ImageWriter
      extended by org.geotools.image.io.GeographicImageWriter
          extended by org.geotools.image.io.StreamImageWriter
All Implemented Interfaces:
javax.imageio.ImageTranscoder
Direct Known Subclasses:
TextImageWriter

public abstract class StreamImageWriter
extends GeographicImageWriter

Base class for simple image encoders. This class provides a getOutputStream() method, which returns the output as an OutputStream for convenience. Different kinds of output like File or URL are automatically handled.

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

Nested Class Summary
static class StreamImageWriter.Spi
          Service provider interface (SPI) for StreamImageWriters.
 
Field Summary
protected  java.io.Closeable closeOnReset
          The stream to close on setOutput(java.lang.Object), reset() or dispose() method invocation.
 
Fields inherited from class javax.imageio.ImageWriter
availableLocales, locale, originatingProvider, output, progressListeners, warningListeners, warningLocales
 
Constructor Summary
protected StreamImageWriter(javax.imageio.spi.ImageWriterSpi provider)
          Constructs a new image writer.
 
Method Summary
protected  void close()
          Closes the output stream created by getOutputStream().
 void dispose()
          Allows any resources held by this writer to be released.
protected  void finalize()
          Closes the streams.
protected  java.io.OutputStream getOutputStream()
          Returns the output as an output stream object.
 void reset()
          Restores the StreamImageWriter to its initial state.
 void setOutput(java.lang.Object output)
          Sets the output source to use.
 
Methods inherited from class org.geotools.image.io.GeographicImageWriter
canWriteRasters, computeSize, convertImageMetadata, convertStreamMetadata, createRectIter, getDefaultImageMetadata, getDefaultStreamMetadata, processImageComplete, processImageStarted, processThumbnailComplete, processThumbnailStarted, processWarningOccurred, processWarningOccurred, warningOccurred
 
Methods inherited from class javax.imageio.ImageWriter
abort, abortRequested, addIIOWriteProgressListener, addIIOWriteWarningListener, canInsertEmpty, canInsertImage, canRemoveImage, canReplaceImageMetadata, canReplacePixels, canReplaceStreamMetadata, canWriteEmpty, canWriteSequence, clearAbortRequest, endInsertEmpty, endReplacePixels, endWriteEmpty, endWriteSequence, getAvailableLocales, getDefaultWriteParam, getLocale, getNumThumbnailsSupported, getOriginatingProvider, getOutput, getPreferredThumbnailSizes, prepareInsertEmpty, prepareReplacePixels, prepareWriteEmpty, prepareWriteSequence, processImageProgress, processImageStarted, processThumbnailProgress, processThumbnailStarted, processWarningOccurred, processWarningOccurred, processWriteAborted, removeAllIIOWriteProgressListeners, removeAllIIOWriteWarningListeners, removeIIOWriteProgressListener, removeIIOWriteWarningListener, removeImage, replaceImageMetadata, replacePixels, replacePixels, replaceStreamMetadata, setLocale, write, write, write, writeInsert, writeToSequence
 
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 setOutput(java.lang.Object), reset() or dispose() method invocation. This stream is typically an output stream or a writer created by getOutputStream() or similar methods in subclasses.

This field is never equals to the user-specified output, since the usual ImageWriter 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:
getOutputStream(), TextImageWriter.getWriter(javax.imageio.ImageWriteParam), close()
Constructor Detail

StreamImageWriter

protected StreamImageWriter(javax.imageio.spi.ImageWriterSpi provider)
Constructs a new image writer.

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

setOutput

public void setOutput(java.lang.Object output)
Sets the output source to use. Output may be one of the following object: File, URL, Writer (for ASCII data), OutputStream or ImageOutputStream. If output is null, then any currently set output source will be removed.

Overrides:
setOutput in class GeographicImageWriter
Parameters:
output - The output object to use for future writing.
See Also:
ImageWriter.getOutput(), getOutputStream()

getOutputStream

protected java.io.OutputStream getOutputStream()
                                        throws java.lang.IllegalStateException,
                                               java.io.IOException
Returns the output as an output stream object. If the output is already an output stream, it is returned unchanged. Otherwise this method creates a new output stream (usually not buffered) from File, URL, URLConnection or ImageOutputStream outputs.

This method creates a new output 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 setOutput(java.lang.Object), reset() or dispose() methods are invoked.

Returns:
ImageWriter.getOutput() as an OutputStream. This output stream is usually not buffered.
Throws:
java.lang.IllegalStateException - if the output is not set.
java.io.IOException - If the output stream can't be created for an other reason.
See Also:
ImageWriter.getOutput(), TextImageWriter.getWriter(javax.imageio.ImageWriteParam)

close

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

This method is invoked automatically by setOutput(java.lang.Object), 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 StreamImageWriter to its initial state. If an output stream were created by a previous call to getOutputStream(), it will be closed before to reset this writer.

Overrides:
reset in class javax.imageio.ImageWriter

dispose

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

Overrides:
dispose in class javax.imageio.ImageWriter

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.