diff options
Diffstat (limited to 'libjava/classpath/javax/imageio/ImageIO.java')
-rw-r--r-- | libjava/classpath/javax/imageio/ImageIO.java | 128 |
1 files changed, 85 insertions, 43 deletions
diff --git a/libjava/classpath/javax/imageio/ImageIO.java b/libjava/classpath/javax/imageio/ImageIO.java index b2304a78304..a3d967726b9 100644 --- a/libjava/classpath/javax/imageio/ImageIO.java +++ b/libjava/classpath/javax/imageio/ImageIO.java @@ -315,27 +315,37 @@ public final class ImageIO } } - private static final class ImageReaderIterator implements Iterator + private static final class ImageReaderIterator + implements Iterator<ImageReader> { - Iterator it; + Iterator<ImageReaderSpi> it; Object readerExtension; - public ImageReaderIterator(Iterator it, Object readerExtension) + public ImageReaderIterator(Iterator<ImageReaderSpi> it, + Object readerExtension) { this.it = it; this.readerExtension = readerExtension; } + + public ImageReaderIterator(Iterator<ImageReaderSpi> it) + { + this.it = it; + } public boolean hasNext() { return it.hasNext(); } - public Object next() + public ImageReader next() { try { - return ((ImageReaderSpi) it.next()).createReaderInstance(readerExtension); + ImageReaderSpi spi = it.next(); + return (readerExtension == null + ? spi.createReaderInstance() + : spi.createReaderInstance(readerExtension)); } catch (IOException e) { @@ -349,27 +359,37 @@ public final class ImageIO } } - private static final class ImageWriterIterator implements Iterator + private static final class ImageWriterIterator + implements Iterator<ImageWriter> { - Iterator it; + Iterator<ImageWriterSpi> it; Object writerExtension; - public ImageWriterIterator(Iterator it, Object writerExtension) + public ImageWriterIterator(Iterator<ImageWriterSpi> it, + Object writerExtension) { this.it = it; this.writerExtension = writerExtension; } + + public ImageWriterIterator(Iterator<ImageWriterSpi> it) + { + this.it = it; + } public boolean hasNext() { return it.hasNext(); } - public Object next() + public ImageWriter next() { try { - return ((ImageWriterSpi) it.next()).createWriterInstance(writerExtension); + ImageWriterSpi spi = it.next(); + return (writerExtension == null + ? spi.createWriterInstance() + : spi.createWriterInstance(writerExtension)); } catch (IOException e) { @@ -386,13 +406,14 @@ public final class ImageIO private static File cacheDirectory; private static boolean useCache = true; - private static Iterator getReadersByFilter(Class type, - ServiceRegistry.Filter filter, - Object readerExtension) + private static Iterator<ImageReader> getReadersByFilter(Class<ImageReaderSpi> type, + ServiceRegistry.Filter filter, + Object readerExtension) { try { - Iterator it = getRegistry().getServiceProviders(type, filter, true); + Iterator<ImageReaderSpi> it + = getRegistry().getServiceProviders(type, filter, true); return new ImageReaderIterator(it, readerExtension); } catch (IllegalArgumentException e) @@ -401,13 +422,14 @@ public final class ImageIO } } - private static Iterator getWritersByFilter(Class type, - ServiceRegistry.Filter filter, - Object writerExtension) + private static Iterator<ImageWriter> getWritersByFilter(Class<ImageWriterSpi> type, + ServiceRegistry.Filter filter, + Object writerExtension) { try { - Iterator it = getRegistry().getServiceProviders(type, filter, true); + Iterator<ImageWriterSpi> it + = getRegistry().getServiceProviders(type, filter, true); return new ImageWriterIterator(it, writerExtension); } catch (IllegalArgumentException e) @@ -436,7 +458,7 @@ public final class ImageIO * * @exception IllegalArgumentException if formatName is null */ - public static Iterator getImageReadersByFormatName(String formatName) + public static Iterator<ImageReader> getImageReadersByFormatName(String formatName) { if (formatName == null) throw new IllegalArgumentException("formatName may not be null"); @@ -457,7 +479,7 @@ public final class ImageIO * * @exception IllegalArgumentException if MIMEType is null */ - public static Iterator getImageReadersByMIMEType(String MIMEType) + public static Iterator<ImageReader> getImageReadersByMIMEType(String MIMEType) { if (MIMEType == null) throw new IllegalArgumentException("MIMEType may not be null"); @@ -477,7 +499,7 @@ public final class ImageIO * * @exception IllegalArgumentException if fileSuffix is null */ - public static Iterator getImageReadersBySuffix(String fileSuffix) + public static Iterator<ImageReader> getImageReadersBySuffix(String fileSuffix) { if (fileSuffix == null) throw new IllegalArgumentException("formatName may not be null"); @@ -497,7 +519,7 @@ public final class ImageIO * * @exception IllegalArgumentException if formatName is null */ - public static Iterator getImageWritersByFormatName(String formatName) + public static Iterator<ImageWriter> getImageWritersByFormatName(String formatName) { if (formatName == null) throw new IllegalArgumentException("formatName may not be null"); @@ -518,7 +540,7 @@ public final class ImageIO * * @exception IllegalArgumentException if MIMEType is null */ - public static Iterator getImageWritersByMIMEType(String MIMEType) + public static Iterator<ImageWriter> getImageWritersByMIMEType(String MIMEType) { if (MIMEType == null) throw new IllegalArgumentException("MIMEType may not be null"); @@ -538,7 +560,7 @@ public final class ImageIO * * @exception IllegalArgumentException if fileSuffix is null */ - public static Iterator getImageWritersBySuffix(String fileSuffix) + public static Iterator<ImageWriter> getImageWritersBySuffix(String fileSuffix) { if (fileSuffix == null) throw new IllegalArgumentException("fileSuffix may not be null"); @@ -1068,8 +1090,7 @@ public final class ImageIO if (writer == null) throw new IllegalArgumentException ("null argument"); - ImageWriterSpi spi = (ImageWriterSpi) getRegistry() - .getServiceProviderByClass(writer.getClass()); + ImageWriterSpi spi = writer.getOriginatingProvider(); String[] readerSpiNames = spi.getImageReaderSpiNames(); @@ -1098,14 +1119,16 @@ public final class ImageIO * * @return an iterator over a collection of image readers */ - public static Iterator getImageReaders (Object input) + public static Iterator<ImageReader> getImageReaders (Object input) { if (input == null) throw new IllegalArgumentException ("null argument"); - return getRegistry().getServiceProviders (ImageReaderSpi.class, - new ReaderObjectFilter(input), - true); + Iterator<ImageReaderSpi> spiIterator + = getRegistry().getServiceProviders (ImageReaderSpi.class, + new ReaderObjectFilter(input), + true); + return new ImageReaderIterator(spiIterator); } /** @@ -1118,16 +1141,18 @@ public final class ImageIO * * @return an iterator over a collection of image writers */ - public static Iterator getImageWriters (ImageTypeSpecifier type, + public static Iterator<ImageWriter> getImageWriters (ImageTypeSpecifier type, String formatName) { if (type == null || formatName == null) throw new IllegalArgumentException ("null argument"); - return getRegistry().getServiceProviders (ImageWriterSpi.class, - new WriterObjectFilter(type, - formatName), - true); + final Iterator<ImageWriterSpi> spiIterator + = getRegistry().getServiceProviders (ImageWriterSpi.class, + new WriterObjectFilter(type, + formatName), + true); + return new ImageWriterIterator(spiIterator); } /** @@ -1149,8 +1174,7 @@ public final class ImageIO if (reader == null) throw new IllegalArgumentException ("null argument"); - ImageReaderSpi spi = (ImageReaderSpi) getRegistry() - .getServiceProviderByClass(reader.getClass()); + ImageReaderSpi spi = reader.getOriginatingProvider(); String[] writerSpiNames = spi.getImageWriterSpiNames(); @@ -1184,15 +1208,33 @@ public final class ImageIO * @exception IllegalArgumentException if either reader or writer is * null */ - public static Iterator getImageTranscoders (ImageReader reader, - ImageWriter writer) + public static Iterator<ImageTranscoder> getImageTranscoders (ImageReader reader, + ImageWriter writer) { if (reader == null || writer == null) throw new IllegalArgumentException ("null argument"); - return getRegistry().getServiceProviders (ImageTranscoderSpi.class, - new TranscoderFilter (reader, - writer), - true); + final Iterator<ImageTranscoderSpi> spiIterator + = getRegistry().getServiceProviders (ImageTranscoderSpi.class, + new TranscoderFilter (reader, + writer), + true); + return new Iterator<ImageTranscoder>() + { + public boolean hasNext() + { + return spiIterator.hasNext(); + } + + public ImageTranscoder next() + { + return spiIterator.next().createTranscoderInstance(); + } + + public void remove() + { + throw new UnsupportedOperationException(); + } + }; } } |