Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/imageio/ImageWriter.java
38829 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.imageio;2627import java.awt.Dimension;28import java.awt.Rectangle;29import java.awt.image.BufferedImage;30import java.awt.image.RenderedImage;31import java.awt.image.Raster;32import java.io.IOException;33import java.util.ArrayList;34import java.util.List;35import java.util.Locale;36import java.util.MissingResourceException;37import java.util.ResourceBundle;38import javax.imageio.event.IIOWriteWarningListener;39import javax.imageio.event.IIOWriteProgressListener;40import javax.imageio.metadata.IIOMetadata;41import javax.imageio.stream.ImageOutputStream;42import javax.imageio.spi.ImageWriterSpi;4344/**45* An abstract superclass for encoding and writing images. This class46* must be subclassed by classes that write out images in the context47* of the Java Image I/O framework.48*49* <p> <code>ImageWriter</code> objects are normally instantiated by50* the service provider class for the specific format. Service51* provider classes are registered with the <code>IIORegistry</code>,52* which uses them for format recognition and presentation of53* available format readers and writers.54*55* <p>56*57* @see ImageReader58* @see ImageWriteParam59* @see javax.imageio.spi.IIORegistry60* @see javax.imageio.spi.ImageWriterSpi61*62*/63public abstract class ImageWriter implements ImageTranscoder {6465/**66* The <code>ImageWriterSpi</code> that instantiated this object,67* or <code>null</code> if its identity is not known or none68* exists. By default it is initialized to <code>null</code>.69*/70protected ImageWriterSpi originatingProvider = null;7172/**73* The <code>ImageOutputStream</code> or other <code>Object</code>74* set by <code>setOutput</code> and retrieved by75* <code>getOutput</code>. By default it is initialized to76* <code>null</code>.77*/78protected Object output = null;7980/**81* An array of <code>Locale</code>s that may be used to localize82* warning messages and compression setting values, or83* <code>null</code> if localization is not supported. By default84* it is initialized to <code>null</code>.85*/86protected Locale[] availableLocales = null;8788/**89* The current <code>Locale</code> to be used for localization, or90* <code>null</code> if none has been set. By default it is91* initialized to <code>null</code>.92*/93protected Locale locale = null;9495/**96* A <code>List</code> of currently registered97* <code>IIOWriteWarningListener</code>s, initialized by default to98* <code>null</code>, which is synonymous with an empty99* <code>List</code>.100*/101protected List<IIOWriteWarningListener> warningListeners = null;102103/**104* A <code>List</code> of <code>Locale</code>s, one for each105* element of <code>warningListeners</code>, initialized by default106* <code>null</code>, which is synonymous with an empty107* <code>List</code>.108*/109protected List<Locale> warningLocales = null;110111/**112* A <code>List</code> of currently registered113* <code>IIOWriteProgressListener</code>s, initialized by default114* <code>null</code>, which is synonymous with an empty115* <code>List</code>.116*/117protected List<IIOWriteProgressListener> progressListeners = null;118119/**120* If <code>true</code>, the current write operation should be121* aborted.122*/123private boolean abortFlag = false;124125/**126* Constructs an <code>ImageWriter</code> and sets its127* <code>originatingProvider</code> instance variable to the128* supplied value.129*130* <p> Subclasses that make use of extensions should provide a131* constructor with signature <code>(ImageWriterSpi,132* Object)</code> in order to retrieve the extension object. If133* the extension object is unsuitable, an134* <code>IllegalArgumentException</code> should be thrown.135*136* @param originatingProvider the <code>ImageWriterSpi</code> that137* is constructing this object, or <code>null</code>.138*/139protected ImageWriter(ImageWriterSpi originatingProvider) {140this.originatingProvider = originatingProvider;141}142143/**144* Returns the <code>ImageWriterSpi</code> object that created145* this <code>ImageWriter</code>, or <code>null</code> if this146* object was not created through the <code>IIORegistry</code>.147*148* <p> The default implementation returns the value of the149* <code>originatingProvider</code> instance variable.150*151* @return an <code>ImageWriterSpi</code>, or <code>null</code>.152*153* @see ImageWriterSpi154*/155public ImageWriterSpi getOriginatingProvider() {156return originatingProvider;157}158159/**160* Sets the destination to the given161* <code>ImageOutputStream</code> or other <code>Object</code>.162* The destination is assumed to be ready to accept data, and will163* not be closed at the end of each write. This allows distributed164* imaging applications to transmit a series of images over a165* single network connection. If <code>output</code> is166* <code>null</code>, any currently set output will be removed.167*168* <p> If <code>output</code> is an169* <code>ImageOutputStream</code>, calls to the170* <code>write</code>, <code>writeToSequence</code>, and171* <code>prepareWriteEmpty</code>/<code>endWriteEmpty</code>172* methods will preserve the existing contents of the stream.173* Other write methods, such as <code>writeInsert</code>,174* <code>replaceStreamMetadata</code>,175* <code>replaceImageMetadata</code>, <code>replacePixels</code>,176* <code>prepareInsertEmpty</code>/<code>endInsertEmpty</code>,177* and <code>endWriteSequence</code>, require the full contents178* of the stream to be readable and writable, and may alter any179* portion of the stream.180*181* <p> Use of a general <code>Object</code> other than an182* <code>ImageOutputStream</code> is intended for writers that183* interact directly with an output device or imaging protocol.184* The set of legal classes is advertised by the writer's service185* provider's <code>getOutputTypes</code> method; most writers186* will return a single-element array containing only187* <code>ImageOutputStream.class</code> to indicate that they188* accept only an <code>ImageOutputStream</code>.189*190* <p> The default implementation sets the <code>output</code>191* instance variable to the value of <code>output</code> after192* checking <code>output</code> against the set of classes193* advertised by the originating provider, if there is one.194*195* @param output the <code>ImageOutputStream</code> or other196* <code>Object</code> to use for future writing.197*198* @exception IllegalArgumentException if <code>output</code> is199* not an instance of one of the classes returned by the200* originating service provider's <code>getOutputTypes</code>201* method.202*203* @see #getOutput204*/205public void setOutput(Object output) {206if (output != null) {207ImageWriterSpi provider = getOriginatingProvider();208if (provider != null) {209Class[] classes = provider.getOutputTypes();210boolean found = false;211for (int i = 0; i < classes.length; i++) {212if (classes[i].isInstance(output)) {213found = true;214break;215}216}217if (!found) {218throw new IllegalArgumentException("Illegal output type!");219}220}221}222223this.output = output;224}225226/**227* Returns the <code>ImageOutputStream</code> or other228* <code>Object</code> set by the most recent call to the229* <code>setOutput</code> method. If no destination has been230* set, <code>null</code> is returned.231*232* <p> The default implementation returns the value of the233* <code>output</code> instance variable.234*235* @return the <code>Object</code> that was specified using236* <code>setOutput</code>, or <code>null</code>.237*238* @see #setOutput239*/240public Object getOutput() {241return output;242}243244// Localization245246/**247* Returns an array of <code>Locale</code>s that may be used to248* localize warning listeners and compression settings. A return249* value of <code>null</code> indicates that localization is not250* supported.251*252* <p> The default implementation returns a clone of the253* <code>availableLocales</code> instance variable if it is254* non-<code>null</code>, or else returns <code>null</code>.255*256* @return an array of <code>Locale</code>s that may be used as257* arguments to <code>setLocale</code>, or <code>null</code>.258*/259public Locale[] getAvailableLocales() {260return (availableLocales == null) ?261null : (Locale[])availableLocales.clone();262}263264/**265* Sets the current <code>Locale</code> of this266* <code>ImageWriter</code> to the given value. A value of267* <code>null</code> removes any previous setting, and indicates268* that the writer should localize as it sees fit.269*270* <p> The default implementation checks <code>locale</code>271* against the values returned by272* <code>getAvailableLocales</code>, and sets the273* <code>locale</code> instance variable if it is found. If274* <code>locale</code> is <code>null</code>, the instance variable275* is set to <code>null</code> without any checking.276*277* @param locale the desired <code>Locale</code>, or278* <code>null</code>.279*280* @exception IllegalArgumentException if <code>locale</code> is281* non-<code>null</code> but is not one of the values returned by282* <code>getAvailableLocales</code>.283*284* @see #getLocale285*/286public void setLocale(Locale locale) {287if (locale != null) {288Locale[] locales = getAvailableLocales();289boolean found = false;290if (locales != null) {291for (int i = 0; i < locales.length; i++) {292if (locale.equals(locales[i])) {293found = true;294break;295}296}297}298if (!found) {299throw new IllegalArgumentException("Invalid locale!");300}301}302this.locale = locale;303}304305/**306* Returns the currently set <code>Locale</code>, or307* <code>null</code> if none has been set.308*309* <p> The default implementation returns the value of the310* <code>locale</code> instance variable.311*312* @return the current <code>Locale</code>, or <code>null</code>.313*314* @see #setLocale315*/316public Locale getLocale() {317return locale;318}319320// Write params321322/**323* Returns a new <code>ImageWriteParam</code> object of the324* appropriate type for this file format containing default325* values, that is, those values that would be used326* if no <code>ImageWriteParam</code> object were specified. This327* is useful as a starting point for tweaking just a few parameters328* and otherwise leaving the default settings alone.329*330* <p> The default implementation constructs and returns a new331* <code>ImageWriteParam</code> object that does not allow tiling,332* progressive encoding, or compression, and that will be333* localized for the current <code>Locale</code> (<i>i.e.</i>,334* what you would get by calling <code>new335* ImageWriteParam(getLocale())</code>.336*337* <p> Individual plug-ins may return an instance of338* <code>ImageWriteParam</code> with additional optional features339* enabled, or they may return an instance of a plug-in specific340* subclass of <code>ImageWriteParam</code>.341*342* @return a new <code>ImageWriteParam</code> object containing343* default values.344*/345public ImageWriteParam getDefaultWriteParam() {346return new ImageWriteParam(getLocale());347}348349// Metadata350351/**352* Returns an <code>IIOMetadata</code> object containing default353* values for encoding a stream of images. The contents of the354* object may be manipulated using either the XML tree structure355* returned by the <code>IIOMetadata.getAsTree</code> method, an356* <code>IIOMetadataController</code> object, or via plug-in357* specific interfaces, and the resulting data supplied to one of358* the <code>write</code> methods that take a stream metadata359* parameter.360*361* <p> An optional <code>ImageWriteParam</code> may be supplied362* for cases where it may affect the structure of the stream363* metadata.364*365* <p> If the supplied <code>ImageWriteParam</code> contains366* optional setting values not supported by this writer (<i>e.g.</i>367* progressive encoding or any format-specific settings), they368* will be ignored.369*370* <p> Writers that do not make use of stream metadata371* (<i>e.g.</i>, writers for single-image formats) should return372* <code>null</code>.373*374* @param param an <code>ImageWriteParam</code> that will be used to375* encode the image, or <code>null</code>.376*377* @return an <code>IIOMetadata</code> object.378*/379public abstract IIOMetadata380getDefaultStreamMetadata(ImageWriteParam param);381382/**383* Returns an <code>IIOMetadata</code> object containing default384* values for encoding an image of the given type. The contents385* of the object may be manipulated using either the XML tree386* structure returned by the <code>IIOMetadata.getAsTree</code>387* method, an <code>IIOMetadataController</code> object, or via388* plug-in specific interfaces, and the resulting data supplied to389* one of the <code>write</code> methods that take a stream390* metadata parameter.391*392* <p> An optional <code>ImageWriteParam</code> may be supplied393* for cases where it may affect the structure of the image394* metadata.395*396* <p> If the supplied <code>ImageWriteParam</code> contains397* optional setting values not supported by this writer (<i>e.g.</i>398* progressive encoding or any format-specific settings), they399* will be ignored.400*401* @param imageType an <code>ImageTypeSpecifier</code> indicating the402* format of the image to be written later.403* @param param an <code>ImageWriteParam</code> that will be used to404* encode the image, or <code>null</code>.405*406* @return an <code>IIOMetadata</code> object.407*/408public abstract IIOMetadata409getDefaultImageMetadata(ImageTypeSpecifier imageType,410ImageWriteParam param);411412// comment inherited413public abstract IIOMetadata convertStreamMetadata(IIOMetadata inData,414ImageWriteParam param);415416// comment inherited417public abstract IIOMetadata418convertImageMetadata(IIOMetadata inData,419ImageTypeSpecifier imageType,420ImageWriteParam param);421422// Thumbnails423424/**425* Returns the number of thumbnails supported by the format being426* written, given the image type and any additional write427* parameters and metadata objects that will be used during428* encoding. A return value of <code>-1</code> indicates that429* insufficient information is available.430*431* <p> An <code>ImageWriteParam</code> may optionally be supplied432* for cases where it may affect thumbnail handling.433*434* <p> If the supplied <code>ImageWriteParam</code> contains435* optional setting values not supported by this writer (<i>e.g.</i>436* progressive encoding or any format-specific settings), they437* will be ignored.438*439* <p> The default implementation returns 0.440*441* @param imageType an <code>ImageTypeSpecifier</code> indicating442* the type of image to be written, or <code>null</code>.443* @param param the <code>ImageWriteParam</code> that will be used for444* writing, or <code>null</code>.445* @param streamMetadata an <code>IIOMetadata</code> object that will446* be used for writing, or <code>null</code>.447* @param imageMetadata an <code>IIOMetadata</code> object that will448* be used for writing, or <code>null</code>.449*450* @return the number of thumbnails that may be written given the451* supplied parameters, or <code>-1</code> if insufficient452* information is available.453*/454public int getNumThumbnailsSupported(ImageTypeSpecifier imageType,455ImageWriteParam param,456IIOMetadata streamMetadata,457IIOMetadata imageMetadata) {458return 0;459}460461/**462* Returns an array of <code>Dimension</code>s indicating the463* legal size ranges for thumbnail images as they will be encoded464* in the output file or stream. This information is merely465* advisory; the writer will resize any supplied thumbnails as466* necessary.467*468* <p> The information is returned as a set of pairs; the first469* element of a pair contains an (inclusive) minimum width and470* height, and the second element contains an (inclusive) maximum471* width and height. Together, each pair defines a valid range of472* sizes. To specify a fixed size, the same width and height will473* appear for both elements. A return value of <code>null</code>474* indicates that the size is arbitrary or unknown.475*476* <p> An <code>ImageWriteParam</code> may optionally be supplied477* for cases where it may affect thumbnail handling.478*479* <p> If the supplied <code>ImageWriteParam</code> contains480* optional setting values not supported by this writer (<i>e.g.</i>481* progressive encoding or any format-specific settings), they482* will be ignored.483*484* <p> The default implementation returns <code>null</code>.485*486* @param imageType an <code>ImageTypeSpecifier</code> indicating the487* type of image to be written, or <code>null</code>.488* @param param the <code>ImageWriteParam</code> that will be used for489* writing, or <code>null</code>.490* @param streamMetadata an <code>IIOMetadata</code> object that will491* be used for writing, or <code>null</code>.492* @param imageMetadata an <code>IIOMetadata</code> object that will493* be used for writing, or <code>null</code>.494*495* @return an array of <code>Dimension</code>s with an even length496* of at least two, or <code>null</code>.497*/498public Dimension[] getPreferredThumbnailSizes(ImageTypeSpecifier imageType,499ImageWriteParam param,500IIOMetadata streamMetadata,501IIOMetadata imageMetadata) {502return null;503}504505/**506* Returns <code>true</code> if the methods that take an507* <code>IIOImage</code> parameter are capable of dealing with a508* <code>Raster</code> (as opposed to <code>RenderedImage</code>)509* source image. If this method returns <code>false</code>, then510* those methods will throw an511* <code>UnsupportedOperationException</code> if supplied with an512* <code>IIOImage</code> containing a <code>Raster</code>.513*514* <p> The default implementation returns <code>false</code>.515*516* @return <code>true</code> if <code>Raster</code> sources are517* supported.518*/519public boolean canWriteRasters() {520return false;521}522523/**524* Appends a complete image stream containing a single image and525* associated stream and image metadata and thumbnails to the526* output. Any necessary header information is included. If the527* output is an <code>ImageOutputStream</code>, its existing528* contents prior to the current seek position are not affected,529* and need not be readable or writable.530*531* <p> The output must have been set beforehand using the532* <code>setOutput</code> method.533*534* <p> Stream metadata may optionally be supplied; if it is535* <code>null</code>, default stream metadata will be used.536*537* <p> If <code>canWriteRasters</code> returns <code>true</code>,538* the <code>IIOImage</code> may contain a <code>Raster</code>539* source. Otherwise, it must contain a540* <code>RenderedImage</code> source.541*542* <p> The supplied thumbnails will be resized if needed, and any543* thumbnails in excess of the supported number will be ignored.544* If the format requires additional thumbnails that are not545* provided, the writer should generate them internally.546*547* <p> An <code>ImageWriteParam</code> may548* optionally be supplied to control the writing process. If549* <code>param</code> is <code>null</code>, a default write param550* will be used.551*552* <p> If the supplied <code>ImageWriteParam</code> contains553* optional setting values not supported by this writer (<i>e.g.</i>554* progressive encoding or any format-specific settings), they555* will be ignored.556*557* @param streamMetadata an <code>IIOMetadata</code> object representing558* stream metadata, or <code>null</code> to use default values.559* @param image an <code>IIOImage</code> object containing an560* image, thumbnails, and metadata to be written.561* @param param an <code>ImageWriteParam</code>, or562* <code>null</code> to use a default563* <code>ImageWriteParam</code>.564*565* @exception IllegalStateException if the output has not566* been set.567* @exception UnsupportedOperationException if <code>image</code>568* contains a <code>Raster</code> and <code>canWriteRasters</code>569* returns <code>false</code>.570* @exception IllegalArgumentException if <code>image</code> is571* <code>null</code>.572* @exception IOException if an error occurs during writing.573*/574public abstract void write(IIOMetadata streamMetadata,575IIOImage image,576ImageWriteParam param) throws IOException;577578/**579* Appends a complete image stream containing a single image with580* default metadata and thumbnails to the output. This method is581* a shorthand for <code>write(null, image, null)</code>.582*583* @param image an <code>IIOImage</code> object containing an584* image, thumbnails, and metadata to be written.585*586* @exception IllegalStateException if the output has not587* been set.588* @exception IllegalArgumentException if <code>image</code> is589* <code>null</code>.590* @exception UnsupportedOperationException if <code>image</code>591* contains a <code>Raster</code> and <code>canWriteRasters</code>592* returns <code>false</code>.593* @exception IOException if an error occurs during writing.594*/595public void write(IIOImage image) throws IOException {596write(null, image, null);597}598599/**600* Appends a complete image stream consisting of a single image601* with default metadata and thumbnails to the output. This602* method is a shorthand for <code>write(null, new IIOImage(image,603* null, null), null)</code>.604*605* @param image a <code>RenderedImage</code> to be written.606*607* @exception IllegalStateException if the output has not608* been set.609* @exception IllegalArgumentException if <code>image</code> is610* <code>null</code>.611* @exception IOException if an error occurs during writing.612*/613public void write(RenderedImage image) throws IOException {614write(null, new IIOImage(image, null, null), null);615}616617// Check that the output has been set, then throw an618// UnsupportedOperationException.619private void unsupported() {620if (getOutput() == null) {621throw new IllegalStateException("getOutput() == null!");622}623throw new UnsupportedOperationException("Unsupported write variant!");624}625626// Sequence writes627628/**629* Returns <code>true</code> if the writer is able to append an630* image to an image stream that already contains header631* information and possibly prior images.632*633* <p> If <code>canWriteSequence</code> returns <code>false</code>,634* <code>writeToSequence</code> and <code>endWriteSequence</code>635* will throw an <code>UnsupportedOperationException</code>.636*637* <p> The default implementation returns <code>false</code>.638*639* @return <code>true</code> if images may be appended sequentially.640*/641public boolean canWriteSequence() {642return false;643}644645/**646* Prepares a stream to accept a series of subsequent647* <code>writeToSequence</code> calls, using the provided stream648* metadata object. The metadata will be written to the stream if649* it should precede the image data. If the argument is <code>null</code>,650* default stream metadata is used.651*652* <p> If the output is an <code>ImageOutputStream</code>, the existing653* contents of the output prior to the current seek position are654* flushed, and need not be readable or writable. If the format655* requires that <code>endWriteSequence</code> be able to rewind to656* patch up the header information, such as for a sequence of images657* in a single TIFF file, then the metadata written by this method658* must remain in a writable portion of the stream. Other formats659* may flush the stream after this method and after each image.660*661* <p> If <code>canWriteSequence</code> returns <code>false</code>,662* this method will throw an663* <code>UnsupportedOperationException</code>.664*665* <p> The output must have been set beforehand using either666* the <code>setOutput</code> method.667*668* <p> The default implementation throws an669* <code>IllegalStateException</code> if the output is670* <code>null</code>, and otherwise throws an671* <code>UnsupportedOperationException</code>.672*673* @param streamMetadata A stream metadata object, or <code>null</code>.674*675* @exception IllegalStateException if the output has not676* been set.677* @exception UnsupportedOperationException if678* <code>canWriteSequence</code> returns <code>false</code>.679* @exception IOException if an error occurs writing the stream680* metadata.681*/682public void prepareWriteSequence(IIOMetadata streamMetadata)683throws IOException {684unsupported();685}686687/**688* Appends a single image and possibly associated metadata and689* thumbnails, to the output. If the output is an690* <code>ImageOutputStream</code>, the existing contents of the691* output prior to the current seek position may be flushed, and692* need not be readable or writable, unless the plug-in needs to693* be able to patch up the header information when694* <code>endWriteSequence</code> is called (<i>e.g.</i> TIFF).695*696* <p> If <code>canWriteSequence</code> returns <code>false</code>,697* this method will throw an698* <code>UnsupportedOperationException</code>.699*700* <p> The output must have been set beforehand using701* the <code>setOutput</code> method.702*703* <p> <code>prepareWriteSequence</code> must have been called704* beforehand, or an <code>IllegalStateException</code> is thrown.705*706* <p> If <code>canWriteRasters</code> returns <code>true</code>,707* the <code>IIOImage</code> may contain a <code>Raster</code>708* source. Otherwise, it must contain a709* <code>RenderedImage</code> source.710*711* <p> The supplied thumbnails will be resized if needed, and any712* thumbnails in excess of the supported number will be ignored.713* If the format requires additional thumbnails that are not714* provided, the writer will generate them internally.715*716* <p> An <code>ImageWriteParam</code> may optionally be supplied717* to control the writing process. If <code>param</code> is718* <code>null</code>, a default write param will be used.719*720* <p> If the supplied <code>ImageWriteParam</code> contains721* optional setting values not supported by this writer (<i>e.g.</i>722* progressive encoding or any format-specific settings), they723* will be ignored.724*725* <p> The default implementation throws an726* <code>IllegalStateException</code> if the output is727* <code>null</code>, and otherwise throws an728* <code>UnsupportedOperationException</code>.729*730* @param image an <code>IIOImage</code> object containing an731* image, thumbnails, and metadata to be written.732* @param param an <code>ImageWriteParam</code>, or733* <code>null</code> to use a default734* <code>ImageWriteParam</code>.735*736* @exception IllegalStateException if the output has not737* been set, or <code>prepareWriteSequence</code> has not been called.738* @exception UnsupportedOperationException if739* <code>canWriteSequence</code> returns <code>false</code>.740* @exception IllegalArgumentException if <code>image</code> is741* <code>null</code>.742* @exception UnsupportedOperationException if <code>image</code>743* contains a <code>Raster</code> and <code>canWriteRasters</code>744* returns <code>false</code>.745* @exception IOException if an error occurs during writing.746*/747public void writeToSequence(IIOImage image, ImageWriteParam param)748throws IOException {749unsupported();750}751752/**753* Completes the writing of a sequence of images begun with754* <code>prepareWriteSequence</code>. Any stream metadata that755* should come at the end of the sequence of images is written out,756* and any header information at the beginning of the sequence is757* patched up if necessary. If the output is an758* <code>ImageOutputStream</code>, data through the stream metadata759* at the end of the sequence are flushed and need not be readable760* or writable.761*762* <p> If <code>canWriteSequence</code> returns <code>false</code>,763* this method will throw an764* <code>UnsupportedOperationException</code>.765*766* <p> The default implementation throws an767* <code>IllegalStateException</code> if the output is768* <code>null</code>, and otherwise throws an769* <code>UnsupportedOperationException</code>.770*771* @exception IllegalStateException if the output has not772* been set, or <code>prepareWriteSequence</code> has not been called.773* @exception UnsupportedOperationException if774* <code>canWriteSequence</code> returns <code>false</code>.775* @exception IOException if an error occurs during writing.776*/777public void endWriteSequence() throws IOException {778unsupported();779}780781// Metadata replacement782783/**784* Returns <code>true</code> if it is possible to replace the785* stream metadata already present in the output.786*787* <p> The default implementation throws an788* <code>IllegalStateException</code> if the output is789* <code>null</code>, and otherwise returns <code>false</code>.790*791* @return <code>true</code> if replacement of stream metadata is792* allowed.793*794* @exception IllegalStateException if the output has not795* been set.796* @exception IOException if an I/O error occurs during the query.797*/798public boolean canReplaceStreamMetadata() throws IOException {799if (getOutput() == null) {800throw new IllegalStateException("getOutput() == null!");801}802return false;803}804805/**806* Replaces the stream metadata in the output with new807* information. If the output is an808* <code>ImageOutputStream</code>, the prior contents of the809* stream are examined and possibly edited to make room for the810* new data. All of the prior contents of the output must be811* available for reading and writing.812*813* <p> If <code>canReplaceStreamMetadata</code> returns814* <code>false</code>, an815* <code>UnsupportedOperationException</code> will be thrown.816*817* <p> The default implementation throws an818* <code>IllegalStateException</code> if the output is819* <code>null</code>, and otherwise throws an820* <code>UnsupportedOperationException</code>.821*822* @param streamMetadata an <code>IIOMetadata</code> object representing823* stream metadata, or <code>null</code> to use default values.824*825* @exception IllegalStateException if the output has not826* been set.827* @exception UnsupportedOperationException if the828* <code>canReplaceStreamMetadata</code> returns829* <code>false</code>. modes do not include830* @exception IOException if an error occurs during writing.831*/832public void replaceStreamMetadata(IIOMetadata streamMetadata)833throws IOException {834unsupported();835}836837/**838* Returns <code>true</code> if it is possible to replace the839* image metadata associated with an existing image with index840* <code>imageIndex</code>. If this method returns841* <code>false</code>, a call to842* <code>replaceImageMetadata(imageIndex)</code> will throw an843* <code>UnsupportedOperationException</code>.844*845* <p> A writer that does not support any image metadata846* replacement may return <code>false</code> without performing847* bounds checking on the index.848*849* <p> The default implementation throws an850* <code>IllegalStateException</code> if the output is851* <code>null</code>, and otherwise returns <code>false</code>852* without checking the value of <code>imageIndex</code>.853*854* @param imageIndex the index of the image whose metadata is to855* be replaced.856*857* @return <code>true</code> if the image metadata of the given858* image can be replaced.859*860* @exception IllegalStateException if the output has not861* been set.862* @exception IndexOutOfBoundsException if the writer supports863* image metadata replacement in general, but864* <code>imageIndex</code> is less than 0 or greater than the865* largest available index.866* @exception IOException if an I/O error occurs during the query.867*/868public boolean canReplaceImageMetadata(int imageIndex)869throws IOException {870if (getOutput() == null) {871throw new IllegalStateException("getOutput() == null!");872}873return false;874}875876/**877* Replaces the image metadata associated with an existing image.878*879* <p> If <code>canReplaceImageMetadata(imageIndex)</code> returns880* <code>false</code>, an881* <code>UnsupportedOperationException</code> will be thrown.882*883* <p> The default implementation throws an884* <code>IllegalStateException</code> if the output is885* <code>null</code>, and otherwise throws an886* <code>UnsupportedOperationException</code>.887*888* @param imageIndex the index of the image whose metadata is to889* be replaced.890* @param imageMetadata an <code>IIOMetadata</code> object891* representing image metadata, or <code>null</code>.892*893* @exception IllegalStateException if the output has not been894* set.895* @exception UnsupportedOperationException if896* <code>canReplaceImageMetadata</code> returns897* <code>false</code>.898* @exception IndexOutOfBoundsException if <code>imageIndex</code>899* is less than 0 or greater than the largest available index.900* @exception IOException if an error occurs during writing.901*/902public void replaceImageMetadata(int imageIndex,903IIOMetadata imageMetadata)904throws IOException {905unsupported();906}907908// Image insertion909910/**911* Returns <code>true</code> if the writer supports the insertion912* of a new image at the given index. Existing images with913* indices greater than or equal to the insertion index will have914* their indices increased by 1. A value for915* <code>imageIndex</code> of <code>-1</code> may be used to916* signify an index one larger than the current largest index.917*918* <p> A writer that does not support any image insertion may919* return <code>false</code> without performing bounds checking on920* the index.921*922* <p> The default implementation throws an923* <code>IllegalStateException</code> if the output is924* <code>null</code>, and otherwise returns <code>false</code>925* without checking the value of <code>imageIndex</code>.926*927* @param imageIndex the index at which the image is to be928* inserted.929*930* @return <code>true</code> if an image may be inserted at the931* given index.932*933* @exception IllegalStateException if the output has not934* been set.935* @exception IndexOutOfBoundsException if the writer supports936* image insertion in general, but <code>imageIndex</code> is less937* than -1 or greater than the largest available index.938* @exception IOException if an I/O error occurs during the query.939*/940public boolean canInsertImage(int imageIndex) throws IOException {941if (getOutput() == null) {942throw new IllegalStateException("getOutput() == null!");943}944return false;945}946947/**948* Inserts a new image into an existing image stream. Existing949* images with an index greater than <code>imageIndex</code> are950* preserved, and their indices are each increased by 1. A value951* for <code>imageIndex</code> of -1 may be used to signify an952* index one larger than the previous largest index; that is, it953* will cause the image to be logically appended to the end of the954* sequence. If the output is an <code>ImageOutputStream</code>,955* the entirety of the stream must be both readable and writeable.956*957* <p> If <code>canInsertImage(imageIndex)</code> returns958* <code>false</code>, an959* <code>UnsupportedOperationException</code> will be thrown.960*961* <p> An <code>ImageWriteParam</code> may optionally be supplied962* to control the writing process. If <code>param</code> is963* <code>null</code>, a default write param will be used.964*965* <p> If the supplied <code>ImageWriteParam</code> contains966* optional setting values not supported by this writer (<i>e.g.</i>967* progressive encoding or any format-specific settings), they968* will be ignored.969*970* <p> The default implementation throws an971* <code>IllegalStateException</code> if the output is972* <code>null</code>, and otherwise throws an973* <code>UnsupportedOperationException</code>.974*975* @param imageIndex the index at which to write the image.976* @param image an <code>IIOImage</code> object containing an977* image, thumbnails, and metadata to be written.978* @param param an <code>ImageWriteParam</code>, or979* <code>null</code> to use a default980* <code>ImageWriteParam</code>.981*982* @exception IllegalStateException if the output has not983* been set.984* @exception UnsupportedOperationException if985* <code>canInsertImage(imageIndex)</code> returns <code>false</code>.986* @exception IllegalArgumentException if <code>image</code> is987* <code>null</code>.988* @exception IndexOutOfBoundsException if <code>imageIndex</code>989* is less than -1 or greater than the largest available index.990* @exception UnsupportedOperationException if <code>image</code>991* contains a <code>Raster</code> and <code>canWriteRasters</code>992* returns <code>false</code>.993* @exception IOException if an error occurs during writing.994*/995public void writeInsert(int imageIndex,996IIOImage image,997ImageWriteParam param) throws IOException {998unsupported();999}10001001// Image removal10021003/**1004* Returns <code>true</code> if the writer supports the removal1005* of an existing image at the given index. Existing images with1006* indices greater than the insertion index will have1007* their indices decreased by 1.1008*1009* <p> A writer that does not support any image removal may1010* return <code>false</code> without performing bounds checking on1011* the index.1012*1013* <p> The default implementation throws an1014* <code>IllegalStateException</code> if the output is1015* <code>null</code>, and otherwise returns <code>false</code>1016* without checking the value of <code>imageIndex</code>.1017*1018* @param imageIndex the index of the image to be removed.1019*1020* @return <code>true</code> if it is possible to remove the given1021* image.1022*1023* @exception IllegalStateException if the output has not1024* been set.1025* @exception IndexOutOfBoundsException if the writer supports1026* image removal in general, but <code>imageIndex</code> is less1027* than 0 or greater than the largest available index.1028* @exception IOException if an I/O error occurs during the1029* query.1030*/1031public boolean canRemoveImage(int imageIndex) throws IOException {1032if (getOutput() == null) {1033throw new IllegalStateException("getOutput() == null!");1034}1035return false;1036}10371038/**1039* Removes an image from the stream.1040*1041* <p> If <code>canRemoveImage(imageIndex)</code> returns false,1042* an <code>UnsupportedOperationException</code>will be thrown.1043*1044* <p> The removal may or may not cause a reduction in the actual1045* file size.1046*1047* <p> The default implementation throws an1048* <code>IllegalStateException</code> if the output is1049* <code>null</code>, and otherwise throws an1050* <code>UnsupportedOperationException</code>.1051*1052* @param imageIndex the index of the image to be removed.1053*1054* @exception IllegalStateException if the output has not1055* been set.1056* @exception UnsupportedOperationException if1057* <code>canRemoveImage(imageIndex)</code> returns <code>false</code>.1058* @exception IndexOutOfBoundsException if <code>imageIndex</code>1059* is less than 0 or greater than the largest available index.1060* @exception IOException if an I/O error occurs during the1061* removal.1062*/1063public void removeImage(int imageIndex) throws IOException {1064unsupported();1065}10661067// Empty images10681069/**1070* Returns <code>true</code> if the writer supports the writing of1071* a complete image stream consisting of a single image with1072* undefined pixel values and associated metadata and thumbnails1073* to the output. The pixel values may be defined by future1074* calls to the <code>replacePixels</code> methods. If the output1075* is an <code>ImageOutputStream</code>, its existing contents1076* prior to the current seek position are not affected, and need1077* not be readable or writable.1078*1079* <p> The default implementation throws an1080* <code>IllegalStateException</code> if the output is1081* <code>null</code>, and otherwise returns <code>false</code>.1082*1083* @return <code>true</code> if the writing of complete image1084* stream with contents to be defined later is supported.1085*1086* @exception IllegalStateException if the output has not been1087* set.1088* @exception IOException if an I/O error occurs during the1089* query.1090*/1091public boolean canWriteEmpty() throws IOException {1092if (getOutput() == null) {1093throw new IllegalStateException("getOutput() == null!");1094}1095return false;1096}10971098/**1099* Begins the writing of a complete image stream, consisting of a1100* single image with undefined pixel values and associated1101* metadata and thumbnails, to the output. The pixel values will1102* be defined by future calls to the <code>replacePixels</code>1103* methods. If the output is an <code>ImageOutputStream</code>,1104* its existing contents prior to the current seek position are1105* not affected, and need not be readable or writable.1106*1107* <p> The writing is not complete until a call to1108* <code>endWriteEmpty</code> occurs. Calls to1109* <code>prepareReplacePixels</code>, <code>replacePixels</code>,1110* and <code>endReplacePixels</code> may occur between calls to1111* <code>prepareWriteEmpty</code> and <code>endWriteEmpty</code>.1112* However, calls to <code>prepareWriteEmpty</code> cannot be1113* nested, and calls to <code>prepareWriteEmpty</code> and1114* <code>prepareInsertEmpty</code> may not be interspersed.1115*1116* <p> If <code>canWriteEmpty</code> returns <code>false</code>,1117* an <code>UnsupportedOperationException</code> will be thrown.1118*1119* <p> An <code>ImageWriteParam</code> may optionally be supplied1120* to control the writing process. If <code>param</code> is1121* <code>null</code>, a default write param will be used.1122*1123* <p> If the supplied <code>ImageWriteParam</code> contains1124* optional setting values not supported by this writer (<i>e.g.</i>1125* progressive encoding or any format-specific settings), they1126* will be ignored.1127*1128* <p> The default implementation throws an1129* <code>IllegalStateException</code> if the output is1130* <code>null</code>, and otherwise throws an1131* <code>UnsupportedOperationException</code>.1132*1133* @param streamMetadata an <code>IIOMetadata</code> object representing1134* stream metadata, or <code>null</code> to use default values.1135* @param imageType an <code>ImageTypeSpecifier</code> describing1136* the layout of the image.1137* @param width the width of the image.1138* @param height the height of the image.1139* @param imageMetadata an <code>IIOMetadata</code> object1140* representing image metadata, or <code>null</code>.1141* @param thumbnails a <code>List</code> of1142* <code>BufferedImage</code> thumbnails for this image, or1143* <code>null</code>.1144* @param param an <code>ImageWriteParam</code>, or1145* <code>null</code> to use a default1146* <code>ImageWriteParam</code>.1147*1148* @exception IllegalStateException if the output has not1149* been set.1150* @exception UnsupportedOperationException if1151* <code>canWriteEmpty</code> returns <code>false</code>.1152* @exception IllegalStateException if a previous call to1153* <code>prepareWriteEmpty</code> has been made without a1154* corresponding call to <code>endWriteEmpty</code>.1155* @exception IllegalStateException if a previous call to1156* <code>prepareInsertEmpty</code> has been made without a1157* corresponding call to <code>endInsertEmpty</code>.1158* @exception IllegalArgumentException if <code>imageType</code>1159* is <code>null</code> or <code>thumbnails</code> contains1160* <code>null</code> references or objects other than1161* <code>BufferedImage</code>s.1162* @exception IllegalArgumentException if width or height are less1163* than 1.1164* @exception IOException if an I/O error occurs during writing.1165*/1166public void prepareWriteEmpty(IIOMetadata streamMetadata,1167ImageTypeSpecifier imageType,1168int width, int height,1169IIOMetadata imageMetadata,1170List<? extends BufferedImage> thumbnails,1171ImageWriteParam param) throws IOException {1172unsupported();1173}11741175/**1176* Completes the writing of a new image that was begun with a1177* prior call to <code>prepareWriteEmpty</code>.1178*1179* <p> If <code>canWriteEmpty()</code> returns <code>false</code>,1180* an <code>UnsupportedOperationException</code> will be thrown.1181*1182* <p> The default implementation throws an1183* <code>IllegalStateException</code> if the output is1184* <code>null</code>, and otherwise throws an1185* <code>UnsupportedOperationException</code>.1186*1187* @exception IllegalStateException if the output has not1188* been set.1189* @exception UnsupportedOperationException if1190* <code>canWriteEmpty(imageIndex)</code> returns1191* <code>false</code>.1192* @exception IllegalStateException if a previous call to1193* <code>prepareWriteEmpty</code> without a corresponding call to1194* <code>endWriteEmpty</code> has not been made.1195* @exception IllegalStateException if a previous call to1196* <code>prepareInsertEmpty</code> without a corresponding call to1197* <code>endInsertEmpty</code> has been made.1198* @exception IllegalStateException if a call to1199* <code>prepareReiplacePixels</code> has been made without a1200* matching call to <code>endReplacePixels</code>.1201* @exception IOException if an I/O error occurs during writing.1202*/1203public void endWriteEmpty() throws IOException {1204if (getOutput() == null) {1205throw new IllegalStateException("getOutput() == null!");1206}1207throw new IllegalStateException("No call to prepareWriteEmpty!");1208}12091210/**1211* Returns <code>true</code> if the writer supports the insertion1212* of a new, empty image at the given index. The pixel values of1213* the image are undefined, and may be specified in pieces using1214* the <code>replacePixels</code> methods. Existing images with1215* indices greater than or equal to the insertion index will have1216* their indices increased by 1. A value for1217* <code>imageIndex</code> of <code>-1</code> may be used to1218* signify an index one larger than the current largest index.1219*1220* <p> A writer that does not support insertion of empty images1221* may return <code>false</code> without performing bounds1222* checking on the index.1223*1224* <p> The default implementation throws an1225* <code>IllegalStateException</code> if the output is1226* <code>null</code>, and otherwise returns <code>false</code>1227* without checking the value of <code>imageIndex</code>.1228*1229* @param imageIndex the index at which the image is to be1230* inserted.1231*1232* @return <code>true</code> if an empty image may be inserted at1233* the given index.1234*1235* @exception IllegalStateException if the output has not been1236* set.1237* @exception IndexOutOfBoundsException if the writer supports1238* empty image insertion in general, but <code>imageIndex</code>1239* is less than -1 or greater than the largest available index.1240* @exception IOException if an I/O error occurs during the1241* query.1242*/1243public boolean canInsertEmpty(int imageIndex) throws IOException {1244if (getOutput() == null) {1245throw new IllegalStateException("getOutput() == null!");1246}1247return false;1248}12491250/**1251* Begins the insertion of a new image with undefined pixel values1252* into an existing image stream. Existing images with an index1253* greater than <code>imageIndex</code> are preserved, and their1254* indices are each increased by 1. A value for1255* <code>imageIndex</code> of -1 may be used to signify an index1256* one larger than the previous largest index; that is, it will1257* cause the image to be logically appended to the end of the1258* sequence. If the output is an <code>ImageOutputStream</code>,1259* the entirety of the stream must be both readable and writeable.1260*1261* <p> The image contents may be1262* supplied later using the <code>replacePixels</code> method.1263* The insertion is not complete until a call to1264* <code>endInsertEmpty</code> occurs. Calls to1265* <code>prepareReplacePixels</code>, <code>replacePixels</code>,1266* and <code>endReplacePixels</code> may occur between calls to1267* <code>prepareInsertEmpty</code> and1268* <code>endInsertEmpty</code>. However, calls to1269* <code>prepareInsertEmpty</code> cannot be nested, and calls to1270* <code>prepareWriteEmpty</code> and1271* <code>prepareInsertEmpty</code> may not be interspersed.1272*1273* <p> If <code>canInsertEmpty(imageIndex)</code> returns1274* <code>false</code>, an1275* <code>UnsupportedOperationException</code> will be thrown.1276*1277* <p> An <code>ImageWriteParam</code> may optionally be supplied1278* to control the writing process. If <code>param</code> is1279* <code>null</code>, a default write param will be used.1280*1281* <p> If the supplied <code>ImageWriteParam</code> contains1282* optional setting values not supported by this writer (<i>e.g.</i>1283* progressive encoding or any format-specific settings), they1284* will be ignored.1285*1286* <p> The default implementation throws an1287* <code>IllegalStateException</code> if the output is1288* <code>null</code>, and otherwise throws an1289* <code>UnsupportedOperationException</code>.1290*1291* @param imageIndex the index at which to write the image.1292* @param imageType an <code>ImageTypeSpecifier</code> describing1293* the layout of the image.1294* @param width the width of the image.1295* @param height the height of the image.1296* @param imageMetadata an <code>IIOMetadata</code> object1297* representing image metadata, or <code>null</code>.1298* @param thumbnails a <code>List</code> of1299* <code>BufferedImage</code> thumbnails for this image, or1300* <code>null</code>.1301* @param param an <code>ImageWriteParam</code>, or1302* <code>null</code> to use a default1303* <code>ImageWriteParam</code>.1304*1305* @exception IllegalStateException if the output has not1306* been set.1307* @exception UnsupportedOperationException if1308* <code>canInsertEmpty(imageIndex)</code> returns1309* <code>false</code>.1310* @exception IndexOutOfBoundsException if <code>imageIndex</code>1311* is less than -1 or greater than the largest available index.1312* @exception IllegalStateException if a previous call to1313* <code>prepareInsertEmpty</code> has been made without a1314* corresponding call to <code>endInsertEmpty</code>.1315* @exception IllegalStateException if a previous call to1316* <code>prepareWriteEmpty</code> has been made without a1317* corresponding call to <code>endWriteEmpty</code>.1318* @exception IllegalArgumentException if <code>imageType</code>1319* is <code>null</code> or <code>thumbnails</code> contains1320* <code>null</code> references or objects other than1321* <code>BufferedImage</code>s.1322* @exception IllegalArgumentException if width or height are less1323* than 1.1324* @exception IOException if an I/O error occurs during writing.1325*/1326public void prepareInsertEmpty(int imageIndex,1327ImageTypeSpecifier imageType,1328int width, int height,1329IIOMetadata imageMetadata,1330List<? extends BufferedImage> thumbnails,1331ImageWriteParam param) throws IOException {1332unsupported();1333}13341335/**1336* Completes the insertion of a new image that was begun with a1337* prior call to <code>prepareInsertEmpty</code>.1338*1339* <p> The default implementation throws an1340* <code>IllegalStateException</code> if the output is1341* <code>null</code>, and otherwise throws an1342* <code>UnsupportedOperationException</code>.1343*1344* @exception IllegalStateException if the output has not1345* been set.1346* @exception UnsupportedOperationException if1347* <code>canInsertEmpty(imageIndex)</code> returns1348* <code>false</code>.1349* @exception IllegalStateException if a previous call to1350* <code>prepareInsertEmpty</code> without a corresponding call to1351* <code>endInsertEmpty</code> has not been made.1352* @exception IllegalStateException if a previous call to1353* <code>prepareWriteEmpty</code> without a corresponding call to1354* <code>endWriteEmpty</code> has been made.1355* @exception IllegalStateException if a call to1356* <code>prepareReplacePixels</code> has been made without a1357* matching call to <code>endReplacePixels</code>.1358* @exception IOException if an I/O error occurs during writing.1359*/1360public void endInsertEmpty() throws IOException {1361unsupported();1362}13631364// Pixel replacement13651366/**1367* Returns <code>true</code> if the writer allows pixels of the1368* given image to be replaced using the <code>replacePixels</code>1369* methods.1370*1371* <p> A writer that does not support any pixel replacement may1372* return <code>false</code> without performing bounds checking on1373* the index.1374*1375* <p> The default implementation throws an1376* <code>IllegalStateException</code> if the output is1377* <code>null</code>, and otherwise returns <code>false</code>1378* without checking the value of <code>imageIndex</code>.1379*1380* @param imageIndex the index of the image whose pixels are to be1381* replaced.1382*1383* @return <code>true</code> if the pixels of the given1384* image can be replaced.1385*1386* @exception IllegalStateException if the output has not been1387* set.1388* @exception IndexOutOfBoundsException if the writer supports1389* pixel replacement in general, but <code>imageIndex</code> is1390* less than 0 or greater than the largest available index.1391* @exception IOException if an I/O error occurs during the query.1392*/1393public boolean canReplacePixels(int imageIndex) throws IOException {1394if (getOutput() == null) {1395throw new IllegalStateException("getOutput() == null!");1396}1397return false;1398}13991400/**1401* Prepares the writer to handle a series of calls to the1402* <code>replacePixels</code> methods. The affected pixel area1403* will be clipped against the supplied1404*1405* <p> If <code>canReplacePixels</code> returns1406* <code>false</code>, and1407* <code>UnsupportedOperationException</code> will be thrown.1408*1409* <p> The default implementation throws an1410* <code>IllegalStateException</code> if the output is1411* <code>null</code>, and otherwise throws an1412* <code>UnsupportedOperationException</code>.1413*1414* @param imageIndex the index of the image whose pixels are to be1415* replaced.1416* @param region a <code>Rectangle</code> that will be used to clip1417* future pixel regions.1418*1419* @exception IllegalStateException if the output has not1420* been set.1421* @exception UnsupportedOperationException if1422* <code>canReplacePixels(imageIndex)</code> returns1423* <code>false</code>.1424* @exception IndexOutOfBoundsException if <code>imageIndex</code>1425* is less than 0 or greater than the largest available index.1426* @exception IllegalStateException if there is a previous call to1427* <code>prepareReplacePixels</code> without a matching call to1428* <code>endReplacePixels</code> (<i>i.e.</i>, nesting is not1429* allowed).1430* @exception IllegalArgumentException if <code>region</code> is1431* <code>null</code> or has a width or height less than 1.1432* @exception IOException if an I/O error occurs during the1433* preparation.1434*/1435public void prepareReplacePixels(int imageIndex,1436Rectangle region) throws IOException {1437unsupported();1438}14391440/**1441* Replaces a portion of an image already present in the output1442* with a portion of the given image. The image data must match,1443* or be convertible to, the image layout of the existing image.1444*1445* <p> The destination region is specified in the1446* <code>param</code> argument, and will be clipped to the image1447* boundaries and the region supplied to1448* <code>prepareReplacePixels</code>. At least one pixel of the1449* source must not be clipped, or an exception is thrown.1450*1451* <p> An <code>ImageWriteParam</code> may optionally be supplied1452* to control the writing process. If <code>param</code> is1453* <code>null</code>, a default write param will be used.1454*1455* <p> If the supplied <code>ImageWriteParam</code> contains1456* optional setting values not supported by this writer (<i>e.g.</i>1457* progressive encoding or any format-specific settings), they1458* will be ignored.1459*1460* <p> This method may only be called after a call to1461* <code>prepareReplacePixels</code>, or else an1462* <code>IllegalStateException</code> will be thrown.1463*1464* <p> The default implementation throws an1465* <code>IllegalStateException</code> if the output is1466* <code>null</code>, and otherwise throws an1467* <code>UnsupportedOperationException</code>.1468*1469* @param image a <code>RenderedImage</code> containing source1470* pixels.1471* @param param an <code>ImageWriteParam</code>, or1472* <code>null</code> to use a default1473* <code>ImageWriteParam</code>.1474*1475* @exception IllegalStateException if the output has not1476* been set.1477* @exception UnsupportedOperationException if1478* <code>canReplacePixels(imageIndex)</code> returns1479* <code>false</code>.1480* @exception IllegalStateException if there is no previous call to1481* <code>prepareReplacePixels</code> without a matching call to1482* <code>endReplacePixels</code>.1483* @exception IllegalArgumentException if any of the following are true:1484* <ul>1485* <li> <code>image</code> is <code>null</code>.1486* <li> <code>param</code> is <code>null</code>.1487* <li> the intersected region does not contain at least one pixel.1488* <li> the layout of <code>image</code> does not match, or this1489* writer cannot convert it to, the existing image layout.1490* </ul>1491* @exception IOException if an I/O error occurs during writing.1492*/1493public void replacePixels(RenderedImage image, ImageWriteParam param)1494throws IOException {1495unsupported();1496}14971498/**1499* Replaces a portion of an image already present in the output1500* with a portion of the given <code>Raster</code>. The image1501* data must match, or be convertible to, the image layout of the1502* existing image.1503*1504* <p> An <code>ImageWriteParam</code> may optionally be supplied1505* to control the writing process. If <code>param</code> is1506* <code>null</code>, a default write param will be used.1507*1508* <p> The destination region is specified in the1509* <code>param</code> argument, and will be clipped to the image1510* boundaries and the region supplied to1511* <code>prepareReplacePixels</code>. At least one pixel of the1512* source must not be clipped, or an exception is thrown.1513*1514* <p> If the supplied <code>ImageWriteParam</code> contains1515* optional setting values not supported by this writer (<i>e.g.</i>1516* progressive encoding or any format-specific settings), they1517* will be ignored.1518*1519* <p> This method may only be called after a call to1520* <code>prepareReplacePixels</code>, or else an1521* <code>IllegalStateException</code> will be thrown.1522*1523* <p> The default implementation throws an1524* <code>IllegalStateException</code> if the output is1525* <code>null</code>, and otherwise throws an1526* <code>UnsupportedOperationException</code>.1527*1528* @param raster a <code>Raster</code> containing source1529* pixels.1530* @param param an <code>ImageWriteParam</code>, or1531* <code>null</code> to use a default1532* <code>ImageWriteParam</code>.1533*1534* @exception IllegalStateException if the output has not1535* been set.1536* @exception UnsupportedOperationException if1537* <code>canReplacePixels(imageIndex)</code> returns1538* <code>false</code>.1539* @exception IllegalStateException if there is no previous call to1540* <code>prepareReplacePixels</code> without a matching call to1541* <code>endReplacePixels</code>.1542* @exception UnsupportedOperationException if1543* <code>canWriteRasters</code> returns <code>false</code>.1544* @exception IllegalArgumentException if any of the following are true:1545* <ul>1546* <li> <code>raster</code> is <code>null</code>.1547* <li> <code>param</code> is <code>null</code>.1548* <li> the intersected region does not contain at least one pixel.1549* <li> the layout of <code>raster</code> does not match, or this1550* writer cannot convert it to, the existing image layout.1551* </ul>1552* @exception IOException if an I/O error occurs during writing.1553*/1554public void replacePixels(Raster raster, ImageWriteParam param)1555throws IOException {1556unsupported();1557}15581559/**1560* Terminates a sequence of calls to <code>replacePixels</code>.1561*1562* <p> If <code>canReplacePixels</code> returns1563* <code>false</code>, and1564* <code>UnsupportedOperationException</code> will be thrown.1565*1566* <p> The default implementation throws an1567* <code>IllegalStateException</code> if the output is1568* <code>null</code>, and otherwise throws an1569* <code>UnsupportedOperationException</code>.1570*1571* @exception IllegalStateException if the output has not1572* been set.1573* @exception UnsupportedOperationException if1574* <code>canReplacePixels(imageIndex)</code> returns1575* <code>false</code>.1576* @exception IllegalStateException if there is no previous call1577* to <code>prepareReplacePixels</code> without a matching call to1578* <code>endReplacePixels</code>.1579* @exception IOException if an I/O error occurs during writing.1580*/1581public void endReplacePixels() throws IOException {1582unsupported();1583}15841585// Abort15861587/**1588* Requests that any current write operation be aborted. The1589* contents of the output following the abort will be undefined.1590*1591* <p> Writers should call <code>clearAbortRequest</code> at the1592* beginning of each write operation, and poll the value of1593* <code>abortRequested</code> regularly during the write.1594*/1595public synchronized void abort() {1596this.abortFlag = true;1597}15981599/**1600* Returns <code>true</code> if a request to abort the current1601* write operation has been made since the writer was instantiated or1602* <code>clearAbortRequest</code> was called.1603*1604* @return <code>true</code> if the current write operation should1605* be aborted.1606*1607* @see #abort1608* @see #clearAbortRequest1609*/1610protected synchronized boolean abortRequested() {1611return this.abortFlag;1612}16131614/**1615* Clears any previous abort request. After this method has been1616* called, <code>abortRequested</code> will return1617* <code>false</code>.1618*1619* @see #abort1620* @see #abortRequested1621*/1622protected synchronized void clearAbortRequest() {1623this.abortFlag = false;1624}16251626// Listeners16271628/**1629* Adds an <code>IIOWriteWarningListener</code> to the list of1630* registered warning listeners. If <code>listener</code> is1631* <code>null</code>, no exception will be thrown and no action1632* will be taken. Messages sent to the given listener will be1633* localized, if possible, to match the current1634* <code>Locale</code>. If no <code>Locale</code> has been set,1635* warning messages may be localized as the writer sees fit.1636*1637* @param listener an <code>IIOWriteWarningListener</code> to be1638* registered.1639*1640* @see #removeIIOWriteWarningListener1641*/1642public void addIIOWriteWarningListener(IIOWriteWarningListener listener) {1643if (listener == null) {1644return;1645}1646warningListeners = ImageReader.addToList(warningListeners, listener);1647warningLocales = ImageReader.addToList(warningLocales, getLocale());1648}16491650/**1651* Removes an <code>IIOWriteWarningListener</code> from the list1652* of registered warning listeners. If the listener was not1653* previously registered, or if <code>listener</code> is1654* <code>null</code>, no exception will be thrown and no action1655* will be taken.1656*1657* @param listener an <code>IIOWriteWarningListener</code> to be1658* deregistered.1659*1660* @see #addIIOWriteWarningListener1661*/1662public1663void removeIIOWriteWarningListener(IIOWriteWarningListener listener) {1664if (listener == null || warningListeners == null) {1665return;1666}1667int index = warningListeners.indexOf(listener);1668if (index != -1) {1669warningListeners.remove(index);1670warningLocales.remove(index);1671if (warningListeners.size() == 0) {1672warningListeners = null;1673warningLocales = null;1674}1675}1676}16771678/**1679* Removes all currently registered1680* <code>IIOWriteWarningListener</code> objects.1681*1682* <p> The default implementation sets the1683* <code>warningListeners</code> and <code>warningLocales</code>1684* instance variables to <code>null</code>.1685*/1686public void removeAllIIOWriteWarningListeners() {1687this.warningListeners = null;1688this.warningLocales = null;1689}16901691/**1692* Adds an <code>IIOWriteProgressListener</code> to the list of1693* registered progress listeners. If <code>listener</code> is1694* <code>null</code>, no exception will be thrown and no action1695* will be taken.1696*1697* @param listener an <code>IIOWriteProgressListener</code> to be1698* registered.1699*1700* @see #removeIIOWriteProgressListener1701*/1702public void1703addIIOWriteProgressListener(IIOWriteProgressListener listener) {1704if (listener == null) {1705return;1706}1707progressListeners = ImageReader.addToList(progressListeners, listener);1708}17091710/**1711* Removes an <code>IIOWriteProgressListener</code> from the list1712* of registered progress listeners. If the listener was not1713* previously registered, or if <code>listener</code> is1714* <code>null</code>, no exception will be thrown and no action1715* will be taken.1716*1717* @param listener an <code>IIOWriteProgressListener</code> to be1718* deregistered.1719*1720* @see #addIIOWriteProgressListener1721*/1722public void1723removeIIOWriteProgressListener(IIOWriteProgressListener listener) {1724if (listener == null || progressListeners == null) {1725return;1726}1727progressListeners =1728ImageReader.removeFromList(progressListeners, listener);1729}17301731/**1732* Removes all currently registered1733* <code>IIOWriteProgressListener</code> objects.1734*1735* <p> The default implementation sets the1736* <code>progressListeners</code> instance variable to1737* <code>null</code>.1738*/1739public void removeAllIIOWriteProgressListeners() {1740this.progressListeners = null;1741}17421743/**1744* Broadcasts the start of an image write to all registered1745* <code>IIOWriteProgressListener</code>s by calling their1746* <code>imageStarted</code> method. Subclasses may use this1747* method as a convenience.1748*1749* @param imageIndex the index of the image about to be written.1750*/1751protected void processImageStarted(int imageIndex) {1752if (progressListeners == null) {1753return;1754}1755int numListeners = progressListeners.size();1756for (int i = 0; i < numListeners; i++) {1757IIOWriteProgressListener listener =1758(IIOWriteProgressListener)progressListeners.get(i);1759listener.imageStarted(this, imageIndex);1760}1761}17621763/**1764* Broadcasts the current percentage of image completion to all1765* registered <code>IIOWriteProgressListener</code>s by calling1766* their <code>imageProgress</code> method. Subclasses may use1767* this method as a convenience.1768*1769* @param percentageDone the current percentage of completion,1770* as a <code>float</code>.1771*/1772protected void processImageProgress(float percentageDone) {1773if (progressListeners == null) {1774return;1775}1776int numListeners = progressListeners.size();1777for (int i = 0; i < numListeners; i++) {1778IIOWriteProgressListener listener =1779(IIOWriteProgressListener)progressListeners.get(i);1780listener.imageProgress(this, percentageDone);1781}1782}17831784/**1785* Broadcasts the completion of an image write to all registered1786* <code>IIOWriteProgressListener</code>s by calling their1787* <code>imageComplete</code> method. Subclasses may use this1788* method as a convenience.1789*/1790protected void processImageComplete() {1791if (progressListeners == null) {1792return;1793}1794int numListeners = progressListeners.size();1795for (int i = 0; i < numListeners; i++) {1796IIOWriteProgressListener listener =1797(IIOWriteProgressListener)progressListeners.get(i);1798listener.imageComplete(this);1799}1800}18011802/**1803* Broadcasts the start of a thumbnail write to all registered1804* <code>IIOWriteProgressListener</code>s by calling their1805* <code>thumbnailStarted</code> method. Subclasses may use this1806* method as a convenience.1807*1808* @param imageIndex the index of the image associated with the1809* thumbnail.1810* @param thumbnailIndex the index of the thumbnail.1811*/1812protected void processThumbnailStarted(int imageIndex,1813int thumbnailIndex) {1814if (progressListeners == null) {1815return;1816}1817int numListeners = progressListeners.size();1818for (int i = 0; i < numListeners; i++) {1819IIOWriteProgressListener listener =1820(IIOWriteProgressListener)progressListeners.get(i);1821listener.thumbnailStarted(this, imageIndex, thumbnailIndex);1822}1823}18241825/**1826* Broadcasts the current percentage of thumbnail completion to1827* all registered <code>IIOWriteProgressListener</code>s by calling1828* their <code>thumbnailProgress</code> method. Subclasses may1829* use this method as a convenience.1830*1831* @param percentageDone the current percentage of completion,1832* as a <code>float</code>.1833*/1834protected void processThumbnailProgress(float percentageDone) {1835if (progressListeners == null) {1836return;1837}1838int numListeners = progressListeners.size();1839for (int i = 0; i < numListeners; i++) {1840IIOWriteProgressListener listener =1841(IIOWriteProgressListener)progressListeners.get(i);1842listener.thumbnailProgress(this, percentageDone);1843}1844}18451846/**1847* Broadcasts the completion of a thumbnail write to all registered1848* <code>IIOWriteProgressListener</code>s by calling their1849* <code>thumbnailComplete</code> method. Subclasses may use this1850* method as a convenience.1851*/1852protected void processThumbnailComplete() {1853if (progressListeners == null) {1854return;1855}1856int numListeners = progressListeners.size();1857for (int i = 0; i < numListeners; i++) {1858IIOWriteProgressListener listener =1859(IIOWriteProgressListener)progressListeners.get(i);1860listener.thumbnailComplete(this);1861}1862}18631864/**1865* Broadcasts that the write has been aborted to all registered1866* <code>IIOWriteProgressListener</code>s by calling their1867* <code>writeAborted</code> method. Subclasses may use this1868* method as a convenience.1869*/1870protected void processWriteAborted() {1871if (progressListeners == null) {1872return;1873}1874int numListeners = progressListeners.size();1875for (int i = 0; i < numListeners; i++) {1876IIOWriteProgressListener listener =1877(IIOWriteProgressListener)progressListeners.get(i);1878listener.writeAborted(this);1879}1880}18811882/**1883* Broadcasts a warning message to all registered1884* <code>IIOWriteWarningListener</code>s by calling their1885* <code>warningOccurred</code> method. Subclasses may use this1886* method as a convenience.1887*1888* @param imageIndex the index of the image on which the warning1889* occurred.1890* @param warning the warning message.1891*1892* @exception IllegalArgumentException if <code>warning</code>1893* is <code>null</code>.1894*/1895protected void processWarningOccurred(int imageIndex,1896String warning) {1897if (warningListeners == null) {1898return;1899}1900if (warning == null) {1901throw new IllegalArgumentException("warning == null!");1902}1903int numListeners = warningListeners.size();1904for (int i = 0; i < numListeners; i++) {1905IIOWriteWarningListener listener =1906(IIOWriteWarningListener)warningListeners.get(i);19071908listener.warningOccurred(this, imageIndex, warning);1909}1910}19111912/**1913* Broadcasts a localized warning message to all registered1914* <code>IIOWriteWarningListener</code>s by calling their1915* <code>warningOccurred</code> method with a string taken1916* from a <code>ResourceBundle</code>. Subclasses may use this1917* method as a convenience.1918*1919* @param imageIndex the index of the image on which the warning1920* occurred.1921* @param baseName the base name of a set of1922* <code>ResourceBundle</code>s containing localized warning1923* messages.1924* @param keyword the keyword used to index the warning message1925* within the set of <code>ResourceBundle</code>s.1926*1927* @exception IllegalArgumentException if <code>baseName</code>1928* is <code>null</code>.1929* @exception IllegalArgumentException if <code>keyword</code>1930* is <code>null</code>.1931* @exception IllegalArgumentException if no appropriate1932* <code>ResourceBundle</code> may be located.1933* @exception IllegalArgumentException if the named resource is1934* not found in the located <code>ResourceBundle</code>.1935* @exception IllegalArgumentException if the object retrieved1936* from the <code>ResourceBundle</code> is not a1937* <code>String</code>.1938*/1939protected void processWarningOccurred(int imageIndex,1940String baseName,1941String keyword) {1942if (warningListeners == null) {1943return;1944}1945if (baseName == null) {1946throw new IllegalArgumentException("baseName == null!");1947}1948if (keyword == null) {1949throw new IllegalArgumentException("keyword == null!");1950}1951int numListeners = warningListeners.size();1952for (int i = 0; i < numListeners; i++) {1953IIOWriteWarningListener listener =1954(IIOWriteWarningListener)warningListeners.get(i);1955Locale locale = (Locale)warningLocales.get(i);1956if (locale == null) {1957locale = Locale.getDefault();1958}19591960/**1961* If an applet supplies an implementation of ImageWriter and1962* resource bundles, then the resource bundle will need to be1963* accessed via the applet class loader. So first try the context1964* class loader to locate the resource bundle.1965* If that throws MissingResourceException, then try the1966* system class loader.1967*/1968ClassLoader loader = (ClassLoader)1969java.security.AccessController.doPrivileged(1970new java.security.PrivilegedAction() {1971public Object run() {1972return Thread.currentThread().getContextClassLoader();1973}1974});19751976ResourceBundle bundle = null;1977try {1978bundle = ResourceBundle.getBundle(baseName, locale, loader);1979} catch (MissingResourceException mre) {1980try {1981bundle = ResourceBundle.getBundle(baseName, locale);1982} catch (MissingResourceException mre1) {1983throw new IllegalArgumentException("Bundle not found!");1984}1985}19861987String warning = null;1988try {1989warning = bundle.getString(keyword);1990} catch (ClassCastException cce) {1991throw new IllegalArgumentException("Resource is not a String!");1992} catch (MissingResourceException mre) {1993throw new IllegalArgumentException("Resource is missing!");1994}19951996listener.warningOccurred(this, imageIndex, warning);1997}1998}19992000// State management20012002/**2003* Restores the <code>ImageWriter</code> to its initial state.2004*2005* <p> The default implementation calls2006* <code>setOutput(null)</code>, <code>setLocale(null)</code>,2007* <code>removeAllIIOWriteWarningListeners()</code>,2008* <code>removeAllIIOWriteProgressListeners()</code>, and2009* <code>clearAbortRequest</code>.2010*/2011public void reset() {2012setOutput(null);2013setLocale(null);2014removeAllIIOWriteWarningListeners();2015removeAllIIOWriteProgressListeners();2016clearAbortRequest();2017}20182019/**2020* Allows any resources held by this object to be released. The2021* result of calling any other method (other than2022* <code>finalize</code>) subsequent to a call to this method2023* is undefined.2024*2025* <p>It is important for applications to call this method when they2026* know they will no longer be using this <code>ImageWriter</code>.2027* Otherwise, the writer may continue to hold on to resources2028* indefinitely.2029*2030* <p>The default implementation of this method in the superclass does2031* nothing. Subclass implementations should ensure that all resources,2032* especially native resources, are released.2033*/2034public void dispose() {2035}2036}203720382039