|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectImageWriter
SpatialImageWriter
ImageWriterAdapter
@Decorator(value=javax.imageio.ImageWriter.class) public abstract class ImageWriterAdapter
Base class for writers which delegate most of their work to an other ImageWriter.
This is used for reusing an existing image writer while adding some extra functionalities,
like encoding geographic information found in SpatialMetadata.
The wrapped image writer is called the main writer. The output given to that
writer is determined by the createOutput(String) method - it may or may not be the
same output than the one given to this ImageWriterAdapter setOutput(Object) method.
The amount of methods declared in this class is large, but the only new methods are:
createOutput(String)initialize()writeStreamMetadata(IIOMetadata)writeImageMetadata(IIOMetadata, int, ImageWriteParam)
All other methods override existing methods declared in parent classes, mostly
ImageWriter and SpatialImageWriter. The default implementation of
most methods delegate directly to the main writer.
Example
The World File format is composed of a classical image file (usually with the
".tiff", ".jpg" or ".png" extension) together with a small text file
containing geolocalization information (often with the ".tfw" extension) and an other
small text file containing projection information (".prj" extension). This
ImageWriterAdapter class can be used for wrapping a TIFF image writer, augmented with
the formatting of TFW and PRJ files. The information written in those files are fetched from
the SpatialMetadata object given to the ImageWriter.write(IIOImage) method in this class.
ImageReaderAdapter
| coverage/geotk-coverageio (download) | View source code for this class |
| Nested Class Summary | |
|---|---|
static class |
ImageWriterAdapter.Spi
Service provider interface (SPI) for ImageWriterAdapters. |
| Field Summary | |
|---|---|
protected ImageWriter |
main
The writer to use for writing the pixel values. |
| Fields inherited from class ImageWriter |
|---|
availableLocales, locale, originatingProvider, output, progressListeners, warningListeners, warningLocales |
| Fields inherited from interface WarningProducer |
|---|
LOGGER |
| Constructor Summary | |
|---|---|
protected |
ImageWriterAdapter(ImageWriterAdapter.Spi provider)
Constructs a new image writer. |
protected |
ImageWriterAdapter(ImageWriterAdapter.Spi provider,
ImageWriter main)
Constructs a new image writer wrapping the given writer. |
| Method Summary | |
|---|---|
void |
abort()
Requests that any current write operation be aborted. |
void |
addIIOWriteProgressListener(IIOWriteProgressListener listener)
Adds the given listener to the list of registered progress listeners. |
void |
addIIOWriteWarningListener(IIOWriteWarningListener listener)
Adds the given listener to the list of registered warning listeners. |
boolean |
canReplacePixels(int imageIndex)
Returns true if the writer allows pixels of the given image to be replaced
using the replacePixels methods. |
boolean |
canWriteRasters()
Returns true if the methods that take an IIOImage parameter are capable of dealing
with a Raster. |
boolean |
canWriteSequence()
Returns true if the writer is able to append an image to an image stream that
already contains header information and possibly prior images. |
protected void |
close()
Closes the output stream created by createOutput(String). |
protected Object |
createOutput(String writerID)
Creates the output to give to the main writer, or to an other writer identified by the writerID argument. |
void |
dispose()
Allows any resources held by this object to be released. |
void |
endReplacePixels()
Terminates a sequence of calls to replacePixels. |
void |
endWriteSequence()
Completes the writing of a sequence of images begun with prepareWriteSequence. |
protected void |
finalize()
Invokes the close() method when this writer is garbage-collected. |
Locale[] |
getAvailableLocales()
Returns the locales that may be used to localize warning listeners. |
SpatialMetadata |
getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param)
Returns a metadata object containing default values for encoding an image of the given type. |
SpatialMetadata |
getDefaultStreamMetadata(ImageWriteParam param)
Returns a metadata object containing default values for encoding a stream of images. |
SpatialImageWriteParam |
getDefaultWriteParam()
Returns a default parameter object appropriate for this format. |
Locale |
getLocale()
Returns the locale used to localize warning listeners. |
int |
getNumThumbnailsSupported(ImageTypeSpecifier imageType,
ImageWriteParam param,
IIOMetadata streamMetadata,
IIOMetadata imageMetadata)
Returns the number of thumbnails suported by the format being written, or -1 if unknown. |
Dimension[] |
getPreferredThumbnailSizes(ImageTypeSpecifier imageType,
ImageWriteParam param,
IIOMetadata streamMetadata,
IIOMetadata imageMetadata)
Returns the legal size ranges for thumbnail images as they will be encoded in the output file or stream. |
protected void |
initialize()
Invoked automatically when the main writer has been given a new output. |
void |
prepareReplacePixels(int imageIndex,
Rectangle region)
Prepares the writer to handle a series of calls to the replacePixels methods. |
void |
prepareWriteSequence(IIOMetadata streamMetadata)
Prepares a stream to accept a series of subsequent writeToSequence
calls. |
void |
removeAllIIOWriteProgressListeners()
Removes all currently registered progress listeners. |
void |
removeAllIIOWriteWarningListeners()
Removes all currently registered warning listeners. |
void |
removeIIOWriteProgressListener(IIOWriteProgressListener listener)
Removes the given listener from the list of registered progress listeners. |
void |
removeIIOWriteWarningListener(IIOWriteWarningListener listener)
Removes the given listener from the list of registered warning listeners. |
void |
replacePixels(Raster raster,
ImageWriteParam param)
Replaces a portion of an image already present in the output with a portion of the given raster. |
void |
replacePixels(RenderedImage image,
ImageWriteParam param)
Replaces a portion of an image already present in the output with a portion of the given image. |
void |
reset()
Restores the ImageWriter to its initial state. |
void |
setLocale(Locale locale)
Sets the locale used to localize warning listeners. |
void |
write(IIOMetadata streamMetadata,
IIOImage image,
ImageWriteParam param)
Appends a complete image stream containing a single image and associated stream and image metadata and thumbnails to the output. |
protected void |
writeImageMetadata(IIOMetadata metadata,
int imageIndex,
ImageWriteParam param)
Invoked by the write methods when image metadata needs to be written. |
protected void |
writeStreamMetadata(IIOMetadata metadata)
Invoked by the write methods when stream metadata needs to be written. |
void |
writeToSequence(IIOImage image,
ImageWriteParam param)
Appends a single image and possibly associated metadata to the output. |
| Methods inherited from class Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final ImageWriter main
| Constructor Detail |
|---|
protected ImageWriterAdapter(ImageWriterAdapter.Spi provider)
throws IOException
provider - The ImageWriterSpi that is constructing this object.
IOException - If an error occurred while creating the main writer.
protected ImageWriterAdapter(ImageWriterAdapter.Spi provider,
ImageWriter main)
provider - The ImageWriterSpi that is constructing this object, or null.main - The writer to use for writing the pixel values.| Method Detail |
|---|
protected Object createOutput(String writerID)
throws IllegalStateException,
IOException
writerID argument. The default ImageWriterAdapter implementation
invokes this method with a writerID argument value equals to "main" when
the main writer needs to be used for the first time. This may happen at any
time after the setOutput method has been invoked.
The only writerID argument value accepted by the default implementation is
"main"; any other argument value causes a null value to be returned.
However subclasses can override this method for supporting more writer types. The
table below summarizes a few types supported by this writer and different subclasses:
| Writer type | Defined by | Usage |
|---|---|---|
"main" |
ImageWriterAdapter |
The output to be given to the main writer. |
"tfw" |
WorldFileImageWriter |
The output for the World File. |
"prj" |
WorldFileImageWriter |
The output for the Map Projection file. |
The default implementation first checks if the main writer accepts directly
the output of this writer. If so, then that output is returned with
no change. Otherwise the output is wrapped in an ImageOutputStream, which is
returned. The output stream assigned to the main writer will be closed by
the close() method.
writerID - Identifier of the writer for which an output is needed.
null if this method can
not create such output.
IllegalStateException - if the output has not been set.
IOException - If an error occurred while creating the output for the writer.ImageReaderAdapter.createInput(String)
protected void initialize()
throws IOException
createOutput("main").
The default implementation does nothing. Subclasses can override this method for performing additional initialization.
IOException - If an error occurred while initializing the main writer.public SpatialImageWriteParam getDefaultWriteParam()
getDefaultWriteParam in class SpatialImageWriterImageWriteParam object which may be used.public SpatialMetadata getDefaultStreamMetadata(ImageWriteParam param)
Subclasses can override the writeStreamMetadata(IIOMetadata) method
for writing those metadata to the output.
getDefaultStreamMetadata in class SpatialImageWriterparam - Parameters that will be used to encode the image (in cases where
it may affect the structure of the metadata), or null.
null.
public SpatialMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param)
Subclasses can override the writeImageMetadata(IIOMetadata, int, ImageWriteParam)
method for writing those metadata to the output.
getDefaultImageMetadata in class SpatialImageWriterimageType - The format of the image to be written later.param - Parameters that will be used to encode the image (in cases where
it may affect the structure of the metadata), or null.
null.
protected void writeStreamMetadata(IIOMetadata metadata)
throws IOException
write methods when stream metadata needs to be written.
The metadata written by the main writer are not concerned by this method.
The default implementation does nothing. Subclasses can override this method for writing spatial metadata.
metadata - The stream metadata, or null if none.
IOException - If an error occurred while writing the metadata.MetadataHelper
protected void writeImageMetadata(IIOMetadata metadata,
int imageIndex,
ImageWriteParam param)
throws IOException
write methods when image metadata needs to be written.
The metadata written by the main writer are not concerned by this method.
The default implementation does nothing. Subclasses can override this method for writing spatial metadata.
metadata - The stream metadata, or null if none.imageIndex - The index of the image being written.param - The user-specified parameter, or null if none.
IOException - If an error occurred while writing the metadata.MetadataHelper
public void write(IIOMetadata streamMetadata,
IIOImage image,
ImageWriteParam param)
throws IOException
writeStreamMetadata(IIOMetadata) with the given
streamMetadata argument.writeImageMetadata(IIOMetadata, int, ImageWriteParam)
with the metadata obtained from the image argument.
write in class ImageWriterIOExceptionpublic boolean canWriteRasters()
IIOImage parameter are capable of dealing
with a Raster. The default implementation delegates to the main writer.
No output needs to be set for this method.
canWriteRasters in class SpatialImageWriterpublic boolean canWriteSequence()
true if the writer is able to append an image to an image stream that
already contains header information and possibly prior images. The default implementation
delegates to the main writer. No output needs to be set for this method.
canWriteSequence in class ImageWriter
public void prepareWriteSequence(IIOMetadata streamMetadata)
throws IOException
writeToSequence
calls. The default implementation performs the following steps:
writeStreamMetadata(IIOMetadata) with the given
streamMetadata argument.
prepareWriteSequence in class ImageWriterIOException
public void writeToSequence(IIOImage image,
ImageWriteParam param)
throws IOException
writeImageMetadata(IIOMetadata, int, ImageWriteParam)
with the metadata obtained from the image argument.
writeToSequence in class ImageWriterIOException
public void endWriteSequence()
throws IOException
prepareWriteSequence. The default implementation delegates to the main
writer.
endWriteSequence in class ImageWriterIOException
public boolean canReplacePixels(int imageIndex)
throws IOException
true if the writer allows pixels of the given image to be replaced
using the replacePixels methods. The default implementation ensures that the
main writer has been initialized, then
delegates to that writer.
canReplacePixels in class ImageWriterIOException
public void prepareReplacePixels(int imageIndex,
Rectangle region)
throws IOException
prepareReplacePixels in class ImageWriterIOException
public void replacePixels(RenderedImage image,
ImageWriteParam param)
throws IOException
replacePixels in class ImageWriterIOException
public void replacePixels(Raster raster,
ImageWriteParam param)
throws IOException
replacePixels in class ImageWriterIOException
public void endReplacePixels()
throws IOException
replacePixels. The default implementation
delegates to the main writer.
endReplacePixels in class ImageWriterIOException
public int getNumThumbnailsSupported(ImageTypeSpecifier imageType,
ImageWriteParam param,
IIOMetadata streamMetadata,
IIOMetadata imageMetadata)
getNumThumbnailsSupported in class ImageWriter
public Dimension[] getPreferredThumbnailSizes(ImageTypeSpecifier imageType,
ImageWriteParam param,
IIOMetadata streamMetadata,
IIOMetadata imageMetadata)
getPreferredThumbnailSizes in class ImageWriterpublic Locale[] getAvailableLocales()
getAvailableLocales in class ImageWriterpublic Locale getLocale()
getLocale in interface LocalizedgetLocale in class ImageWriterpublic void setLocale(Locale locale)
setLocale in class ImageWriterpublic void addIIOWriteWarningListener(IIOWriteWarningListener listener)
addIIOWriteWarningListener in class ImageWriterpublic void removeIIOWriteWarningListener(IIOWriteWarningListener listener)
removeIIOWriteWarningListener in class ImageWriterpublic void removeAllIIOWriteWarningListeners()
removeAllIIOWriteWarningListeners in class ImageWriterpublic void addIIOWriteProgressListener(IIOWriteProgressListener listener)
addIIOWriteProgressListener in class ImageWriterpublic void removeIIOWriteProgressListener(IIOWriteProgressListener listener)
removeIIOWriteProgressListener in class ImageWriterpublic void removeAllIIOWriteProgressListeners()
removeAllIIOWriteProgressListeners in class ImageWriterpublic void abort()
abort in class ImageWriterpublic void reset()
ImageWriter to its initial state. The default implementation
delegates to both the main writer and to the super-class method.
reset in class ImageWriterpublic void dispose()
dispose in interface Disposabledispose in class SpatialImageWriter
protected void close()
throws IOException
createOutput(String). This method does nothing
if the output used by the main writer is the one given by the user to the
setOutput method. Otherwise, if the output of the main writer
is an instance of ImageOutputStream or Closeable, then it is closed.
This method is invoked automatically by setOutput(...),
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. Overriding methods shall make sure that super.close()
is invoked even in case of failure.
IOException - if an error occurred while closing the stream.
protected void finalize()
throws Throwable
close() method when this writer is garbage-collected.
Note that this will actually close the stream only if it has been created
by this writer, rather than supplied by the user.
finalize in class ObjectThrowable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||