private int computeLength(IIOMetadataNode root) { NodeList list = root.getChildNodes(); int length = 0; for (int i = 0; i < list.getLength(); i++) { IIOMetadataNode node = (IIOMetadataNode) list.item(i); String name = node.getNodeName(); if (format.isLeaf(name)) length += new Integer((String) Box.getAttribute(node, "Length")).intValue(); else length += computeLength(node); } return length + (root.getNodeName().startsWith("JPEG2000") ? 8 : 0); }
private void writeSuperBox(IIOMetadataNode node) throws IOException { NodeList list = node.getChildNodes(); String name = node.getNodeName(); if (name.startsWith("JPEG2000")) { stream.writeInt(computeLength(node)); stream.writeInt(Box.getTypeInt((String) Box.getTypeByName(name))); otherLength += 8; } for (int i = 0; i < list.getLength(); i++) { IIOMetadataNode child = (IIOMetadataNode) list.item(i); name = child.getNodeName(); if (name.startsWith("JPEG2000") && format.isLeaf(name)) writeBox(child); else writeSuperBox(child); } }