diff options
author | Thomas Fitzsimmons <fitzsim@redhat.com> | 2005-10-02 15:56:46 +0000 |
---|---|---|
committer | Thomas Fitzsimmons <fitzsim@redhat.com> | 2005-10-02 15:56:46 +0000 |
commit | 61e82a839a0195d6878f26f82e55ac1d414cc802 (patch) | |
tree | 0fd1cb9cc94ace7082efccbd89bcf3d4602ee3e3 /javax/imageio/ImageIO.java | |
parent | 619e8768182806097f104f34862ec62fd11f52f2 (diff) | |
download | classpath-61e82a839a0195d6878f26f82e55ac1d414cc802.tar.gz |
2005-10-02 Thomas Fitzsimmons <fitzsim@redhat.com>
* javax/imageio/ImageIO.java: Fix compilation problems.
Diffstat (limited to 'javax/imageio/ImageIO.java')
-rw-r--r-- | javax/imageio/ImageIO.java | 127 |
1 files changed, 85 insertions, 42 deletions
diff --git a/javax/imageio/ImageIO.java b/javax/imageio/ImageIO.java index b5e5dab68..3ea7e8585 100644 --- a/javax/imageio/ImageIO.java +++ b/javax/imageio/ImageIO.java @@ -141,21 +141,45 @@ public final class ImageIO { ImageReaderSpi spi = (ImageReaderSpi) provider; - try - { - if (spi.canDecodeInput(object)) - return true; - } - catch (IOException ioe) - { - // Apparently it couldn't... - } + try + { + if (spi.canDecodeInput(object)) + return true; + } + catch (IOException e) + { + // Return false in this case + } } - return false; } } + private static final class ReaderSuffixFilter implements ServiceRegistry.Filter + { + private String fileSuffix; + + public ReaderSuffixFilter(String fileSuffix) + { + this.fileSuffix = fileSuffix; + } + + public boolean filter(Object provider) + { + if (provider instanceof ImageReaderSpi) + { + ImageReaderSpi spi = (ImageReaderSpi) provider; + String[] suffixes = spi.getFileSuffixes(); + + for (int i = suffixes.length - 1; i >= 0; --i) + if (fileSuffix.equals(suffixes[i])) + return true; + } + + return false; + } + } + private static final class WriterFormatFilter implements ServiceRegistry.Filter { private String formatName; @@ -268,7 +292,7 @@ public final class ImageIO private ImageWriter writer; public TranscoderFilter(ImageReader reader, - ImageWriter writer) + ImageWriter writer) { this.reader = reader; this.writer = writer; @@ -457,10 +481,9 @@ public final class ImageIO { if (fileSuffix == null) throw new IllegalArgumentException("formatName may not be null"); - - // XXX We use ReaderObjectFiler, should there be a ReaderSuffixFilter? + return getReadersByFilter(ImageReaderSpi.class, - new ReaderObjectFilter(fileSuffix), + new ReaderSuffixFilter(fileSuffix), fileSuffix); } @@ -970,19 +993,17 @@ public final class ImageIO { ImageInputStreamSpi spi = (ImageInputStreamSpi) spis.next(); - if (spi.getInputClass().isAssignableFrom(input.getClass())) + if (input.getClass().equals(spi.getInputClass())) { foundSpi = spi; break; } } - if (foundSpi == null) - return null; - else - return foundSpi.createInputStreamInstance (input, - getUseCache(), - getCacheDirectory()); + return foundSpi == null ? null : + foundSpi.createInputStreamInstance (input, + getUseCache(), + getCacheDirectory()); } /** @@ -1018,19 +1039,17 @@ public final class ImageIO { ImageOutputStreamSpi spi = (ImageOutputStreamSpi) spis.next(); - if (spi.getOutputClass().isAssignableFrom(output.getClass())) + if (output.getClass().equals(spi.getOutputClass())) { foundSpi = spi; break; } } - if (foundSpi == null) - return null; - else - return foundSpi.createOutputStreamInstance (output, - getUseCache(), - getCacheDirectory()); + return foundSpi == null ? null : + foundSpi.createOutputStreamInstance (output, + getUseCache(), + getCacheDirectory()); } /** @@ -1054,9 +1073,21 @@ public final class ImageIO String[] readerSpiNames = spi.getImageReaderSpiNames(); - // XXX - Check this - How to map String to actual class instance? - return null; - // return readerSpiNames == null ? null : readerSpiNames[0]; + ImageReader r = null; + + if (readerSpiNames != null) + { + try + { + Class readerClass = Class.forName (readerSpiNames[0]); + r = (ImageReader) readerClass.newInstance (); + } + catch (Exception e) + { + return null; + } + } + return r; } /** @@ -1083,20 +1114,20 @@ public final class ImageIO * given format. * * @param type the output image's colour and sample models - * @param format the output image format + * @param formatName the output image format * * @return an iterator over a collection of image writers */ public static Iterator getImageWriters (ImageTypeSpecifier type, - String format) + String formatName) { - if (type == null || format == null) + if (type == null || formatName == null) throw new IllegalArgumentException ("null argument"); - return getRegistry().getServiceProviders(ImageWriterSpi.class, - new WriterObjectFilter(type, - format), - true); + return getRegistry().getServiceProviders (ImageWriterSpi.class, + new WriterObjectFilter(type, + formatName), + true); } /** @@ -1123,9 +1154,21 @@ public final class ImageIO String[] writerSpiNames = spi.getImageWriterSpiNames(); - // XXX - Check this - How to map String to actual class instance? - return null; - // return writerSpiNames == null ? null : writerSpiNames[0]; + ImageWriter w = null; + + if (writerSpiNames != null) + { + try + { + Class writerClass = Class.forName (writerSpiNames[0]); + w = (ImageWriter) writerClass.newInstance (); + } + catch (Exception e) + { + return null; + } + } + return w; } /** @@ -1149,7 +1192,7 @@ public final class ImageIO return getRegistry().getServiceProviders (ImageTranscoderSpi.class, new TranscoderFilter (reader, - writer), + writer), true); } } |