org.geotoolkit.image.io
Class TextImageWriter

Object
  extended by ImageWriter
      extended by SpatialImageWriter
          extended by StreamImageWriter
              extended by TextImageWriter
All Implemented Interfaces:
ImageTranscoder, WarningProducer, Disposable, Localized
Direct Known Subclasses:
AsciiGridWriter, TextMatrixImageWriter

public abstract class TextImageWriter
extends StreamImageWriter

Base class for image writers that expect a BufferedWriter output. "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:
TextImageReader
Module:
coverage/geotk-coverageio (download)    View source code for this class

Nested Class Summary
protected static class TextImageWriter.Spi
          Service provider interface (SPI) for TextImageWriter.
 
Field Summary
 
Fields inherited from class StreamImageWriter
closeOnReset
 
Fields inherited from class ImageWriter
availableLocales, locale, originatingProvider, output, progressListeners, warningListeners, warningLocales
 
Fields inherited from interface WarningProducer
LOGGER
 
Constructor Summary
protected TextImageWriter(TextImageWriter.Spi provider)
          Constructs a TextImageWriter.
 
Method Summary
protected  void close()
          Closes the writer created by getWriter(...).
protected  NumberFormat createNumberFormat(IIOImage image, ImageWriteParam parameters)
          Returns a number format to be used for formatting the sample values in the given image.
protected  Charset getCharset(ImageWriteParam parameters)
          Returns the character set to use for encoding the string to the output stream.
protected  Locale getDataLocale(ImageWriteParam parameters)
          Returns the locale to use for encoding values, or null for the default.
protected  FieldPosition getExpectedFractionPosition(NumberFormat format)
          Returns the expected position of the fraction part for numbers to be formatted using the given format.
protected  String getLineSeparator(ImageWriteParam parameters)
          Returns the line separator to use when writing to the output stream.
protected  BufferedWriter getWriter(ImageWriteParam parameters)
          Returns the output as a writer.
 
Methods inherited from class StreamImageWriter
finalize, getOutputStream, setOutput
 
Methods inherited from class SpatialImageWriter
canWriteRasters, computeSize, convertImageMetadata, convertStreamMetadata, createRectIter, dispose, getDefaultImageMetadata, getDefaultStreamMetadata, getDefaultWriteParam, getSampleModel, processImageComplete, processImageStarted, processThumbnailComplete, processThumbnailStarted, processWarningOccurred, processWarningOccurred, warningOccurred
 
Methods inherited from class ImageWriter
abort, abortRequested, addIIOWriteProgressListener, addIIOWriteWarningListener, canInsertEmpty, canInsertImage, canRemoveImage, canReplaceImageMetadata, canReplacePixels, canReplaceStreamMetadata, canWriteEmpty, canWriteSequence, clearAbortRequest, endInsertEmpty, endReplacePixels, endWriteEmpty, endWriteSequence, getAvailableLocales, 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, reset, setLocale, write, write, write, writeInsert, writeToSequence
 
Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface Localized
getLocale
 

Constructor Detail

TextImageWriter

protected TextImageWriter(TextImageWriter.Spi provider)
Constructs a TextImageWriter.

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

getDataLocale

protected Locale getDataLocale(ImageWriteParam parameters)
Returns the locale to use for encoding values, or null for the default. The default implementation returns the locale specified to the Spi object given to this TextImageWriter constructor. Subclasses can override this method if they want to specify the data locale in some other way.

Note: This locale should not be confused with ImageWriter.getLocale().

Parameters:
parameters - The write parameters, or null for the defaults.
Returns:
The locale to use for parsing numbers in the image file.
See Also:
TextImageWriter.Spi.locale

getCharset

protected Charset getCharset(ImageWriteParam parameters)
                      throws IOException
Returns the character set to use for encoding the string to the output stream. The default implementation returns the character set specified to the Spi object given to this TextImageWriter constructor. Subclasses can override this method if they want to specify the character encoding in some other way.

Parameters:
parameters - The write parameters, or null for the defaults.
Returns:
The character encoding, or null for the platform default encoding.
Throws:
IOException - If reading from the output stream failed.
See Also:
TextImageWriter.Spi.charset

getLineSeparator

protected String getLineSeparator(ImageWriteParam parameters)
Returns the line separator to use when writing to the output stream. The default implementation returns the line separator specified to the TextImageWriter.Spi object given to this TextImageWriter constructor. Subclasses can override this method if they want to specify the line separator in some other way.

Parameters:
parameters - The write parameters, or null for the defaults.
Returns:
The line separator to use for writing the image.
See Also:
TextImageWriter.Spi.lineSeparator

getWriter

protected BufferedWriter getWriter(ImageWriteParam parameters)
                            throws IllegalStateException,
                                   IOException
Returns the output as a writer. If the output is already a buffered writer, then it is returned unchanged. Otherwise the default implementation creates a new BufferedWriter from various output types including File, URL, URLConnection, Writer, OutputStream and ImageOutputStream.

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

Parameters:
parameters - The write parameters, or null for the defaults.
Returns:
ImageWriter.getOutput() usually as a BufferedWriter.
Throws:
IllegalStateException - if the output is not set.
IOException - If the output stream can't be created for an other reason.
See Also:
ImageWriter.getOutput(), StreamImageWriter.getOutputStream()

createNumberFormat

protected NumberFormat createNumberFormat(IIOImage image,
                                          ImageWriteParam parameters)
Returns a number format to be used for formatting the sample values in the given image.

Parameters:
image - The image or raster to be written.
parameters - The write parameters, or null if the whole image will be written.
Returns:
A number format appropriate for the given image.

getExpectedFractionPosition

protected FieldPosition getExpectedFractionPosition(NumberFormat format)
Returns the expected position of the fraction part for numbers to be formatted using the given format. This method should be invoked after createNumberFormat(javax.imageio.IIOImage, javax.imageio.ImageWriteParam), but the given format doesn't need to be the instance returned by the later.

Parameters:
format - The format to be used for formatting numbers.
Returns:
The expected position of the fraction part.

close

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

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


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