52 |
import java.util.Iterator; |
import java.util.Iterator; |
53 |
|
|
54 |
import javax.imageio.spi.IIORegistry; |
import javax.imageio.spi.IIORegistry; |
55 |
|
import javax.imageio.spi.ImageInputStreamSpi; |
56 |
|
import javax.imageio.spi.ImageOutputStreamSpi; |
57 |
import javax.imageio.spi.ImageReaderSpi; |
import javax.imageio.spi.ImageReaderSpi; |
58 |
|
import javax.imageio.spi.ImageTranscoderSpi; |
59 |
import javax.imageio.spi.ImageWriterSpi; |
import javax.imageio.spi.ImageWriterSpi; |
60 |
import javax.imageio.spi.ServiceRegistry; |
import javax.imageio.spi.ServiceRegistry; |
61 |
import javax.imageio.stream.ImageInputStream; |
import javax.imageio.stream.ImageInputStream; |
141 |
{ |
{ |
142 |
ImageReaderSpi spi = (ImageReaderSpi) provider; |
ImageReaderSpi spi = (ImageReaderSpi) provider; |
143 |
|
|
144 |
if (spi.canDecodeInput(object)) |
try |
145 |
return true; |
{ |
146 |
|
if (spi.canDecodeInput(object)) |
147 |
|
return true; |
148 |
|
} |
149 |
|
catch (IOException ioe) |
150 |
|
{ |
151 |
|
// Apparently it couldn't... |
152 |
|
} |
153 |
} |
} |
154 |
|
|
155 |
return false; |
return false; |
267 |
private ImageReader reader; |
private ImageReader reader; |
268 |
private ImageWriter writer; |
private ImageWriter writer; |
269 |
|
|
270 |
public WriterObjectFilter(ImageReader reader, |
public TranscoderFilter(ImageReader reader, |
271 |
ImageWriter writer) |
ImageWriter writer) |
272 |
{ |
{ |
273 |
this.reader = reader; |
this.reader = reader; |
274 |
this.writer = writer; |
this.writer = writer; |
457 |
{ |
{ |
458 |
if (fileSuffix == null) |
if (fileSuffix == null) |
459 |
throw new IllegalArgumentException("formatName may not be null"); |
throw new IllegalArgumentException("formatName may not be null"); |
460 |
|
|
461 |
|
// XXX We use ReaderObjectFiler, should there be a ReaderSuffixFilter? |
462 |
return getReadersByFilter(ImageReaderSpi.class, |
return getReadersByFilter(ImageReaderSpi.class, |
463 |
new ReaderSuffixFilter(fileSuffix), |
new ReaderObjectFilter(fileSuffix), |
464 |
fileSuffix); |
fileSuffix); |
465 |
} |
} |
466 |
|
|
970 |
{ |
{ |
971 |
ImageInputStreamSpi spi = (ImageInputStreamSpi) spis.next(); |
ImageInputStreamSpi spi = (ImageInputStreamSpi) spis.next(); |
972 |
|
|
973 |
if (input instanceof spi.getInputClass()) |
if (spi.getInputClass().isAssignableFrom(input.getClass())) |
974 |
{ |
{ |
975 |
foundSpi = spi; |
foundSpi = spi; |
976 |
break; |
break; |
977 |
} |
} |
978 |
} |
} |
979 |
|
|
980 |
if (foundSpi == false) |
if (foundSpi == null) |
981 |
return null; |
return null; |
982 |
else |
else |
983 |
return foundSpi.createInputStreamInstance (input, |
return foundSpi.createInputStreamInstance (input, |
1018 |
{ |
{ |
1019 |
ImageOutputStreamSpi spi = (ImageOutputStreamSpi) spis.next(); |
ImageOutputStreamSpi spi = (ImageOutputStreamSpi) spis.next(); |
1020 |
|
|
1021 |
if (input instanceof spi.getOutputClass()) |
if (spi.getOutputClass().isAssignableFrom(output.getClass())) |
1022 |
{ |
{ |
1023 |
foundSpi = spi; |
foundSpi = spi; |
1024 |
break; |
break; |
1025 |
} |
} |
1026 |
} |
} |
1027 |
|
|
1028 |
if (foundSpi == false) |
if (foundSpi == null) |
1029 |
return null; |
return null; |
1030 |
else |
else |
1031 |
return foundSpi.createOutputStreamInstance (input, |
return foundSpi.createOutputStreamInstance (output, |
1032 |
getUseCache(), |
getUseCache(), |
1033 |
getCacheDirectory()); |
getCacheDirectory()); |
1034 |
} |
} |
1054 |
|
|
1055 |
String[] readerSpiNames = spi.getImageReaderSpiNames(); |
String[] readerSpiNames = spi.getImageReaderSpiNames(); |
1056 |
|
|
1057 |
return readerSpiNames == null ? null : readerSpiNames[0]; |
// XXX - Check this - How to map String to actual class instance? |
1058 |
|
return null; |
1059 |
|
// return readerSpiNames == null ? null : readerSpiNames[0]; |
1060 |
} |
} |
1061 |
|
|
1062 |
/** |
/** |
1073 |
throw new IllegalArgumentException ("null argument"); |
throw new IllegalArgumentException ("null argument"); |
1074 |
|
|
1075 |
return getRegistry().getServiceProviders (ImageReaderSpi.class, |
return getRegistry().getServiceProviders (ImageReaderSpi.class, |
1076 |
new ReaderObjectFilter(object), |
new ReaderObjectFilter(input), |
1077 |
true); |
true); |
1078 |
} |
} |
1079 |
|
|
1083 |
* given format. |
* given format. |
1084 |
* |
* |
1085 |
* @param type the output image's colour and sample models |
* @param type the output image's colour and sample models |
1086 |
* @param formatName the output image format |
* @param format the output image format |
1087 |
* |
* |
1088 |
* @return an iterator over a collection of image writers |
* @return an iterator over a collection of image writers |
1089 |
*/ |
*/ |
1090 |
public static Iterator getImageWriters (ImageTypeSpecifier type, |
public static Iterator getImageWriters (ImageTypeSpecifier type, |
1091 |
String formatName) |
String format) |
1092 |
{ |
{ |
1093 |
if (type == null || formatName == null) |
if (type == null || format == null) |
1094 |
throw new IllegalArgumentException ("null argument"); |
throw new IllegalArgumentException ("null argument"); |
1095 |
|
|
1096 |
return getRegistry().getServiceProviders (ImageWriterSpi.class, |
return getRegistry().getServiceProviders(ImageWriterSpi.class, |
1097 |
new WriterObjectFilter(object), |
new WriterObjectFilter(type, |
1098 |
true); |
format), |
1099 |
|
true); |
1100 |
} |
} |
1101 |
|
|
1102 |
/** |
/** |
1123 |
|
|
1124 |
String[] writerSpiNames = spi.getImageWriterSpiNames(); |
String[] writerSpiNames = spi.getImageWriterSpiNames(); |
1125 |
|
|
1126 |
return writerSpiNames == null ? null : writerSpiNames[0]; |
// XXX - Check this - How to map String to actual class instance? |
1127 |
|
return null; |
1128 |
|
// return writerSpiNames == null ? null : writerSpiNames[0]; |
1129 |
} |
} |
1130 |
|
|
1131 |
/** |
/** |
1148 |
throw new IllegalArgumentException ("null argument"); |
throw new IllegalArgumentException ("null argument"); |
1149 |
|
|
1150 |
return getRegistry().getServiceProviders (ImageTranscoderSpi.class, |
return getRegistry().getServiceProviders (ImageTranscoderSpi.class, |
1151 |
new ImageTranscoderSpi (reader, |
new TranscoderFilter (reader, |
1152 |
writer), |
writer), |
1153 |
true); |
true); |
1154 |
} |
} |
1155 |
} |
} |