use of javax.imageio.spi.IIORegistry in project jdk8u_jdk by JetBrains.
the class GetNumImages method main.
public static void main(String[] args) throws Exception {
IIORegistry registry = IIORegistry.getDefaultInstance();
// test ImageReader.getNumImages() for all available ImageReaders,
// with no source set
Iterator readerspis = registry.getServiceProviders(ImageReaderSpi.class, false);
while (readerspis.hasNext()) {
boolean caughtEx = false;
ImageReaderSpi readerspi = (ImageReaderSpi) readerspis.next();
ImageReader reader = readerspi.createReaderInstance();
try {
reader.getNumImages(false);
} catch (IllegalStateException ise) {
// caught exception, everything's okay
caughtEx = true;
}
if (!caughtEx) {
throw new RuntimeException("Test failed: exception was not " + "thrown for null input: " + reader);
}
}
// test ImageReader.getNumImages() for all available ImageReaders,
// with source set, seekForwardOnly and allowSearch both true
readerspis = registry.getServiceProviders(ImageReaderSpi.class, false);
while (readerspis.hasNext()) {
boolean caughtEx = false;
ImageReaderSpi readerspi = (ImageReaderSpi) readerspis.next();
ImageReader reader = readerspi.createReaderInstance();
byte[] barr = new byte[100];
ByteArrayInputStream bais = new ByteArrayInputStream(barr);
ImageInputStream iis = ImageIO.createImageInputStream(bais);
try {
reader.setInput(iis, true);
reader.getNumImages(true);
} catch (IllegalStateException ise) {
// caught exception, everything's okay
caughtEx = true;
}
if (!caughtEx) {
throw new RuntimeException("Test failed: exception was not " + "thrown when allowSearch and " + "seekForwardOnly are both true: " + reader);
}
}
}
use of javax.imageio.spi.IIORegistry in project jdk8u_jdk by JetBrains.
the class NullInputOutput method main.
public static void main(String[] args) throws Exception {
IIORegistry registry = IIORegistry.getDefaultInstance();
// test ImageReader.read() for all available ImageReaders
Iterator readerspis = registry.getServiceProviders(ImageReaderSpi.class, false);
while (readerspis.hasNext()) {
ImageReaderSpi readerspi = (ImageReaderSpi) readerspis.next();
ImageReader reader = readerspi.createReaderInstance();
try {
reader.read(0);
} catch (IllegalStateException ise) {
// caught exception, everything's okay
}
}
// test ImageWriter.write() for all available ImageWriters
BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
Iterator writerspis = registry.getServiceProviders(ImageWriterSpi.class, false);
while (writerspis.hasNext()) {
ImageWriterSpi writerspi = (ImageWriterSpi) writerspis.next();
ImageWriter writer = writerspi.createWriterInstance();
try {
writer.write(bi);
} catch (IllegalStateException ise) {
// caught exception, everything's okay
}
}
}
use of javax.imageio.spi.IIORegistry in project jdk8u_jdk by JetBrains.
the class CanWriteSequence method main.
public static void main(final String[] args) throws Exception {
final IIORegistry registry = IIORegistry.getDefaultInstance();
final Iterator<ImageWriterSpi> iter = registry.getServiceProviders(ImageWriterSpi.class, provider -> true, true);
// Validates all supported ImageWriters
while (iter.hasNext()) {
final ImageWriter writer = iter.next().createWriterInstance();
System.out.println("ImageWriter = " + writer);
test(writer);
}
System.out.println("Test passed");
}
Aggregations