|
JSR-209 (Final Release) | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.imageio.ImageWriter
An abstract superclass for encoding and writing images.
ImageReader
,
ImageWriteParam
Field Summary | |
protected java.util.Locale[] |
availableLocales
An array of Locale s that may be used to localize
warning messages and compression setting values, or
null if localization is not supported. |
protected java.util.Locale |
locale
The current Locale to be used for localization, or
null if none has been set. |
protected java.lang.Object |
output
The ImageOutputStream or other Object
set by setOutput and retrieved by
getOutput . |
protected java.util.List |
progressListeners
A List of currently registered
IIOWriteProgressListener s, initialized by default
null , which is synonymous with an empty
List . |
protected java.util.List |
warningListeners
A List of currently registered
IIOWriteWarningListener s, initialized by default to
null , which is synonymous with an empty
List . |
protected java.util.List |
warningLocales
A List of Locale s, one for each
element of warningListeners , initialized by default
null , which is synonymous with an empty
List . |
Method Summary | |
void |
abort()
Requests that any current write operation be aborted. |
protected boolean |
abortRequested()
Returns true if a request to abort the current
write operation has been made since the writer was instantiated or
clearAbortRequest was called. |
void |
addIIOWriteProgressListener(IIOWriteProgressListener listener)
Adds an IIOWriteProgressListener to the list of
registered progress listeners. |
void |
addIIOWriteWarningListener(IIOWriteWarningListener listener)
Adds an IIOWriteWarningListener to the list of
registered warning listeners. |
boolean |
canInsertEmpty(int imageIndex)
Returns true if the writer supports the insertion
of a new, empty image at the given index. |
boolean |
canInsertImage(int imageIndex)
Returns true if the writer supports the insertion
of a new image at the given index. |
boolean |
canRemoveImage(int imageIndex)
Returns true if the writer supports the removal
of an existing image at the given index. |
boolean |
canReplacePixels(int imageIndex)
Returns true if the writer allows pixels of the
given image to be replaced using the replacePixels
methods. |
protected void |
clearAbortRequest()
Clears any previous abort request. |
void |
dispose()
Allows any resources held by this object to be released. |
void |
endReplacePixels()
Terminates a sequence of calls to replacePixels . |
java.util.Locale[] |
getAvailableLocales()
Returns an array of Locale s that may be used to
localize warning listeners and compression settings. |
ImageWriteParam |
getDefaultWriteParam()
Returns a new ImageWriteParam object of the
appropriate type for this file format containing default
values, that is, those values that would be used
if no ImageWriteParam object were specified. |
java.util.Locale |
getLocale()
Returns the currently set Locale , or
null if none has been set. |
java.lang.Object |
getOutput()
Returns the ImageOutputStream or other
Object set by the most recent call to the
setOutput method. |
void |
prepareReplacePixels(int imageIndex,
Rectangle region)
Prepares the writer to handle a series of calls to the replacePixels methods. |
protected void |
processImageComplete()
Broadcasts the completion of an image write to all registered IIOWriteProgressListener s by calling their
imageComplete method. |
protected void |
processImageProgress(float percentageDone)
Broadcasts the current percentage of image completion to all registered IIOWriteProgressListener s by calling
their imageProgress method. |
protected void |
processImageStarted(int imageIndex)
Broadcasts the start of an image write to all registered IIOWriteProgressListener s by calling their
imageStarted method. |
protected void |
processWarningOccurred(int imageIndex,
java.lang.String warning)
Broadcasts a warning message to all registered IIOWriteWarningListener s by calling their
warningOccurred method. |
protected void |
processWarningOccurred(int imageIndex,
java.lang.String baseName,
java.lang.String keyword)
Broadcasts a localized warning message to all registered IIOWriteWarningListener s by calling their
warningOccurred method with a string taken
from a ResourceBundle . |
protected void |
processWriteAborted()
Broadcasts that the write has been aborted to all registered IIOWriteProgressListener s by calling their
writeAborted method. |
void |
removeAllIIOWriteProgressListeners()
Removes all currently registered IIOWriteProgressListener objects. |
void |
removeAllIIOWriteWarningListeners()
Removes all currently registered IIOWriteWarningListener objects. |
void |
removeIIOWriteProgressListener(IIOWriteProgressListener listener)
Removes an IIOWriteProgressListener from the list
of registered progress listeners. |
void |
removeIIOWriteWarningListener(IIOWriteWarningListener listener)
Removes an IIOWriteWarningListener from the list
of registered warning listeners. |
void |
removeImage(int imageIndex)
Removes an image from the stream. |
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(java.util.Locale locale)
Sets the current Locale of this
ImageWriter to the given value. |
void |
setOutput(java.lang.Object output)
Sets the destination to the given ImageOutputStream or other Object . |
abstract void |
write(IIOMetadata streamMetadata,
IIOImage image,
ImageWriteParam param)
Appends a complete image stream containing a single image and associated stream to the output. |
void |
write(RenderedImage image)
Appends a complete image stream consisting of a single image to the output. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.Object output
ImageOutputStream
or other Object
set by setOutput
and retrieved by
getOutput
. By default it is initialized to
null
.
protected java.util.Locale[] availableLocales
Locale
s that may be used to localize
warning messages and compression setting values, or
null
if localization is not supported. By default
it is initialized to null
.
protected java.util.Locale locale
Locale
to be used for localization, or
null
if none has been set. By default it is
initialized to null
.
protected java.util.List warningListeners
List
of currently registered
IIOWriteWarningListener
s, initialized by default to
null
, which is synonymous with an empty
List
.
protected java.util.List warningLocales
List
of Locale
s, one for each
element of warningListeners
, initialized by default
null
, which is synonymous with an empty
List
.
protected java.util.List progressListeners
List
of currently registered
IIOWriteProgressListener
s, initialized by default
null
, which is synonymous with an empty
List
.
Method Detail |
public void setOutput(java.lang.Object output)
ImageOutputStream
or other Object
.
The destination is assumed to be ready to accept data, and will
not be closed at the end of each write. This allows distributed
imaging applications to transmit a series of images over a
single network connection. If output
is
null
, any currently set output will be removed.
If output
is an
ImageOutputStream
, calls to the
write
, writeToSequence
, and
prepareWriteEmpty
/endWriteEmpty
methods will preserve the existing contents of the stream.
Other write methods, such as writeInsert
,
replacePixels
,
prepareInsertEmpty
/endInsertEmpty
,
and endWriteSequence
, require the full contents
of the stream to be readable and writable, and may alter any
portion of the stream.
Use of a general Object
other than an
ImageOutputStream
is intended for writers that
interact directly with an output device or imaging protocol.
Most writers will return a single-element array containing only
ImageOutputStream.class
to indicate that they
accept only an ImageOutputStream
.
output
- the ImageOutputStream
or other
Object
to use for future writing.getOutput()
public java.lang.Object getOutput()
ImageOutputStream
or other
Object
set by the most recent call to the
setOutput
method. If no destination has been
set, null
is returned.
The default implementation returns the value of the
output
instance variable.
Object
that was specified using
setOutput
, or null
.setOutput(java.lang.Object)
public java.util.Locale[] getAvailableLocales()
Locale
s that may be used to
localize warning listeners and compression settings. A return
value of null
indicates that localization is not
supported.
The default implementation returns a clone of the
availableLocales
instance variable if it is
non-null
, or else returns null
.
Locale
s that may be used as
arguments to setLocale
, or null
.public void setLocale(java.util.Locale locale)
Locale
of this
ImageWriter
to the given value. A value of
null
removes any previous setting, and indicates
that the writer should localize as it sees fit.
The default implementation checks locale
against the values returned by
getAvailableLocales
, and sets the
locale
instance variable if it is found. If
locale
is null
, the instance variable
is set to null
without any checking.
locale
- the desired Locale
, or
null
.
java.lang.IllegalArgumentException
- if locale
is
non-null
but is not one of the values returned by
getAvailableLocales
.getLocale()
public java.util.Locale getLocale()
Locale
, or
null
if none has been set.
The default implementation returns the value of the
locale
instance variable.
Locale
, or null
.setLocale(java.util.Locale)
public ImageWriteParam getDefaultWriteParam()
ImageWriteParam
object of the
appropriate type for this file format containing default
values, that is, those values that would be used
if no ImageWriteParam
object were specified. This
is useful as a starting point for tweaking just a few parameters
and otherwise leaving the default settings alone.
The default implementation constructs and returns a new
ImageWriteParam
object that does not allow
progressive encoding, or compression, and that will be
localized for the current Locale
(i.e.,
what you would get by calling new
ImageWriteParam(getLocale())
.
ImageWriteParam
object containing
default values.public abstract void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws java.io.IOException
ImageOutputStream
,
its existing contents prior to the current seek position are not
affected, and need not be readable or writable.
The output must have been set beforehand using the
setOutput
method.
streamMetadata must be null
, any value
other than null
, will throw an
IllegalArgumentException
.
An ImageWriteParam
may
optionally be supplied to control the writing process. If
param
is null
, a default write param
will be used.
If the supplied ImageWriteParam
contains
optional setting values not supported by this writer, they
will be ignored.
streamMetadata
- must be null
. Any value
other than null
will throw an
IllegalArgumentException
.image
- an IIOImage
objectparam
- an ImageWriteParam
, or
null
to use a default
ImageWriteParam
.
java.lang.IllegalStateException
- if the output has not
been set.
java.lang.IllegalArgumentException
- if IIOmetadata
is not null
java.io.IOException
- if an error occurs during writing.public void write(RenderedImage image) throws java.io.IOException
write(null, new IIOImage(image, null, null), null)
.
image
- a RenderedImage
to be written.
java.lang.IllegalStateException
- if the output has not
been set.
java.lang.IllegalArgumentException
- if image
is
null
or not a BufferedImage.
See restriction on RenderedImage
.
java.io.IOException
- if an error occurs during writing.
public boolean canInsertImage(int imageIndex) throws java.io.IOException
true
if the writer supports the insertion
of a new image at the given index. Existing images with
indices greater than or equal to the insertion index will have
their indices increased by 1. A value for
imageIndex
of -1
may be used to
signify an index one larger than the current largest index.
A writer that does not support any image insertion may
return false
without performing bounds checking on
the index.
The default implementation throws an
IllegalStateException
if the output is
null
, and otherwise returns false
withour checking the value of imageIndex
.
imageIndex
- the index at which the image is to be
inserted.
true
if an image may be inserted at the
given index.
java.lang.IllegalStateException
- if the output has not
been set.
java.lang.IndexOutOfBoundsException
- if the writer supports
image insertion in general, but imageIndex
is less
than -1 or greater than the largest available index.
java.io.IOException
- if an I/O error occurs during the query.public boolean canRemoveImage(int imageIndex) throws java.io.IOException
true
if the writer supports the removal
of an existing image at the given index. Existing images with
indices greater than the insertion index will have
their indices decreased by 1.
A writer that does not support any image removal may
return false
without performing bounds checking on
the index.
The default implementation throws an
IllegalStateException
if the output is
null
, and otherwise returns false
without checking the value of imageIndex
.
imageIndex
- the index of the image to be removed.
true
if it is possible to remove the given
image.
java.lang.IllegalStateException
- if the output has not
been set.
java.lang.IndexOutOfBoundsException
- if the writer supports
image removal in general, but imageIndex
is less
than 0 or greater than the largest available index.
java.io.IOException
- if an I/O error occurs during the
query.public void removeImage(int imageIndex) throws java.io.IOException
If canRemoveImage(imageIndex)
returns false,
an UnsupportedOperationException
will be thrown.
The removal may or may not cause a reduction in the actual file size.
The default implementation throws an
IllegalStateException
if the output is
null
, and otherwise throws an
UnsupportedOperationException
.
imageIndex
- the index of the image to be removed.
java.lang.IllegalStateException
- if the output has not
been set.
java.lang.UnsupportedOperationException
- if
canRemoveImage(imageIndex)
returns false
.
java.lang.IndexOutOfBoundsException
- if imageIndex
is less than 0 or greater than the largest available index.
java.io.IOException
- if an I/O error occurs during the
removal.public boolean canInsertEmpty(int imageIndex) throws java.io.IOException
true
if the writer supports the insertion
of a new, empty image at the given index. The pixel values of
the image are undefined, and may be specified in pieces using
the replacePixels
methods. Existing images with
indices greater than or equal to the insertion index will have
their indices increased by 1. A value for
imageIndex
of -1
may be used to
signify an index one larger than the current largest index.
A writer that does not support insertion of empty images
may return false
without performing bounds
checking on the index.
The default implementation throws an
IllegalStateException
if the output is
null
, and otherwise returns false
without checking the value of imageIndex
.
imageIndex
- the index at which the image is to be
inserted.
true
if an empty image may be inserted at
the given index.
java.lang.IllegalStateException
- if the output has not been
set.
java.lang.IndexOutOfBoundsException
- if the writer supports
empty image insertion in general, but imageIndex
is less than -1 or greater than the largest available index.
java.io.IOException
- if an I/O error occurs during the
query.public boolean canReplacePixels(int imageIndex) throws java.io.IOException
true
if the writer allows pixels of the
given image to be replaced using the replacePixels
methods.
A writer that does not support any pixel replacement may
return false
without performing bounds checking on
the index.
The default implementation throws an
IllegalStateException
if the output is
null
, and otherwise returns false
without checking the value of imageIndex
.
imageIndex
- the index of the image whose pixels are to be
replaced.
true
if the pixels of the given
image can be replaced.
java.lang.IllegalStateException
- if the output has not been
set.
java.lang.IndexOutOfBoundsException
- if the writer supports
pixel replacement in general, but imageIndex
is
less than 0 or greater than the largest available index.
java.io.IOException
- if an I/O error occurs during the query.public void prepareReplacePixels(int imageIndex, Rectangle region) throws java.io.IOException
replacePixels
methods. The affected pixel area
will be clipped against the supplied
If canReplacePixels
returns
false
, and
UnsupportedOperationException
will be thrown.
The default implementation throws an
IllegalStateException
if the output is
null
, and otherwise throws an
UnsupportedOperationException
.
imageIndex
- the index of the image whose pixels are to be
replaced.region
- a Rectangle
that will be used to clip
future pixel regions.
java.lang.IllegalStateException
- if the output has not
been set.
java.lang.UnsupportedOperationException
- if
canReplacePixels(imageIndex)
returns
false
.
java.lang.IndexOutOfBoundsException
- if imageIndex
is less than 0 or greater than the largest available index.
java.lang.IllegalStateException
- if there is a previous call to
prepareReplacePixels
without a matching call to
endReplacePixels
(i.e., nesting is not
allowed).
java.lang.IllegalArgumentException
- if region
is
null
or has a width or height less than 1.
java.io.IOException
- if an I/O error occurs during the
preparation.public void replacePixels(RenderedImage image, ImageWriteParam param) throws java.io.IOException
The destination region is specified in the
param
argument, and will be clipped to the image
boundaries and the region supplied to
prepareReplacePixels
. At least one pixel of the
source must not be clipped, or an exception is thrown.
An ImageWriteParam
may optionally be supplied
to control the writing process. If param
is
null
, a default write param will be used.
If the supplied ImageWriteParam
contains
optional setting values not supported by this writer, they
will be ignored.
This method may only be called after a call to
prepareReplacePixels
, or else an
IllegalStateException
will be thrown.
The default implementation throws an
IllegalStateException
if the output is
null
, and otherwise throws an
UnsupportedOperationException
.
image
- a RenderedImage
containing source
pixels.param
- an ImageWriteParam
, or
null
to use a default
ImageWriteParam
.
java.lang.IllegalStateException
- if the output has not
been set.
java.lang.UnsupportedOperationException
- if
canReplacePixels(imageIndex)
returns
false
.
java.lang.IllegalStateException
- if there is no previous call to
prepareReplacePixels
without a matching call to
endReplacePixels
.
java.lang.IllegalArgumentException
- if any of the following are true:
image
is null
or not a
BufferedImage
. See restriction on RenderedImage
.
param
is null
.
image
does not match, or this
writer cannot convert it to, the existing image layout.
java.io.IOException
- if an I/O error occurs during writing.public void endReplacePixels() throws java.io.IOException
replacePixels
.
If canReplacePixels
returns
false
, and
UnsupportedOperationException
will be thrown.
The default implementation throws an
IllegalStateException
if the output is
null
, and otherwise throws an
UnsupportedOperationException
.
java.lang.IllegalStateException
- if the output has not
been set.
java.lang.UnsupportedOperationException
- if
canReplacePixels(imageIndex)
returns
false
.
java.lang.IllegalStateException
- if there is no previous call
to prepareReplacePixels
without a matching call to
endReplacePixels
.
java.io.IOException
- if an I/O error occurs during writing.public void abort()
Writers should call clearAbortRequest
at the
beginning of each write operation, and poll the value of
abortRequested
regularly during the write.
protected boolean abortRequested()
true
if a request to abort the current
write operation has been made since the writer was instantiated or
clearAbortRequest
was called.
true
if the current write operation should
be aborted.abort()
,
clearAbortRequest()
protected void clearAbortRequest()
abortRequested
will return
false
.
abort()
,
abortRequested()
public void addIIOWriteWarningListener(IIOWriteWarningListener listener)
IIOWriteWarningListener
to the list of
registered warning listeners. If listener
is
null
, no exception will be thrown and no action
will be taken. Messages sent to the given listener will be
localized, if possible, to match the current
Locale
. If no Locale
has been set,
warning messages may be localized as the writer sees fit.
listener
- an IIOWriteWarningListener
to be
registered.removeIIOWriteWarningListener(javax.imageio.event.IIOWriteWarningListener)
public void removeIIOWriteWarningListener(IIOWriteWarningListener listener)
IIOWriteWarningListener
from the list
of registered warning listeners. If the listener was not
previously registered, or if listener
is
null
, no exception will be thrown and no action
will be taken.
listener
- an IIOWriteWarningListener
to be
deregistered.addIIOWriteWarningListener(javax.imageio.event.IIOWriteWarningListener)
public void removeAllIIOWriteWarningListeners()
IIOWriteWarningListener
objects.
The default implementation sets the
warningListeners
and warningLocales
instance variables to null
.
public void addIIOWriteProgressListener(IIOWriteProgressListener listener)
IIOWriteProgressListener
to the list of
registered progress listeners. If listener
is
null
, no exception will be thrown and no action
will be taken.
listener
- an IIOWriteProgressListener
to be
registered.removeIIOWriteProgressListener(javax.imageio.event.IIOWriteProgressListener)
public void removeIIOWriteProgressListener(IIOWriteProgressListener listener)
IIOWriteProgressListener
from the list
of registered progress listeners. If the listener was not
previously registered, or if listener
is
null
, no exception will be thrown and no action
will be taken.
listener
- an IIOWriteProgressListener
to be
deregistered.addIIOWriteProgressListener(javax.imageio.event.IIOWriteProgressListener)
public void removeAllIIOWriteProgressListeners()
IIOWriteProgressListener
objects.
The default implementation sets the
progressListeners
instance variable to
null
.
protected void processImageStarted(int imageIndex)
IIOWriteProgressListener
s by calling their
imageStarted
method. Subclasses may use this
method as a convenience.
imageIndex
- the index of the image about to be written.protected void processImageProgress(float percentageDone)
IIOWriteProgressListener
s by calling
their imageProgress
method. Subclasses may use
this method as a convenience.
percentageDone
- the current percentage of completion,
as a float
.protected void processImageComplete()
IIOWriteProgressListener
s by calling their
imageComplete
method. Subclasses may use this
method as a convenience.
protected void processWriteAborted()
IIOWriteProgressListener
s by calling their
writeAborted
method. Subclasses may use this
method as a convenience.
protected void processWarningOccurred(int imageIndex, java.lang.String warning)
IIOWriteWarningListener
s by calling their
warningOccurred
method. Subclasses may use this
method as a convenience.
imageIndex
- the index of the image on which the warning
occurred.warning
- the warning message.protected void processWarningOccurred(int imageIndex, java.lang.String baseName, java.lang.String keyword)
IIOWriteWarningListener
s by calling their
warningOccurred
method with a string taken
from a ResourceBundle
. Subclasses may use this
method as a convenience.
imageIndex
- the index of the image on which the warning
occurred.baseName
- the base name of a set of
ResourceBundle
s containing localized warning
messages.keyword
- the keyword used to index the warning message
within the set of ResourceBundle
s.public void reset()
ImageWriter
to its initial state.
The default implementation calls
setOutput(null)
, setLocale(null)
,
removeAllIIOWriteWarningListeners()
,
removeAllIIOWriteProgressListeners()
, and
clearAbortRequest
.
public void dispose()
finalize
) subsequent to a call to this method
is undefined.
It is important for applications to call this method when they
know they will no longer be using this ImageWriter
.
Otherwise, the writer may continue to hold on to resources
indefinitely.
The default implementation of this method in the superclass does nothing. Subclass implementations should ensure that all resources, especially native resources, are released.
|
JSR-209 (Final Release) | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |