2037 lines · 82.1 KB · Java
RawDownload
     * with a portion of the given <code>Raster</code>.  The image     * data must match, or be convertible to, the image layout of the     * existing image.     *     * <p> An <code>ImageWriteParam</code> may optionally be supplied     * to control the writing process.  If <code>param</code> is     * <code>null</code>, a default write param will be used.     *     * <p> The destination region is specified in the     * <code>param</code> argument, and will be clipped to the image     * boundaries and the region supplied to     * <code>prepareReplacePixels</code>.  At least one pixel of the     * source must not be clipped, or an exception is thrown.     *     * <p> If the supplied <code>ImageWriteParam</code> contains     * optional setting values not supported by this writer (<i>e.g.</i>     * progressive encoding or any format-specific settings), they     * will be ignored.     *     * <p> This method may only be called after a call to     * <code>prepareReplacePixels</code>, or else an     * <code>IllegalStateException</code> will be thrown.     *     * <p> The default implementation throws an     * <code>IllegalStateException</code> if the output is     * <code>null</code>, and otherwise throws an     * <code>UnsupportedOperationException</code>.     *     * @param raster a <code>Raster</code> containing source     * pixels.     * @param param an <code>ImageWriteParam</code>, or     * <code>null</code> to use a default     * <code>ImageWriteParam</code>.     *     * @exception IllegalStateException if the output has not     * been set.     * @exception UnsupportedOperationException if     * <code>canReplacePixels(imageIndex)</code> returns     * <code>false</code>.     * @exception IllegalStateException if there is no previous call to     * <code>prepareReplacePixels</code> without a matching call to     * <code>endReplacePixels</code>.     * @exception UnsupportedOperationException if     * <code>canWriteRasters</code> returns <code>false</code>.     * @exception IllegalArgumentException if any of the following are true:     * <ul>     * <li> <code>raster</code> is <code>null</code>.     * <li> <code>param</code> is <code>null</code>.     * <li> the intersected region does not contain at least one pixel.     * <li> the layout of <code>raster</code> does not match, or this     * writer cannot convert it to, the existing image layout.     * </ul>     * @exception IOException if an I/O error occurs during writing.     */    public void replacePixels(Raster raster, ImageWriteParam param)        throws IOException {        unsupported();    }     /**     * Terminates a sequence of calls to <code>replacePixels</code>.     *     * <p> If <code>canReplacePixels</code> returns     * <code>false</code>, and     * <code>UnsupportedOperationException</code> will be thrown.     *     * <p> The default implementation throws an     * <code>IllegalStateException</code> if the output is     * <code>null</code>, and otherwise throws an     * <code>UnsupportedOperationException</code>.     *     * @exception IllegalStateException if the output has not     * been set.     * @exception UnsupportedOperationException if     * <code>canReplacePixels(imageIndex)</code> returns     * <code>false</code>.     * @exception IllegalStateException if there is no previous call     * to <code>prepareReplacePixels</code> without a matching call to     * <code>endReplacePixels</code>.     * @exception IOException if an I/O error occurs during writing.     */    public void endReplacePixels() throws IOException {        unsupported();    }     // Abort     /**     * Requests that any current write operation be aborted.  The     * contents of the output following the abort will be undefined.     *     * <p> Writers should call <code>clearAbortRequest</code> at the     * beginning of each write operation, and poll the value of     * <code>abortRequested</code> regularly during the write.     */    public synchronized void abort() {        this.abortFlag = true;    }     /**     * Returns <code>true</code> if a request to abort the current     * write operation has been made since the writer was instantiated or     * <code>clearAbortRequest</code> was called.     *     * @return <code>true</code> if the current write operation should     * be aborted.     *     * @see #abort     * @see #clearAbortRequest     */    protected synchronized boolean abortRequested() {        return this.abortFlag;    }     /**     * Clears any previous abort request.  After this method has been     * called, <code>abortRequested</code> will return     * <code>false</code>.     *     * @see #abort     * @see #abortRequested     */    protected synchronized void clearAbortRequest() {        this.abortFlag = false;    }     // Listeners     /**     * Adds an <code>IIOWriteWarningListener</code> to the list of     * registered warning listeners.  If <code>listener</code> is     * <code>null</code>, no exception will be thrown and no action     * will be taken.  Messages sent to the given listener will be     * localized, if possible, to match the current     * <code>Locale</code>.  If no <code>Locale</code> has been set,     * warning messages may be localized as the writer sees fit.     *     * @param listener an <code>IIOWriteWarningListener</code> to be     * registered.     *     * @see #removeIIOWriteWarningListener     */    public void addIIOWriteWarningListener(IIOWriteWarningListener listener) {        if (listener == null) {            return;        }        warningListeners = ImageReader.addToList(warningListeners, listener);        warningLocales = ImageReader.addToList(warningLocales, getLocale());    }     /**     * Removes an <code>IIOWriteWarningListener</code> from the list     * of registered warning listeners.  If the listener was not     * previously registered, or if <code>listener</code> is     * <code>null</code>, no exception will be thrown and no action     * will be taken.     *     * @param listener an <code>IIOWriteWarningListener</code> to be     * deregistered.     *     * @see #addIIOWriteWarningListener     */    public        void removeIIOWriteWarningListener(IIOWriteWarningListener listener) {        if (listener == null || warningListeners == null) {            return;        }        int index = warningListeners.indexOf(listener);        if (index != -1) {            warningListeners.remove(index);            warningLocales.remove(index);            if (warningListeners.size() == 0) {                warningListeners = null;                warningLocales = null;            }        }    }     /**     * Removes all currently registered     * <code>IIOWriteWarningListener</code> objects.     *     * <p> The default implementation sets the     * <code>warningListeners</code> and <code>warningLocales</code>     * instance variables to <code>null</code>.     */    public void removeAllIIOWriteWarningListeners() {        this.warningListeners = null;        this.warningLocales = null;    }     /**     * Adds an <code>IIOWriteProgressListener</code> to the list of     * registered progress listeners.  If <code>listener</code> is     * <code>null</code>, no exception will be thrown and no action     * will be taken.     *     * @param listener an <code>IIOWriteProgressListener</code> to be     * registered.     *     * @see #removeIIOWriteProgressListener     */    public void        addIIOWriteProgressListener(IIOWriteProgressListener listener) {        if (listener == null) {            return;        }        progressListeners = ImageReader.addToList(progressListeners, listener);    }     /**     * Removes an <code>IIOWriteProgressListener</code> from the list     * of registered progress listeners.  If the listener was not     * previously registered, or if <code>listener</code> is     * <code>null</code>, no exception will be thrown and no action     * will be taken.     *     * @param listener an <code>IIOWriteProgressListener</code> to be     * deregistered.     *     * @see #addIIOWriteProgressListener     */    public void        removeIIOWriteProgressListener(IIOWriteProgressListener listener) {        if (listener == null || progressListeners == null) {            return;        }        progressListeners =            ImageReader.removeFromList(progressListeners, listener);    }     /**     * Removes all currently registered     * <code>IIOWriteProgressListener</code> objects.     *     * <p> The default implementation sets the     * <code>progressListeners</code> instance variable to     * <code>null</code>.     */    public void removeAllIIOWriteProgressListeners() {        this.progressListeners = null;    }     /**     * Broadcasts the start of an image write to all registered     * <code>IIOWriteProgressListener</code>s by calling their     * <code>imageStarted</code> method.  Subclasses may use this     * method as a convenience.     *     * @param imageIndex the index of the image about to be written.     */    protected void processImageStarted(int imageIndex) {        if (progressListeners == null) {            return;        }        int numListeners = progressListeners.size();        for (int i = 0; i < numListeners; i++) {            IIOWriteProgressListener listener =                (IIOWriteProgressListener)progressListeners.get(i);            listener.imageStarted(this, imageIndex);        }    }     /**     * Broadcasts the current percentage of image completion to all     * registered <code>IIOWriteProgressListener</code>s by calling     * their <code>imageProgress</code> method.  Subclasses may use     * this method as a convenience.     *     * @param percentageDone the current percentage of completion,     * as a <code>float</code>.     */    protected void processImageProgress(float percentageDone) {        if (progressListeners == null) {            return;        }        int numListeners = progressListeners.size();        for (int i = 0; i < numListeners; i++) {            IIOWriteProgressListener listener =                (IIOWriteProgressListener)progressListeners.get(i);            listener.imageProgress(this, percentageDone);        }    }     /**     * Broadcasts the completion of an image write to all registered     * <code>IIOWriteProgressListener</code>s by calling their     * <code>imageComplete</code> method.  Subclasses may use this     * method as a convenience.     */    protected void processImageComplete() {        if (progressListeners == null) {            return;        }        int numListeners = progressListeners.size();        for (int i = 0; i < numListeners; i++) {            IIOWriteProgressListener listener =                (IIOWriteProgressListener)progressListeners.get(i);            listener.imageComplete(this);        }    }     /**     * Broadcasts the start of a thumbnail write to all registered     * <code>IIOWriteProgressListener</code>s by calling their     * <code>thumbnailStarted</code> method.  Subclasses may use this     * method as a convenience.     *     * @param imageIndex the index of the image associated with the     * thumbnail.     * @param thumbnailIndex the index of the thumbnail.     */    protected void processThumbnailStarted(int imageIndex,                                           int thumbnailIndex) {        if (progressListeners == null) {            return;        }        int numListeners = progressListeners.size();        for (int i = 0; i < numListeners; i++) {            IIOWriteProgressListener listener =                (IIOWriteProgressListener)progressListeners.get(i);            listener.thumbnailStarted(this, imageIndex, thumbnailIndex);        }    }     /**     * Broadcasts the current percentage of thumbnail completion to     * all registered <code>IIOWriteProgressListener</code>s by calling     * their <code>thumbnailProgress</code> method.  Subclasses may     * use this method as a convenience.     *     * @param percentageDone the current percentage of completion,     * as a <code>float</code>.     */    protected void processThumbnailProgress(float percentageDone) {        if (progressListeners == null) {            return;        }        int numListeners = progressListeners.size();        for (int i = 0; i < numListeners; i++) {            IIOWriteProgressListener listener =                (IIOWriteProgressListener)progressListeners.get(i);            listener.thumbnailProgress(this, percentageDone);        }    }     /**     * Broadcasts the completion of a thumbnail write to all registered     * <code>IIOWriteProgressListener</code>s by calling their     * <code>thumbnailComplete</code> method.  Subclasses may use this     * method as a convenience.     */    protected void processThumbnailComplete() {        if (progressListeners == null) {            return;        }        int numListeners = progressListeners.size();        for (int i = 0; i < numListeners; i++) {            IIOWriteProgressListener listener =                (IIOWriteProgressListener)progressListeners.get(i);            listener.thumbnailComplete(this);        }    }     /**     * Broadcasts that the write has been aborted to all registered     * <code>IIOWriteProgressListener</code>s by calling their     * <code>writeAborted</code> method.  Subclasses may use this     * method as a convenience.     */    protected void processWriteAborted() {        if (progressListeners == null) {            return;        }        int numListeners = progressListeners.size();        for (int i = 0; i < numListeners; i++) {            IIOWriteProgressListener listener =                (IIOWriteProgressListener)progressListeners.get(i);            listener.writeAborted(this);        }    }     /**     * Broadcasts a warning message to all registered     * <code>IIOWriteWarningListener</code>s by calling their     * <code>warningOccurred</code> method.  Subclasses may use this     * method as a convenience.     *     * @param imageIndex the index of the image on which the warning     * occurred.     * @param warning the warning message.     *     * @exception IllegalArgumentException if <code>warning</code>     * is <code>null</code>.     */    protected void processWarningOccurred(int imageIndex,                                          String warning) {        if (warningListeners == null) {            return;        }        if (warning == null) {            throw new IllegalArgumentException("warning == null!");        }        int numListeners = warningListeners.size();        for (int i = 0; i < numListeners; i++) {            IIOWriteWarningListener listener =                (IIOWriteWarningListener)warningListeners.get(i);             listener.warningOccurred(this, imageIndex, warning);        }    }     /**     * Broadcasts a localized warning message to all registered     * <code>IIOWriteWarningListener</code>s by calling their     * <code>warningOccurred</code> method with a string taken     * from a <code>ResourceBundle</code>.  Subclasses may use this     * method as a convenience.     *     * @param imageIndex the index of the image on which the warning     * occurred.     * @param baseName the base name of a set of     * <code>ResourceBundle</code>s containing localized warning     * messages.     * @param keyword the keyword used to index the warning message     * within the set of <code>ResourceBundle</code>s.     *     * @exception IllegalArgumentException if <code>baseName</code>     * is <code>null</code>.     * @exception IllegalArgumentException if <code>keyword</code>     * is <code>null</code>.     * @exception IllegalArgumentException if no appropriate     * <code>ResourceBundle</code> may be located.     * @exception IllegalArgumentException if the named resource is     * not found in the located <code>ResourceBundle</code>.     * @exception IllegalArgumentException if the object retrieved     * from the <code>ResourceBundle</code> is not a     * <code>String</code>.     */    protected void processWarningOccurred(int imageIndex,                                          String baseName,                                          String keyword) {        if (warningListeners == null) {            return;        }        if (baseName == null) {            throw new IllegalArgumentException("baseName == null!");        }        if (keyword == null) {            throw new IllegalArgumentException("keyword == null!");        }        int numListeners = warningListeners.size();        for (int i = 0; i < numListeners; i++) {            IIOWriteWarningListener listener =                (IIOWriteWarningListener)warningListeners.get(i);            Locale locale = (Locale)warningLocales.get(i);            if (locale == null) {                locale = Locale.getDefault();            }             /**             * If an applet supplies an implementation of ImageWriter and             * resource bundles, then the resource bundle will need to be             * accessed via the applet class loader. So first try the context             * class loader to locate the resource bundle.             * If that throws MissingResourceException, then try the             * system class loader.             */            ClassLoader loader = (ClassLoader)                java.security.AccessController.doPrivileged(                   new java.security.PrivilegedAction() {                      public Object run() {                        return Thread.currentThread().getContextClassLoader();                      }                });             ResourceBundle bundle = null;            try {                bundle = ResourceBundle.getBundle(baseName, locale, loader);            } catch (MissingResourceException mre) {                try {                    bundle = ResourceBundle.getBundle(baseName, locale);                } catch (MissingResourceException mre1) {                    throw new IllegalArgumentException("Bundle not found!");                }            }             String warning = null;            try {                warning = bundle.getString(keyword);            } catch (ClassCastException cce) {                throw new IllegalArgumentException("Resource is not a String!");            } catch (MissingResourceException mre) {                throw new IllegalArgumentException("Resource is missing!");            }             listener.warningOccurred(this, imageIndex, warning);        }    } 

Lines 1501–2000 of 2037. Previous lines