harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apavle...@apache.org
Subject svn commit: r648538 - /harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java
Date Wed, 16 Apr 2008 06:07:23 GMT
Author: apavlenko
Date: Tue Apr 15 23:07:22 2008
New Revision: 648538

URL: http://svn.apache.org/viewvc?rev=648538&view=rev
Log:
Patch for HARMONY-5738: Implementation of ImageIO.getImageWritersByMIMEType and ImageIO.getImageReadersByMIMEType

Modified:
    harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java

Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java?rev=648538&r1=648537&r2=648538&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java
Tue Apr 15 23:07:22 2008
@@ -14,10 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Rustem V. Rafikov
- * @version $Revision: 1.3 $
- */
+
 package javax.imageio;
 
 import javax.imageio.stream.ImageInputStream;
@@ -146,9 +143,11 @@
         return new SpiIteratorToReadersIteratorWrapper(it);
     }
 
-    public static Iterator<ImageReader> getImageReadersByMIMEType(String MIMEType)
throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public static Iterator<ImageReader> getImageReadersByMIMEType(
+                    final String MIMEType) {
+        return new SpiIteratorToReadersIteratorWrapper(
+                registry.getServiceProviders(ImageReaderSpi.class,
+                new MIMETypeFilter(MIMEType), true));
     }
 
     public static String[] getWriterFormatNames() throws NotImplementedException {
@@ -181,9 +180,11 @@
         return new SpiIteratorToWritersIteratorWrapper(it);
     }
 
-    public static Iterator<ImageWriter> getImageWritersByMIMEType(String MIMEType)
throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public static Iterator<ImageWriter> getImageWritersByMIMEType(
+                    final String MIMEType) {
+        return new SpiIteratorToWritersIteratorWrapper(
+                registry.getServiceProviders(ImageWriterSpi.class,
+                new MIMETypeFilter(MIMEType), true));
     }
 
     public static ImageWriter getImageWriter(ImageReader reader) throws NotImplementedException
{
@@ -382,6 +383,26 @@
         public boolean filter(Object provider) {
             ImageReaderWriterSpi spi = (ImageReaderWriterSpi) provider;
             return Arrays.asList(spi.getFileSuffixes()).contains(suf);
+        }
+    }
+
+    /**
+     * Filter to match spi by MIMEType
+     */
+    static class MIMETypeFilter implements ServiceRegistry.Filter {
+        private final String mimeType;
+
+        public MIMETypeFilter(final String mimeType) {
+            if (mimeType == null) {
+                throw new NullPointerException("MIMEType cannot be NULL");
+            }
+            
+            this.mimeType = mimeType;
+        }
+
+        public boolean filter(final Object provider) {
+            final String[] types = ((ImageReaderWriterSpi) provider).getMIMETypes();
+            return (types != null) && Arrays.asList(types).contains(mimeType);
         }
     }
 



Mime
View raw message