use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class MyAttrNode method test1.
public static void test1() {
IIOMetadataNode parent = new IIOMetadataNode("parent");
IIOMetadataNode elem = new IIOMetadataNode("elem");
MyAttrNode attrNode = new MyAttrNode("name", "value");
elem.setAttributeNode(attrNode);
attrNode.setOwnerElement(elem);
try {
parent.setAttributeNode(attrNode);
} catch (DOMException e) {
if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) {
throw new RuntimeException("Test 1 failed: " + "Invalid exception code: " + e.code);
}
return;
}
throw new RuntimeException("Test 1 failed: DOMException not thrown");
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class MyAttrNode method test2.
public static void test2() {
String name = "attr";
String oldValue = "old value";
String newValue = "new value";
Attr retAttr;
IIOMetadataNode parent = new IIOMetadataNode("parent");
MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
MyAttrNode attrNode2 = new MyAttrNode(name, newValue);
retAttr = parent.setAttributeNode(attrNode1);
retAttr = parent.setAttributeNode(attrNode2);
String actName = retAttr.getNodeName();
String actValue = retAttr.getValue();
if (!actName.equals(name) || !actValue.equals(oldValue)) {
throw new RuntimeException("Test 2 failed: Invalid attribute " + "returned: " + "(name: " + actName + ", value: " + actValue + ")");
}
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class WriteMetadataTest method testWritableMetadata.
public static void testWritableMetadata(IIOMetadata m) {
String nativeFormatName = m.getNativeMetadataFormatName();
System.out.println("Format: " + nativeFormatName);
IIOMetadataNode root = (IIOMetadataNode) m.getAsTree(nativeFormatName);
if (m.isReadOnly()) {
throw new RuntimeException("Metadata is read only!");
}
try {
m.setFromTree(nativeFormatName, root);
} catch (IIOInvalidTreeException e) {
e.printStackTrace();
throw new RuntimeException("Test failed!", e);
} catch (IllegalStateException e) {
throw new RuntimeException("Test failed!", e);
}
System.out.println("Test passed.\n\n");
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class ITXtTest method writeTo.
private static void writeTo(File f, ITXtTest t) {
BufferedImage src = createBufferedImage();
try {
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(f);
ImageTypeSpecifier imageTypeSpecifier = new ImageTypeSpecifier(src);
ImageWriter imageWriter = ImageIO.getImageWritersByFormatName("PNG").next();
imageWriter.setOutput(imageOutputStream);
IIOMetadata m = imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);
String format = m.getNativeMetadataFormatName();
Node root = m.getAsTree(format);
IIOMetadataNode iTXt = t.getNode();
root.appendChild(iTXt);
m.setFromTree(format, root);
imageWriter.write(new IIOImage(src, null, m));
imageOutputStream.close();
System.out.println("Writing done.");
} catch (Throwable e) {
throw new RuntimeException("Writing test failed.", e);
}
}
use of javax.imageio.metadata.IIOMetadataNode in project jdk8u_jdk by JetBrains.
the class BMPMetadata method addChildNode.
private IIOMetadataNode addChildNode(IIOMetadataNode root, String name, Object object) {
IIOMetadataNode child = new IIOMetadataNode(name);
if (object != null) {
child.setUserObject(object);
child.setNodeValue(ImageUtil.convertObjectToString(object));
}
root.appendChild(child);
return child;
}
Aggregations