Search in sources :

Example 1 with IIOMetadataFormat

use of javax.imageio.metadata.IIOMetadataFormat in project jdk8u_jdk by JetBrains.

the class UserPluginMetadataFormatTest method doTest.

public void doTest() throws IOException {
    DummyImageReaderImpl reader;
    reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());
    byte[] data = new byte[1024];
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    reader.setInput(ImageIO.createImageInputStream(bais));
    IIOMetadata metadata = reader.getImageMetadata(1);
    if (metadata == null) {
        throw new RuntimeException("IIOMetada is NULL");
    }
    String[] formatNames = metadata.getMetadataFormatNames();
    for (int j = 0; j < formatNames.length; j++) {
        String formatName = formatNames[j];
        System.out.println("\nFormat Names : " + formatName);
        try {
            IIOMetadataFormat metadataFormat = metadata.getMetadataFormat(formatName);
            System.out.println("  Class Name " + metadataFormat.getClass());
        } catch (IllegalStateException ise) {
            Throwable t = ise;
            t.printStackTrace();
            while (t.getCause() != null) {
                t = t.getCause();
                t.printStackTrace();
            }
            // test failed!
            // stop applet!
            System.out.println("Test faied.");
            throw new RuntimeException("Test failed.", ise);
        }
    }
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) IIOMetadataFormat(javax.imageio.metadata.IIOMetadataFormat) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 2 with IIOMetadataFormat

use of javax.imageio.metadata.IIOMetadataFormat in project jdk8u_jdk by JetBrains.

the class MetadataFormatPrinter method main.

public static void main(String[] args) {
    IIOMetadataFormat format = null;
    if (args.length == 0 || args[0].equals("javax_imageio_1.0")) {
        format = IIOMetadataFormatImpl.getStandardFormatInstance();
    } else {
        IIORegistry registry = IIORegistry.getDefaultInstance();
        Iterator iter = registry.getServiceProviders(ImageReaderSpi.class, false);
        while (iter.hasNext()) {
            ImageReaderSpi spi = (ImageReaderSpi) iter.next();
            if (args[0].equals(spi.getNativeStreamMetadataFormatName())) {
                System.out.print(spi.getDescription(null));
                System.out.println(": native stream format");
                format = spi.getStreamMetadataFormat(args[0]);
                break;
            }
            String[] extraStreamFormatNames = spi.getExtraStreamMetadataFormatNames();
            if (extraStreamFormatNames != null && Arrays.asList(extraStreamFormatNames).contains(args[0])) {
                System.out.print(spi.getDescription(null));
                System.out.println(": extra stream format");
                format = spi.getStreamMetadataFormat(args[0]);
                break;
            }
            if (args[0].equals(spi.getNativeImageMetadataFormatName())) {
                System.out.print(spi.getDescription(null));
                System.out.println(": native image format");
                format = spi.getImageMetadataFormat(args[0]);
                break;
            }
            String[] extraImageFormatNames = spi.getExtraImageMetadataFormatNames();
            if (extraImageFormatNames != null && Arrays.asList(extraImageFormatNames).contains(args[0])) {
                System.out.print(spi.getDescription(null));
                System.out.println(": extra image format");
                format = spi.getImageMetadataFormat(args[0]);
                break;
            }
        }
    }
    if (format == null) {
        System.err.println("Unknown format: " + args[0]);
        System.exit(0);
    }
    MetadataFormatPrinter printer = new MetadataFormatPrinter(System.out);
    printer.print(format);
}
Also used : IIOMetadataFormat(javax.imageio.metadata.IIOMetadataFormat) IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) Iterator(java.util.Iterator)

Example 3 with IIOMetadataFormat

use of javax.imageio.metadata.IIOMetadataFormat in project jdk8u_jdk by JetBrains.

the class ImageReaderWriterSpi method getMetadataFormat.

private IIOMetadataFormat getMetadataFormat(String formatName, boolean supportsStandard, String nativeName, String nativeClassName, String[] extraNames, String[] extraClassNames) {
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }
    if (supportsStandard && formatName.equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
        return IIOMetadataFormatImpl.getStandardFormatInstance();
    }
    String formatClassName = null;
    if (formatName.equals(nativeName)) {
        formatClassName = nativeClassName;
    } else if (extraNames != null) {
        for (int i = 0; i < extraNames.length; i++) {
            if (formatName.equals(extraNames[i])) {
                formatClassName = extraClassNames[i];
                // out of for
                break;
            }
        }
    }
    if (formatClassName == null) {
        throw new IllegalArgumentException("Unsupported format name");
    }
    try {
        Class cls = Class.forName(formatClassName, true, ClassLoader.getSystemClassLoader());
        Method meth = cls.getMethod("getInstance");
        return (IIOMetadataFormat) meth.invoke(null);
    } catch (Exception e) {
        RuntimeException ex = new IllegalStateException("Can't obtain format");
        ex.initCause(e);
        throw ex;
    }
}
Also used : IIOMetadataFormat(javax.imageio.metadata.IIOMetadataFormat) Method(java.lang.reflect.Method) IOException(java.io.IOException)

Aggregations

IIOMetadataFormat (javax.imageio.metadata.IIOMetadataFormat)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 IIOMetadata (javax.imageio.metadata.IIOMetadata)1 IIORegistry (javax.imageio.spi.IIORegistry)1 ImageReaderSpi (javax.imageio.spi.ImageReaderSpi)1