Search in sources :

Example 6 with IIORegistry

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);
        }
    }
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) Iterator(java.util.Iterator) ImageReader(javax.imageio.ImageReader)

Example 7 with IIORegistry

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
        }
    }
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) Iterator(java.util.Iterator) ImageWriter(javax.imageio.ImageWriter) ImageReader(javax.imageio.ImageReader) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi) BufferedImage(java.awt.image.BufferedImage)

Example 8 with IIORegistry

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");
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ImageWriter(javax.imageio.ImageWriter) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi)

Aggregations

IIORegistry (javax.imageio.spi.IIORegistry)8 ImageReaderSpi (javax.imageio.spi.ImageReaderSpi)5 Iterator (java.util.Iterator)4 ImageWriterSpi (javax.imageio.spi.ImageWriterSpi)4 ImageWriter (javax.imageio.ImageWriter)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ImageReader (javax.imageio.ImageReader)2 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Enumeration (java.util.Enumeration)1 Hashtable (java.util.Hashtable)1 IIOMetadataFormat (javax.imageio.metadata.IIOMetadataFormat)1 ImageInputStream (javax.imageio.stream.ImageInputStream)1