blob: d6119b0789ab320e0522ef1d49bd7237cd276b16 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * @author Rustem V. Rafikov
19 * @version $Revision: 1.3 $
20 */
21package javax.imageio;
22
23import java.awt.Dimension;
24import java.awt.Rectangle;
25import java.awt.image.BufferedImage;
26import java.awt.image.Raster;
27import java.awt.image.RenderedImage;
28import java.io.IOException;
29import java.security.AccessController;
30import java.security.PrivilegedAction;
31import java.util.ArrayList;
32import java.util.List;
33import java.util.Locale;
34import java.util.MissingResourceException;
35import java.util.ResourceBundle;
36
37import javax.imageio.event.IIOWriteProgressListener;
38import javax.imageio.event.IIOWriteWarningListener;
39import javax.imageio.metadata.IIOMetadata;
40import javax.imageio.spi.ImageWriterSpi;
41
42/**
43 * The ImageWriter class is an abstract class for encoding images.
44 * ImageWriter objects are instantiated by the service provider
45 * interface, ImageWriterSpi class, for the specific format.
46 * ImageWriterSpi class should be registered with the IIORegistry,
47 * which uses them for format recognition and presentation of available
48 * format readers and writers.
49 */
50public abstract class ImageWriter implements ImageTranscoder {
51
52 /** The available locales. */
53 protected Locale[] availableLocales;
54
55 /** The locale. */
56 protected Locale locale;
57
58 /** The originating provider. */
59 protected ImageWriterSpi originatingProvider;
60
61 /** The output. */
62 protected Object output;
63
64 /** The progress listeners. */
65 protected List<IIOWriteProgressListener> progressListeners;
66
67 /** The warning listeners. */
68 protected List<IIOWriteWarningListener> warningListeners;
69
70 /** The warning locales. */
71 protected List<Locale> warningLocales;
72
73 // Indicates that abort operation is requested
74 // Abort mechanism should be thread-safe
75 /** The aborted. */
76 private boolean aborted;
77
78 /**
79 * Instantiates a new ImageWriter.
80 *
81 * @param originatingProvider the ImageWriterSpi which
82 * instanties this ImageWriter.
83 */
84 protected ImageWriter(ImageWriterSpi originatingProvider) {
85 this.originatingProvider = originatingProvider;
86 }
87
88 public abstract IIOMetadata convertStreamMetadata(IIOMetadata iioMetadata,
89 ImageWriteParam imageWriteParam);
90
91 public abstract IIOMetadata convertImageMetadata(IIOMetadata iioMetadata,
92 ImageTypeSpecifier imageTypeSpecifier,
93 ImageWriteParam imageWriteParam);
94
95 /**
96 * Gets the ImageWriterSpi which instantiated this ImageWriter.
97 *
98 * @return the ImageWriterSpi.
99 */
100 public ImageWriterSpi getOriginatingProvider() {
101 return originatingProvider;
102 }
103
104 /**
105 * Processes the start of an image read by calling their imageStarted
106 * method of registered IIOWriteProgressListeners.
107 *
108 * @param imageIndex the image index.
109 */
110 protected void processImageStarted(int imageIndex) {
111 if (null != progressListeners) {
112 for (IIOWriteProgressListener listener : progressListeners) {
113 listener.imageStarted(this, imageIndex);
114 }
115 }
116 }
117
118 /**
119 * Processes the current percentage of image completion by calling
120 * imageProgress method of registered IIOWriteProgressListener.
121 *
122 * @param percentageDone the percentage done.
123 */
124 protected void processImageProgress(float percentageDone) {
125 if (null != progressListeners) {
126 for (IIOWriteProgressListener listener : progressListeners) {
127 listener.imageProgress(this, percentageDone);
128 }
129 }
130 }
131
132 /**
133 * Processes image completion by calling imageComplete method
134 * of registered IIOWriteProgressListeners.
135 */
136 protected void processImageComplete() {
137 if (null != progressListeners) {
138 for (IIOWriteProgressListener listener : progressListeners) {
139 listener.imageComplete(this);
140 }
141 }
142 }
143
144 /**
145 * Processes a warning message by calling warningOccurred method
146 * of registered IIOWriteWarningListeners.
147 *
148 * @param imageIndex the image index.
149 * @param warning the warning.
150 */
151 protected void processWarningOccurred(int imageIndex, String warning) {
152 if (null == warning) {
153 throw new NullPointerException("warning message should not be NULL");
154 }
155 if (null != warningListeners) {
156 for (IIOWriteWarningListener listener : warningListeners) {
157 listener.warningOccurred(this, imageIndex, warning);
158 }
159 }
160 }
161
162 /**
163 * Processes a warning message by calling warningOccurred method
164 * of registered IIOWriteWarningListeners with string from
165 * ResourceBundle.
166 *
167 * @param imageIndex the image index.
168 * @param bundle the name of ResourceBundle.
169 * @param key the keyword.
170 */
171 protected void processWarningOccurred(int imageIndex, String bundle, String key) {
172 if (warningListeners != null) { // Don't check the parameters
173 return;
174 }
175
176 if (bundle == null) {
177 throw new IllegalArgumentException("baseName == null!");
178 }
179 if (key == null) {
180 throw new IllegalArgumentException("keyword == null!");
181 }
182
183 // Get the context class loader and try to locate the bundle with it first
184 ClassLoader contextClassloader = AccessController.doPrivileged(
185 new PrivilegedAction<ClassLoader>() {
186 public ClassLoader run() {
187 return Thread.currentThread().getContextClassLoader();
188 }
189 });
190
191 // Iterate through both listeners and locales
192 int n = warningListeners.size();
193 for (int i=0; i < n; i++) {
194 IIOWriteWarningListener listener = warningListeners.get(i);
195 Locale locale = warningLocales.get(i);
196
197 // Now try to get the resource bundle
198 ResourceBundle rb;
199 try {
200 rb = ResourceBundle.getBundle(bundle, locale, contextClassloader);
201 } catch (MissingResourceException e) {
202 try {
203 rb = ResourceBundle.getBundle(bundle, locale);
204 } catch (MissingResourceException e1) {
205 throw new IllegalArgumentException("Bundle not found!");
206 }
207 }
208
209 try {
210 String warning = rb.getString(key);
211 listener.warningOccurred(this, imageIndex, warning);
212 } catch (MissingResourceException e) {
213 throw new IllegalArgumentException("Resource is missing!");
214 } catch (ClassCastException e) {
215 throw new IllegalArgumentException("Resource is not a String!");
216 }
217 }
218 }
219
220 /**
221 * Sets the specified Object to the output of this ImageWriter.
222 *
223 * @param output the Object which represents destination, it can
224 * be ImageOutputStream or other objects.
225 */
226 public void setOutput(Object output) {
227 if (output != null) {
228 ImageWriterSpi spi = getOriginatingProvider();
229 if (null != spi) {
230 Class[] outTypes = spi.getOutputTypes();
231 boolean supported = false;
232 for (Class<?> element : outTypes) {
233 if (element.isInstance(output)) {
234 supported = true;
235 break;
236 }
237 }
238 if (!supported) {
239 throw new IllegalArgumentException("output " + output + " is not supported");
240 }
241 }
242 }
243 this.output = output;
244 }
245
246 /**
247 * Writes a completed image stream that contains the specified image,
248 * default metadata, and thumbnails to the output.
249 *
250 * @param image the specified image to be written.
251 *
252 * @throws IOException Signals that an I/O exception has occurred
253 * during writting.
254 */
255 public void write(IIOImage image) throws IOException {
256 write(null, image, null);
257 }
258
259 /**
260 * Writes a completed image stream that contains the specified
261 * rendered image, default metadata, and thumbnails to the output.
262 *
263 * @param image the specified RenderedImage to be written.
264 *
265 * @throws IOException Signals that an I/O exception has occurred
266 * during writting.
267 */
268 public void write(RenderedImage image) throws IOException {
269 write(null, new IIOImage(image, null, null), null);
270 }
271
272 /**
273 * Writes a completed image stream that contains the specified image,
274 * metadata and thumbnails to the output.
275 *
276 * @param streamMetadata the stream metadata, or null.
277 * @param image the specified image to be written, if
278 * canWriteRaster() method returns false, then Image must contain
279 * only RenderedImage.
280 * @param param the ImageWriteParam, or null.
281 *
282 * @throws IOException - if an error occurs during writing.
283 */
284 public abstract void write(IIOMetadata streamMetadata,
285 IIOImage image, ImageWriteParam param) throws IOException;
286
287 /**
288 * Disposes of any resources.
289 */
290 public void dispose() {
291 // def impl. does nothing according to the spec.
292 }
293
294 /**
295 * Requests an abort operation for current writing operation.
296 */
297 public synchronized void abort() {
298 aborted = true;
299 }
300
301 /**
302 * Checks whether or not a request to abort the current write operation
303 * has been made successfully.
304 *
305 * @return true, if the request to abort the current write operation
306 * has been made successfully, false otherwise.
307 */
308 protected synchronized boolean abortRequested() {
309 return aborted;
310 }
311
312 /**
313 * Clears all previous abort request, and abortRequested returns false
314 * after calling this method.
315 */
316 protected synchronized void clearAbortRequest() {
317 aborted = false;
318 }
319
320 /**
321 * Adds the IIOWriteProgressListener listener.
322 *
323 * @param listener the IIOWriteProgressListener listener.
324 */
325 public void addIIOWriteProgressListener(IIOWriteProgressListener listener) {
326 if (listener == null) {
327 return;
328 }
329
330 if (progressListeners == null) {
331 progressListeners = new ArrayList<IIOWriteProgressListener>();
332 }
333
334 progressListeners.add(listener);
335 }
336
337 /**
338 * Adds the IIOWriteWarningListener.
339 *
340 * @param listener the IIOWriteWarningListener listener.
341 */
342 public void addIIOWriteWarningListener(IIOWriteWarningListener listener) {
343 if (listener == null) {
344 return;
345 }
346
347 if (warningListeners == null) {
348 warningListeners = new ArrayList<IIOWriteWarningListener>();
349 warningLocales = new ArrayList<Locale>();
350 }
351
352 warningListeners.add(listener);
353 warningLocales.add(getLocale());
354 }
355
356 /**
357 * Gets the output object that was set by setOutput method.
358 *
359 * @return the output object such as ImageOutputStream, or null if
360 * it is not set.
361 */
362 public Object getOutput() {
363 return output;
364 }
365
366 /**
367 * Check output return false.
368 *
369 * @return true, if successful
370 */
371 private final boolean checkOutputReturnFalse() {
372 if (getOutput() == null) {
373 throw new IllegalStateException("getOutput() == null!");
374 }
375 return false;
376 }
377
378 /**
379 * Unsupported operation.
380 */
381 private final void unsupportedOperation() {
382 if (getOutput() == null) {
383 throw new IllegalStateException("getOutput() == null!");
384 }
385 throw new UnsupportedOperationException("Unsupported write variant!");
386 }
387
388
389 /**
390 * Returns true if a new empty image can be inserted at
391 * the specified index.
392 *
393 * @param imageIndex the specified index of image.
394 *
395 * @return true if a new empty image can be inserted at
396 * the specified index, false otherwise.
397 *
398 * @throws IOException Signals that an I/O exception has occurred.
399 */
400 public boolean canInsertEmpty(int imageIndex) throws IOException {
401 return checkOutputReturnFalse();
402 }
403
404 /**
405 * Returns true if a new image can be inserted at the specified index.
406 *
407 * @param imageIndex the specified index of image.
408 *
409 * @return true if a new image can be inserted at the specified index,
410 * false otherwise.
411 *
412 * @throws IOException Signals that an I/O exception has occurred.
413 */
414 public boolean canInsertImage(int imageIndex) throws IOException {
415 return checkOutputReturnFalse();
416 }
417
418 /**
419 * Returnes true if the image with the specified index can be removed.
420 *
421 * @param imageIndex the specified index of image.
422 *
423 * @return true if the image with the specified index can be removed,
424 * false otherwise.
425 *
426 * @throws IOException Signals that an I/O exception has occurred.
427 */
428 public boolean canRemoveImage(int imageIndex) throws IOException {
429 return checkOutputReturnFalse();
430 }
431
432 /**
433 * Returns true if metadata of the image with the specified index
434 * can be replaced.
435 *
436 * @param imageIndex the specified image index.
437 *
438 * @return true if metadata of the image with the specified index
439 * can be replaced, false otherwise.
440 *
441 * @throws IOException Signals that an I/O exception has occurred.
442 */
443 public boolean canReplaceImageMetadata(int imageIndex) throws IOException {
444 return checkOutputReturnFalse();
445 }
446
447 /**
448 * Returns true if pixels of the image with the specified index
449 * can be replaced by the replacePixels methods.
450 *
451 * @param imageIndex the image's index.
452 *
453 * @return true if pixels of the image with the specified index
454 * can be replaced by the replacePixels methods, false otherwise.
455 *
456 * @throws IOException Signals that an I/O exception has occurred.
457 */
458 public boolean canReplacePixels(int imageIndex) throws IOException {
459 return checkOutputReturnFalse();
460 }
461
462 /**
463 * Returns true if the stream metadata presented in the output
464 * can be removed.
465 *
466 * @return true if the stream metadata presented in the output
467 * can be removed, false otherwise.
468 *
469 * @throws IOException Signals that an I/O exception has occurred.
470 */
471 public boolean canReplaceStreamMetadata() throws IOException {
472 return checkOutputReturnFalse();
473 }
474
475 /**
476 * Returns true if the writing of a complete image stream which
477 * contains a single image is supported with undefined pixel
478 * values and associated metadata and thumbnails to the output.
479 *
480 * @return true if the writing of a complete image stream which
481 * contains a single image is supported, false otherwise.
482 *
483 * @throws IOException Signals that an I/O exception has occurred.
484 */
485 public boolean canWriteEmpty() throws IOException {
486 return checkOutputReturnFalse();
487 }
488
489 /**
490 * Returns true if the methods which taken an IIOImageParameter
491 * can deal with a Raster source image.
492 *
493 * @return true if the methods which taken an IIOImageParameter
494 * can deal with a Raster source image, false otherwise.
495 */
496 public boolean canWriteRasters() {
497 return false;
498 }
499
500 /**
501 * Returns true if the writer can add an image to stream that
502 * already contains header information.
503 *
504 * @return if the writer can add an image to stream that
505 * already contains header information, false otherwise.
506 */
507 public boolean canWriteSequence() {
508 return false;
509 }
510
511 /**
512 * Ends the insertion of a new image.
513 *
514 * @throws IOException Signals that an I/O exception has occurred.
515 */
516 public void endInsertEmpty() throws IOException {
517 unsupportedOperation();
518 }
519
520 /**
521 * Ends the repalce pixels operation.
522 *
523 * @throws IOException Signals that an I/O exception has occurred.
524 */
525 public void endReplacePixels() throws IOException {
526 unsupportedOperation();
527 }
528
529 /**
530 * Ends an empty write operation.
531 *
532 * @throws IOException Signals that an I/O exception has occurred.
533 */
534 public void endWriteEmpty() throws IOException {
535 unsupportedOperation();
536 }
537
538 /**
539 * Ends the sequence of write operations.
540 *
541 * @throws IOException Signals that an I/O exception has occurred.
542 */
543 public void endWriteSequence() throws IOException {
544 unsupportedOperation();
545 }
546
547 /**
548 * Gets an array of available locales.
549 *
550 * @return an of array available locales.
551 */
552 public Locale[] getAvailableLocales() {
553 if (availableLocales == null) {
554 return null;
555 }
556
557 return availableLocales.clone();
558 }
559
560 /**
561 * Gets an IIOMetadata object that contains default values
562 * for encoding an image with the specified type.
563 *
564 * @param imageType the ImageTypeSpecifier.
565 * @param param the ImageWriteParam.
566 *
567 * @return the IIOMetadata object.
568 */
569 public abstract IIOMetadata getDefaultImageMetadata(
570 ImageTypeSpecifier imageType,
571 ImageWriteParam param
572 );
573
574 /**
575 * Gets an IIOMetadata object that contains default values
576 * for encoding a stream of images.
577 *
578 * @param param the ImageWriteParam.
579 *
580 * @return the IIOMetadata object.
581 */
582 public abstract IIOMetadata getDefaultStreamMetadata(ImageWriteParam param);
583
584 /**
585 * Gets the current locale of this ImageWriter.
586 *
587 * @return the current locale of this ImageWriter.
588 */
589 public Locale getLocale() {
590 return locale;
591 }
592
593 /**
594 * Gets the default write param.
595 * Gets a new ImageWriteParam object for this ImageWriter with the
596 * current Locale.
597 *
598 * @return a new ImageWriteParam object for this ImageWriter.
599 */
600 public ImageWriteParam getDefaultWriteParam() {
601 return new ImageWriteParam(getLocale());
602 }
603
604 /**
605 * Gets the number of thumbnails suported by the format
606 * being written with supported image type, image write
607 * parameters, stream, and image metadata objects.
608 *
609 * @param imageType the ImageTypeSpecifier.
610 * @param param the image's parameters.
611 * @param streamMetadata the stream metadata.
612 * @param imageMetadata the image metadata.
613 *
614 * @return the number of thumbnails supported
615 */
616 public int getNumThumbnailsSupported(
617 ImageTypeSpecifier imageType,
618 ImageWriteParam param,
619 IIOMetadata streamMetadata,
620 IIOMetadata imageMetadata
621 ) {
622 return 0;
623 }
624
625 /**
626 * Gets the preferred thumbnail sizes.
627 * Gets an array of Dimensions with the sizes for thumbnail images
628 * as they are encoded in the output file or stream.
629 *
630 * @param imageType the ImageTypeSpecifier.
631 * @param param the ImageWriteParam.
632 * @param streamMetadata the stream metadata.
633 * @param imageMetadata the image metadata.
634 *
635 * @return the preferred thumbnail sizes
636 */
637 public Dimension[] getPreferredThumbnailSizes(
638 ImageTypeSpecifier imageType,
639 ImageWriteParam param,
640 IIOMetadata streamMetadata,
641 IIOMetadata imageMetadata
642 ) {
643 return null;
644 }
645
646 /**
647 * Prepares insertion of an empty image by requesting the insertion of
648 * a new image into an existing image stream.
649 *
650 * @param imageIndex the image index.
651 * @param imageType the image type.
652 * @param width the width of the image.
653 * @param height the height of the image.
654 * @param imageMetadata the image metadata, or null.
655 * @param thumbnails the array thumbnails for this image, or null.
656 * @param param the ImageWriteParam, or null.
657 *
658 * @throws IOException Signals that an I/O exception has occurred.
659 */
660 public void prepareInsertEmpty(
661 int imageIndex, ImageTypeSpecifier imageType,
662 int width, int height,
663 IIOMetadata imageMetadata, List<? extends BufferedImage> thumbnails,
664 ImageWriteParam param
665 ) throws IOException {
666 unsupportedOperation();
667 }
668
669 /**
670 * Prepares the writer to call the replacePixels method for the
671 * specified region.
672 *
673 * @param imageIndex the image's index.
674 * @param region the specified region.
675 *
676 * @throws IOException Signals that an I/O exception has occurred.
677 */
678 public void prepareReplacePixels(int imageIndex, Rectangle region) throws IOException {
679 unsupportedOperation();
680 }
681
682 /**
683 * Prepares the writer for writing an empty image by beginning the
684 * process of writing a complete image stream that contains a single image
685 * with undefined pixel values, metadata and thumbnails,
686 * to the output.
687 *
688 * @param streamMetadata the stream metadata.
689 * @param imageType the image type.
690 * @param width the width of the image.
691 * @param height the height of the image.
692 * @param imageMetadata the image's metadata, or null.
693 * @param thumbnails the image's thumbnails, or null.
694 * @param param the image's parameters, or null.
695 *
696 * @throws IOException Signals that an I/O exception has occurred.
697 */
698 public void prepareWriteEmpty(
699 IIOMetadata streamMetadata, ImageTypeSpecifier imageType,
700 int width, int height,
701 IIOMetadata imageMetadata, List<? extends BufferedImage> thumbnails,
702 ImageWriteParam param
703 ) throws IOException {
704 unsupportedOperation();
705 }
706
707 /**
708 * Prepares a stream to accept calls of writeToSequence method
709 * using the metadata object.
710 *
711 * @param streamMetadata the stream metadata.
712 *
713 * @throws IOException Signals that an I/O exception has occurred.
714 */
715 public void prepareWriteSequence(IIOMetadata streamMetadata) throws IOException {
716 unsupportedOperation();
717 }
718
719 /**
720 * Processes the completion of a thumbnail read
721 * by calling their thumbnailComplete method
722 * of registered IIOWriteProgressListeners.
723 */
724 protected void processThumbnailComplete() {
725 if (progressListeners != null) {
726 for (IIOWriteProgressListener listener : progressListeners) {
727 listener.thumbnailComplete(this);
728 }
729 }
730 }
731
732 /**
733 * Processes the current percentage of thumbnail completion
734 * by calling their thumbnailProgress method of registered
735 * IIOWriteProgressListeners.
736 *
737 * @param percentageDone the percentage done.
738 */
739 protected void processThumbnailProgress(float percentageDone) {
740 if (progressListeners != null) {
741 for (IIOWriteProgressListener listener : progressListeners) {
742 listener.thumbnailProgress(this, percentageDone);
743 }
744 }
745 }
746
747 /**
748 * Processes the start of a thumbnail read by calling
749 * thumbnailStarted method of registered IIOWriteProgressListeners.
750 *
751 * @param imageIndex the image index.
752 * @param thumbnailIndex the thumbnail index.
753 */
754 protected void processThumbnailStarted(int imageIndex, int thumbnailIndex) {
755 if (progressListeners != null) {
756 for (IIOWriteProgressListener listener : progressListeners) {
757 listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
758 }
759 }
760 }
761
762 /**
763 * Processes that the writing has been aborted by calling writeAborted
764 * method of registered IIOWriteProgressListeners.
765 */
766 protected void processWriteAborted() {
767 if (progressListeners != null) {
768 for (IIOWriteProgressListener listener : progressListeners) {
769 listener.writeAborted(this);
770 }
771 }
772 }
773
774 /**
775 * Removes the all IIOWriteProgressListener listeners.
776 */
777 public void removeAllIIOWriteProgressListeners() {
778 progressListeners = null;
779 }
780
781 /**
782 * Removes the all IIOWriteWarningListener listeners.
783 */
784 public void removeAllIIOWriteWarningListeners() {
785 warningListeners = null;
786 warningLocales = null;
787 }
788
789 /**
790 * Removes the specified IIOWriteProgressListener listener.
791 *
792 * @param listener the registered IIOWriteProgressListener
793 * to be removed.
794 */
795 public void removeIIOWriteProgressListener(IIOWriteProgressListener listener) {
796 if (progressListeners != null && listener != null) {
797 if (progressListeners.remove(listener) && progressListeners.isEmpty()) {
798 progressListeners = null;
799 }
800 }
801 }
802
803 /**
804 * Removes the specified IIOWriteWarningListener listener.
805 *
806 * @param listener the registered IIOWriteWarningListener listener
807 * to be removed.
808 */
809 public void removeIIOWriteWarningListener(IIOWriteWarningListener listener) {
810 if (warningListeners == null || listener == null) {
811 return;
812 }
813
814 int idx = warningListeners.indexOf(listener);
815 if (idx > -1) {
816 warningListeners.remove(idx);
817 warningLocales.remove(idx);
818
819 if (warningListeners.isEmpty()) {
820 warningListeners = null;
821 warningLocales = null;
822 }
823 }
824 }
825
826 /**
827 * Removes the image with the specified index from the stream.
828 *
829 * @param imageIndex the image's index.
830 *
831 * @throws IOException Signals that an I/O exception has occurred.
832 */
833 public void removeImage(int imageIndex) throws IOException {
834 unsupportedOperation();
835 }
836
837 /**
838 * Replaces image metadata of the image with specified index.
839 *
840 * @param imageIndex the image's index.
841 * @param imageMetadata the image metadata.
842 *
843 * @throws IOException Signals that an I/O exception has occurred.
844 */
845 public void replaceImageMetadata(int imageIndex, IIOMetadata imageMetadata) throws IOException {
846 unsupportedOperation();
847 }
848
849 /**
850 * Replaces a part of an image presented in the output
851 * with the specified RenderedImage.
852 *
853 * @param image the RenderedImage.
854 * @param param the ImageWriteParam.
855 *
856 * @throws IOException Signals that an I/O exception has occurred.
857 */
858 public void replacePixels(RenderedImage image, ImageWriteParam param) throws IOException {
859 unsupportedOperation();
860 }
861
862 /**
863 * Replaces a part of an image presented in the output
864 * with the specified Raster.
865 *
866 * @param raster the Raster.
867 * @param param the ImageWriteParam.
868 *
869 * @throws IOException Signals that an I/O exception has occurred.
870 */
871 public void replacePixels(Raster raster, ImageWriteParam param) throws IOException {
872 unsupportedOperation();
873 }
874
875 /**
876 * Replaces the stream metadata of the output with new IIOMetadata.
877 *
878 * @param streamMetadata the new stream metadata.
879 *
880 * @throws IOException Signals that an I/O exception has occurred.
881 */
882 public void replaceStreamMetadata(IIOMetadata streamMetadata) throws IOException {
883 unsupportedOperation();
884 }
885
886 /**
887 * Sets the locale of this ImageWriter.
888 *
889 * @param locale the new locale.
890 */
891 public void setLocale(Locale locale) {
892 if (locale == null) {
893 this.locale = null;
894 return;
895 }
896
897 Locale[] locales = getAvailableLocales();
898 boolean validLocale = false;
899 if (locales != null) {
900 for (int i = 0; i < locales.length; i++) {
901 if (locale.equals(locales[i])) {
902 validLocale = true;
903 break;
904 }
905 }
906 }
907
908 if (validLocale) {
909 this.locale = locale;
910 } else {
911 throw new IllegalArgumentException("Invalid locale!");
912 }
913 }
914
915 /**
916 * Resets this ImageWriter.
917 */
918 public void reset() {
919 setOutput(null);
920 setLocale(null);
921 removeAllIIOWriteWarningListeners();
922 removeAllIIOWriteProgressListeners();
923 clearAbortRequest();
924 }
925
926 /**
927 * Inserts image into existing output stream.
928 *
929 * @param imageIndex the image index where an image will be written.
930 * @param image the specified image to be written.
931 * @param param the ImageWriteParam, or null.
932 *
933 * @throws IOException Signals that an I/O exception has occurred.
934 */
935 public void writeInsert(int imageIndex, IIOImage image, ImageWriteParam param) throws IOException {
936 unsupportedOperation();
937 }
938
939 /**
940 * Writes the specified image to the sequence.
941 *
942 * @param image the image to be written.
943 * @param param the ImageWriteParam, or null.
944 *
945 * @throws IOException Signals that an I/O exception has occurred
946 * during writting.
947 */
948 public void writeToSequence(IIOImage image, ImageWriteParam param) throws IOException {
949 unsupportedOperation();
950 }
951}