javax.imageio.metadata.IIOMetadataFormat Java Examples

The following examples show how to use javax.imageio.metadata.IIOMetadataFormat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IIOMetadataFormatImplTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public IIOMetadataFormatImpl440335x() {
    super("rootNode", 0, 1);
    addElement("anElement", "rootNode", 20, 200);
    addAttribute("anElement", "exclusiveAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "50", "500",
                 false, false);
    addAttribute("anElement", "minAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "60", "600",
                 true, false);
    addAttribute("anElement", "maxAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "70", "700",
                 false, true);
    addAttribute("anElement", "minMaxAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "80", "800",
                 true, true);
}
 
Example #2
Source File: IIOMetadataFormatImplTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public IIOMetadataFormatImpl440335x() {
    super("rootNode", 0, 1);
    addElement("anElement", "rootNode", 20, 200);
    addAttribute("anElement", "exclusiveAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "50", "500",
                 false, false);
    addAttribute("anElement", "minAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "60", "600",
                 true, false);
    addAttribute("anElement", "maxAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "70", "700",
                 false, true);
    addAttribute("anElement", "minMaxAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "80", "800",
                 true, true);
}
 
Example #3
Source File: IIOMetadataFormatImplTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public IIOMetadataFormatImpl440335x() {
    super("rootNode", 0, 1);
    addElement("anElement", "rootNode", 20, 200);
    addAttribute("anElement", "exclusiveAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "50", "500",
                 false, false);
    addAttribute("anElement", "minAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "60", "600",
                 true, false);
    addAttribute("anElement", "maxAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "70", "700",
                 false, true);
    addAttribute("anElement", "minMaxAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "80", "800",
                 true, true);
}
 
Example #4
Source File: RemoveElement.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    String elem = "elem2";
    int policy = IIOMetadataFormat.CHILD_POLICY_SOME;
    MyFormatImpl fmt = new MyFormatImpl("root", 1, 10);
    fmt.addElement("elem1", "root", policy);
    fmt.addElement(elem, "root", policy);
    fmt.removeElement("elem1");

    boolean gotIAE = false;
    try {
        fmt.getChildPolicy("elem1");
    } catch (IllegalArgumentException e) {
        gotIAE = true;
    }
    if (!gotIAE) {
        throw new RuntimeException("Element is still present!");
    }
    String[] chNames = fmt.getChildNames("root");
    if (chNames.length != 1) {
        throw new RuntimeException("Root still has more than 1 child!");
    }
    if (!elem.equals(chNames[0])) {
        throw new RuntimeException("Root's remaining child is incorrect!");
    }
}
 
Example #5
Source File: IIOMetadataFormatImplTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public IIOMetadataFormatImpl440335x() {
    super("rootNode", 0, 1);
    addElement("anElement", "rootNode", 20, 200);
    addAttribute("anElement", "exclusiveAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "50", "500",
                 false, false);
    addAttribute("anElement", "minAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "60", "600",
                 true, false);
    addAttribute("anElement", "maxAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "70", "700",
                 false, true);
    addAttribute("anElement", "minMaxAttr",
                 IIOMetadataFormat.DATATYPE_INTEGER,
                 true, null,
                 "80", "800",
                 true, true);
}
 
Example #6
Source File: RemoveElement.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    String elem = "elem2";
    int policy = IIOMetadataFormat.CHILD_POLICY_SOME;
    MyFormatImpl fmt = new MyFormatImpl("root", 1, 10);
    fmt.addElement("elem1", "root", policy);
    fmt.addElement(elem, "root", policy);
    fmt.removeElement("elem1");

    boolean gotIAE = false;
    try {
        fmt.getChildPolicy("elem1");
    } catch (IllegalArgumentException e) {
        gotIAE = true;
    }
    if (!gotIAE) {
        throw new RuntimeException("Element is still present!");
    }
    String[] chNames = fmt.getChildNames("root");
    if (chNames.length != 1) {
        throw new RuntimeException("Root still has more than 1 child!");
    }
    if (!elem.equals(chNames[0])) {
        throw new RuntimeException("Root's remaining child is incorrect!");
    }
}
 
Example #7
Source File: MetadataFormatPrinter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void print(IIOMetadataFormat format) {
    String rootName = format.getRootName();
    println("<!DOCTYPE \"" +
                       rootName +
                       "\" [");
    ++indentLevel;
    print(format, rootName);
    --indentLevel;
    print("]>");
    println();
    println();
}
 
Example #8
Source File: ImageReaderWriterSpi.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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];
                break;  // out of for
            }
        }
    }
    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;
    }
}
 
Example #9
Source File: ObjectArrayMaxLength.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    IIOMetadataFormat f = new MyIIOMetadataFormatImpl();
    if (f.getObjectArrayMaxLength("root") != 321) {
        throw new RuntimeException
            ("Bad value for getObjectArrayMaxLength!");
    }
}
 
Example #10
Source File: MetadataFormatPrinter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void print(IIOMetadataFormat format) {
    String rootName = format.getRootName();
    println("<!DOCTYPE \"" +
                       rootName +
                       "\" [");
    ++indentLevel;
    print(format, rootName);
    --indentLevel;
    print("]>");
    println();
    println();
}
 
Example #11
Source File: ObjectArrayMaxLength.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    IIOMetadataFormat f = new MyIIOMetadataFormatImpl();
    if (f.getObjectArrayMaxLength("root") != 321) {
        throw new RuntimeException
            ("Bad value for getObjectArrayMaxLength!");
    }
}
 
Example #12
Source File: RegisteredFormatsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testMetadataFormat(IIOMetadataFormat fmt,
                                       String fmt_name) {
    System.out.print(fmt_name + "...");
    if (fmt != null) {
        fmts.put(fmt_name, Boolean.TRUE);
        System.out.println("Ok");
    } else {
        throw new RuntimeException("Test failed for " + fmt_name);
    }
}
 
Example #13
Source File: ObjectArrayMaxLength.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    IIOMetadataFormat f = new MyIIOMetadataFormatImpl();
    if (f.getObjectArrayMaxLength("root") != 321) {
        throw new RuntimeException
            ("Bad value for getObjectArrayMaxLength!");
    }
}
 
Example #14
Source File: ObjectArrayMaxLength.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    IIOMetadataFormat f = new MyIIOMetadataFormatImpl();
    if (f.getObjectArrayMaxLength("root") != 321) {
        throw new RuntimeException
            ("Bad value for getObjectArrayMaxLength!");
    }
}
 
Example #15
Source File: ObjectArrayMaxLength.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    IIOMetadataFormat f = new MyIIOMetadataFormatImpl();
    if (f.getObjectArrayMaxLength("root") != 321) {
        throw new RuntimeException
            ("Bad value for getObjectArrayMaxLength!");
    }
}
 
Example #16
Source File: ObjectArrayMaxLength.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    IIOMetadataFormat f = new MyIIOMetadataFormatImpl();
    if (f.getObjectArrayMaxLength("root") != 321) {
        throw new RuntimeException
            ("Bad value for getObjectArrayMaxLength!");
    }
}
 
Example #17
Source File: MetadataFormatPrinter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void print(IIOMetadataFormat format) {
    String rootName = format.getRootName();
    println("<!DOCTYPE \"" +
                       rootName +
                       "\" [");
    ++indentLevel;
    print(format, rootName);
    --indentLevel;
    print("]>");
    println();
    println();
}
 
Example #18
Source File: MetadataFormatPrinter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void print(IIOMetadataFormat format,
                   String elementName) {
    // Don't print elements more than once
    if (printedElements.contains(elementName)) {
        return;
    }
    printedElements.add(elementName);

    // Add the unscheduled children of this node to a list,
    // and mark them as scheduled
    List children = new ArrayList();
    String[] childNames = format.getChildNames(elementName);
    if (childNames != null) {
        for (int i = 0; i < childNames.length; i++) {
            String childName = childNames[i];
            if (!scheduledElements.contains(childName)) {
                children.add(childName);
                scheduledElements.add(childName);
            }
        }
    }

    printElementInfo(format, elementName);
    printObjectInfo(format, elementName);

    ++indentLevel;
    String[] attrNames = format.getAttributeNames(elementName);
    for (int i = 0; i < attrNames.length; i++) {
        printAttributeInfo(format, elementName, attrNames[i]);
    }

    // Recurse on child nodes
    Iterator iter = children.iterator();
    while (iter.hasNext()) {
        print(format, (String)iter.next());
    }
    --indentLevel;
}
 
Example #19
Source File: ImageReaderWriterSpi.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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];
                break;  // out of for
            }
        }
    }
    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;
    }
}
 
Example #20
Source File: JPEGImageMetadataFormat.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static synchronized IIOMetadataFormat getInstance() {
    if (theInstance == null) {
        theInstance = new JPEGImageMetadataFormat();
    }
    return theInstance;
}
 
Example #21
Source File: JPEGStreamMetadataFormat.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static synchronized IIOMetadataFormat getInstance() {
    if (theInstance == null) {
        theInstance = new JPEGStreamMetadataFormat();
    }
    return theInstance;
}
 
Example #22
Source File: GIFStreamMetadataFormat.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static synchronized IIOMetadataFormat getInstance() {
    if (instance == null) {
        instance = new GIFStreamMetadataFormat();
    }
    return instance;
}
 
Example #23
Source File: WBMPMetadataFormat.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static synchronized IIOMetadataFormat getInstance() {
    if (instance == null) {
        instance = new WBMPMetadataFormat();
    }
    return instance;
}
 
Example #24
Source File: MetadataFormatPrinter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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);
}
 
Example #25
Source File: MetadataFormatPrinter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void printObjectInfo(IIOMetadataFormat format,
                             String elementName) {
    int objectType = format.getObjectValueType(elementName);
    if (objectType == IIOMetadataFormat.VALUE_NONE) {
        return;
    }

    Class objectClass = format.getObjectClass(elementName);
    if (objectClass != null) {
        indent();
        if (objectType == IIOMetadataFormat.VALUE_LIST) {
            println("  <!-- User object: array of " +
                    objectClass.getName() +
                    " -->");
        } else {
            println("  <!-- User object: " +
                    objectClass.getName() +
                    " -->");
        }

        Object defaultValue = format.getObjectDefaultValue(elementName);
        if (defaultValue != null) {
            indent();
            println("  <!-- Default value: " +
                    defaultValue.toString() +
                    " -->");
        }

        switch (objectType) {
        case IIOMetadataFormat.VALUE_RANGE:
            indent();
            println("  <!-- Min value: " +
                    format.getObjectMinValue(elementName).toString() +
                    " -->");
            indent();
            println("  <!-- Max value: " +
                    format.getObjectMaxValue(elementName).toString() +
                    " -->");
            break;

        case IIOMetadataFormat.VALUE_ENUMERATION:
            Object[] enums = format.getObjectEnumerations(elementName);
            for (int i = 0; i < enums.length; i++) {
                indent();
                println("  <!-- Enumerated value: " +
                        enums[i].toString() +
                        " -->");
            }
            break;

        case IIOMetadataFormat.VALUE_LIST:
            int minLength = format.getObjectArrayMinLength(elementName);
            if (minLength != 0) {
                indent();
                println("  <!-- Min length: " +
                        minLength +
                        " -->");
            }
            int maxLength = format.getObjectArrayMaxLength(elementName);
            if (maxLength != Integer.MAX_VALUE) {
                indent();
                println("  <!-- Max length: " +
                        maxLength +
                        " -->");
            }
            break;
        }
    }
}
 
Example #26
Source File: JPEGStreamMetadataFormat.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static synchronized IIOMetadataFormat getInstance() {
    if (theInstance == null) {
        theInstance = new JPEGStreamMetadataFormat();
    }
    return theInstance;
}
 
Example #27
Source File: UserPluginMetadataFormatTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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);
            }
        }
    }
 
Example #28
Source File: BMPMetadataFormat.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static synchronized IIOMetadataFormat getInstance() {
    if (instance == null) {
        instance = new BMPMetadataFormat();
    }
    return instance;
}
 
Example #29
Source File: PNGMetadataFormat.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static synchronized IIOMetadataFormat getInstance() {
    if (instance == null) {
        instance = new PNGMetadataFormat();
    }
    return instance;
}
 
Example #30
Source File: JPEGImageMetadataFormat.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static synchronized IIOMetadataFormat getInstance() {
    if (theInstance == null) {
        theInstance = new JPEGImageMetadataFormat();
    }
    return theInstance;
}