Coverage Report - net.sourceforge.jeuclid.converter.ImageIODetector
 
Classes in this File Line Coverage Branch Coverage Complexity
ImageIODetector
100%
18/18
80%
8/10
3,5
 
 1  
 /*
 2  
  * Copyright 2007 - 2007 JEuclid, http://jeuclid.sf.net
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 /* $Id: ImageIODetector.java,v 584e9b40f728 2009/04/09 07:41:44 maxberger $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.converter;
 20  
 
 21  
 import java.util.Iterator;
 22  
 import java.util.Set;
 23  
 import java.util.TreeSet;
 24  
 
 25  
 import javax.imageio.ImageIO;
 26  
 import javax.imageio.ImageWriter;
 27  
 
 28  
 /**
 29  
  * Detects and registers the Converters from ImageIO.
 30  
  * 
 31  
  * @version $Revision: 584e9b40f728 $
 32  
  */
 33  
 public final class ImageIODetector implements ConverterDetector {
 34  
 
 35  
     /**
 36  
      * Default constructor.
 37  
      */
 38  209
     public ImageIODetector() {
 39  
         // Empty on purpose
 40  209
     }
 41  
 
 42  
     /**
 43  
      * Detects and registers all converters available through ImageIO.
 44  
      * 
 45  
      * @param registry
 46  
      *            ConverterRegistry to use.
 47  
      */
 48  
     public void detectConversionPlugins(final ConverterRegistry registry) {
 49  
 
 50  209
         final String[] mimeTypes = ImageIO.getWriterMIMETypes();
 51  
 
 52  209
         final Set<String> noAlphaMimeTypes = new TreeSet<String>();
 53  209
         noAlphaMimeTypes.add("image/jpeg");
 54  209
         noAlphaMimeTypes.add("image/bmp");
 55  
 
 56  2090
         for (final String mimeType : mimeTypes) {
 57  1881
             final Iterator<ImageWriter> iwit = ImageIO
 58  
                     .getImageWritersByMIMEType(mimeType);
 59  1881
             if (iwit != null) {
 60  3971
                 while (iwit.hasNext()) {
 61  2090
                     final ImageWriter iw = iwit.next();
 62  2090
                     final String[] suffixes = iw.getOriginatingProvider()
 63  
                             .getFileSuffixes();
 64  2090
                     if (suffixes != null) {
 65  4389
                         for (final String suffix : suffixes) {
 66  2299
                             registry.registerMimeTypeAndSuffix(mimeType,
 67  
                                     suffix, false);
 68  
                         }
 69  
                     }
 70  2090
                     registry.registerConverter(mimeType,
 71  
                             new ImageIOConverter(iw, noAlphaMimeTypes
 72  
                                     .contains(mimeType)), false);
 73  2090
                 }
 74  
 
 75  
             }
 76  
 
 77  
         }
 78  
 
 79  209
     }
 80  
 }