javax.imageio.metadata.IIOInvalidTreeException Java Examples

The following examples show how to use javax.imageio.metadata.IIOInvalidTreeException. 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: TIFFStreamMetadata.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private void mergeNativeTree(Node root) throws IIOInvalidTreeException {
    Node node = root;
    if (!node.getNodeName().equals(nativeMetadataFormatName)) {
        fatal(node, "Root must be " + nativeMetadataFormatName);
    }

    node = node.getFirstChild();
    if (node == null || !node.getNodeName().equals("ByteOrder")) {
        fatal(node, "Root must have \"ByteOrder\" child");
    }

    NamedNodeMap attrs = node.getAttributes();
    String order = attrs.getNamedItem("value").getNodeValue();

    if (order == null) {
        fatal(node, "ByteOrder node must have a \"value\" attribute");
    }
    if (order.equals(bigEndianString)) {
        this.byteOrder = ByteOrder.BIG_ENDIAN;
    } else if (order.equals(littleEndianString)) {
        this.byteOrder = ByteOrder.LITTLE_ENDIAN;
    } else {
        fatal(node, "Incorrect value for ByteOrder \"value\" attribute");
    }
}
 
Example #2
Source File: JPEGMetadata.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public void setFromTree(String formatName, Node root)
    throws IIOInvalidTreeException {
    if (formatName == null) {
        throw new IllegalArgumentException("null formatName!");
    }
    if (root == null) {
        throw new IllegalArgumentException("null root!");
    }
    if (isStream &&
        (formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
        setFromNativeTree(root);
    } else if (!isStream &&
               (formatName.equals(JPEG.nativeImageMetadataFormatName))) {
        setFromNativeTree(root);
    } else if (!isStream &&
               (formatName.equals
                (IIOMetadataFormatImpl.standardMetadataFormatName))) {
        // In this case a reset followed by a merge is correct
        super.setFromTree(formatName, root);
    } else {
        throw  new IllegalArgumentException("Unsupported format name: "
                                            + formatName);
    }
}
 
Example #3
Source File: GIFMetadata.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected static boolean getBooleanAttribute(Node node, String name,
                                             boolean defaultValue,
                                             boolean required)
  throws IIOInvalidTreeException {
    Node attr = node.getAttributes().getNamedItem(name);
    if (attr == null) {
        if (!required) {
            return defaultValue;
        } else {
            fatal(node, "Required attribute " + name + " not present!");
        }
    }
    String value = attr.getNodeValue();
    // Allow lower case booleans for backward compatibility, #5082756
    if (value.equals("TRUE") || value.equals("true")) {
        return true;
    } else if (value.equals("FALSE") || value.equals("false")) {
        return false;
    } else {
        fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
        return false;
    }
}
 
Example #4
Source File: PNGMetadata.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void mergeTree(String formatName, Node root)
    throws IIOInvalidTreeException {
    if (formatName.equals(nativeMetadataFormatName)) {
        if (root == null) {
            throw new IllegalArgumentException("root == null!");
        }
        mergeNativeTree(root);
    } else if (formatName.equals
               (IIOMetadataFormatImpl.standardMetadataFormatName)) {
        if (root == null) {
            throw new IllegalArgumentException("root == null!");
        }
        mergeStandardTree(root);
    } else {
        throw new IllegalArgumentException("Not a recognized format!");
    }
}
 
Example #5
Source File: JPEGMetadata.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void mergeStandardTextNode(Node node)
    throws IIOInvalidTreeException {
    // Convert to comments.  For the moment ignore the encoding issue.
    // Ignore keywords, language, and encoding (for the moment).
    // If compression tag is present, use only entries with "none".
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        NamedNodeMap attrs = child.getAttributes();
        Node comp = attrs.getNamedItem("compression");
        boolean copyIt = true;
        if (comp != null) {
            String compString = comp.getNodeValue();
            if (!compString.equals("none")) {
                copyIt = false;
            }
        }
        if (copyIt) {
            String value = attrs.getNamedItem("value").getNodeValue();
            COMMarkerSegment com = new COMMarkerSegment(value);
            insertCOMMarkerSegment(com);
        }
    }
}
 
Example #6
Source File: PNGMetadata.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean getBooleanAttribute(Node node, String name,
                                    boolean defaultValue,
                                    boolean required)
    throws IIOInvalidTreeException {
    Node attr = node.getAttributes().getNamedItem(name);
    if (attr == null) {
        if (!required) {
            return defaultValue;
        } else {
            fatal(node, "Required attribute " + name + " not present!");
        }
    }
    String value = attr.getNodeValue();
    // Allow lower case booleans for backward compatibility, #5082756
    if (value.equals("TRUE") || value.equals("true")) {
        return true;
    } else if (value.equals("FALSE") || value.equals("false")) {
        return false;
    } else {
        fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
        return false;
    }
}
 
Example #7
Source File: JPEGMetadata.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private void mergeStandardTree(Node root) throws IIOInvalidTreeException {
    transparencyDone = false;
    NodeList children = root.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        String name = node.getNodeName();
        if (name.equals("Chroma")) {
            mergeStandardChromaNode(node, children);
        } else if (name.equals("Compression")) {
            mergeStandardCompressionNode(node);
        } else if (name.equals("Data")) {
            mergeStandardDataNode(node);
        } else if (name.equals("Dimension")) {
            mergeStandardDimensionNode(node);
        } else if (name.equals("Document")) {
            mergeStandardDocumentNode(node);
        } else if (name.equals("Text")) {
            mergeStandardTextNode(node);
        } else if (name.equals("Transparency")) {
            mergeStandardTransparencyNode(node);
        } else {
            throw new IIOInvalidTreeException("Invalid node: " + name, node);
        }
    }
}
 
Example #8
Source File: SOFMarkerSegment.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
void updateFromNativeNode(Node node, boolean fromScratch)
    throws IIOInvalidTreeException {
    NamedNodeMap attrs = node.getAttributes();
    int value = getAttributeValue(node, attrs, "process", 0, 2, false);
    tag = (value != -1) ? value+JPEG.SOF0 : tag;
    // If samplePrecision is present, it must be 8.
    // This just checks.  We don't bother to assign the value.
    value = getAttributeValue(node, attrs, "samplePrecision", 8, 8, false);
    value = getAttributeValue(node, attrs, "numLines", 0, 65535, false);
    numLines = (value != -1) ? value : numLines;
    value = getAttributeValue(node, attrs, "samplesPerLine", 0, 65535, false);
    samplesPerLine = (value != -1) ? value : samplesPerLine;
    int numComponents = getAttributeValue(node, attrs, "numFrameComponents",
                                          1, 4, false);
    NodeList children = node.getChildNodes();
    if (children.getLength() != numComponents) {
        throw new IIOInvalidTreeException
            ("numFrameComponents must match number of children", node);
    }
    componentSpecs = new ComponentSpec [numComponents];
    for (int i = 0; i < numComponents; i++) {
        componentSpecs[i] = new ComponentSpec(children.item(i));
    }
}
 
Example #9
Source File: JPEGMetadata.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void setFromTree(String formatName, Node root)
    throws IIOInvalidTreeException {
    if (formatName == null) {
        throw new IllegalArgumentException("null formatName!");
    }
    if (root == null) {
        throw new IllegalArgumentException("null root!");
    }
    if (isStream &&
        (formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
        setFromNativeTree(root);
    } else if (!isStream &&
               (formatName.equals(JPEG.nativeImageMetadataFormatName))) {
        setFromNativeTree(root);
    } else if (!isStream &&
               (formatName.equals
                (IIOMetadataFormatImpl.standardMetadataFormatName))) {
        // In this case a reset followed by a merge is correct
        super.setFromTree(formatName, root);
    } else {
        throw  new IllegalArgumentException("Unsupported format name: "
                                            + formatName);
    }
}
 
Example #10
Source File: SOFMarkerSegment.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
void updateFromNativeNode(Node node, boolean fromScratch)
    throws IIOInvalidTreeException {
    NamedNodeMap attrs = node.getAttributes();
    int value = getAttributeValue(node, attrs, "process", 0, 2, false);
    tag = (value != -1) ? value+JPEG.SOF0 : tag;
    // If samplePrecision is present, it must be 8.
    // This just checks.  We don't bother to assign the value.
    value = getAttributeValue(node, attrs, "samplePrecision", 8, 8, false);
    value = getAttributeValue(node, attrs, "numLines", 0, 65535, false);
    numLines = (value != -1) ? value : numLines;
    value = getAttributeValue(node, attrs, "samplesPerLine", 0, 65535, false);
    samplesPerLine = (value != -1) ? value : samplesPerLine;
    int numComponents = getAttributeValue(node, attrs, "numFrameComponents",
                                          1, 4, false);
    NodeList children = node.getChildNodes();
    if (children.getLength() != numComponents) {
        throw new IIOInvalidTreeException
            ("numFrameComponents must match number of children", node);
    }
    componentSpecs = new ComponentSpec [numComponents];
    for (int i = 0; i < numComponents; i++) {
        componentSpecs[i] = new ComponentSpec(children.item(i));
    }
}
 
Example #11
Source File: COMMarkerSegment.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a marker segment from a native tree node.  If the node
 * is an <code>IIOMetadataNode</code> and contains a user object,
 * that object is used rather than the string attribute.  If the
 * string attribute is used, the default encoding is used.
 */
COMMarkerSegment(Node node) throws IIOInvalidTreeException{
    super(JPEG.COM);
    if (node instanceof IIOMetadataNode) {
        IIOMetadataNode ourNode = (IIOMetadataNode) node;
        data = (byte []) ourNode.getUserObject();
    }
    if (data == null) {
        String comment =
            node.getAttributes().getNamedItem("comment").getNodeValue();
        if (comment != null) {
            data = comment.getBytes(); // Default encoding
        } else {
            throw new IIOInvalidTreeException("Empty comment node!", node);
        }
    }
}
 
Example #12
Source File: GIFMetadata.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void mergeTree(String formatName, Node root)
  throws IIOInvalidTreeException {
    if (formatName.equals(nativeMetadataFormatName)) {
        if (root == null) {
            throw new IllegalArgumentException("root == null!");
        }
        mergeNativeTree(root);
    } else if (formatName.equals
              (IIOMetadataFormatImpl.standardMetadataFormatName)) {
        if (root == null) {
            throw new IllegalArgumentException("root == null!");
        }
        mergeStandardTree(root);
    } else {
        throw new IllegalArgumentException("Not a recognized format!");
    }
}
 
Example #13
Source File: JPEGMetadata.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Merge a JFIF subtree into the marker sequence, if the subtree
 * is non-empty.
 * If a JFIF marker exists, update it from the subtree.
 * If none exists, create one from the subtree and insert it at the
 * beginning of the marker sequence.
 */
private void mergeJFIFsubtree(Node JPEGvariety)
    throws IIOInvalidTreeException {
    if (JPEGvariety.getChildNodes().getLength() != 0) {
        Node jfifNode = JPEGvariety.getFirstChild();
        // is there already a jfif marker segment?
        JFIFMarkerSegment jfifSeg =
            (JFIFMarkerSegment) findMarkerSegment(JFIFMarkerSegment.class, true);
        if (jfifSeg != null) {
            jfifSeg.updateFromNativeNode(jfifNode, false);
        } else {
            // Add it as the first element in the list.
            markerSequence.add(0, new JFIFMarkerSegment(jfifNode));
        }
    }
}
 
Example #14
Source File: GIFMetadata.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected static int getEnumeratedAttribute(Node node,
                                            String name,
                                            String[] legalNames,
                                            int defaultValue,
                                            boolean required)
  throws IIOInvalidTreeException {
    Node attr = node.getAttributes().getNamedItem(name);
    if (attr == null) {
        if (!required) {
            return defaultValue;
        } else {
            fatal(node, "Required attribute " + name + " not present!");
        }
    }
    String value = attr.getNodeValue();
    for (int i = 0; i < legalNames.length; i++) {
        if(value.equals(legalNames[i])) {
            return i;
        }
    }

    fatal(node, "Illegal value for attribute " + name + "!");
    return -1;
}
 
Example #15
Source File: PNGMetadata.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private boolean getBooleanAttribute(Node node, String name,
                                    boolean defaultValue,
                                    boolean required)
    throws IIOInvalidTreeException {
    Node attr = node.getAttributes().getNamedItem(name);
    if (attr == null) {
        if (!required) {
            return defaultValue;
        } else {
            fatal(node, "Required attribute " + name + " not present!");
        }
    }
    String value = attr.getNodeValue();
    // Allow lower case booleans for backward compatibility, #5082756
    if (value.equals("TRUE") || value.equals("true")) {
        return true;
    } else if (value.equals("FALSE") || value.equals("false")) {
        return false;
    } else {
        fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
        return false;
    }
}
 
Example #16
Source File: SOFMarkerSegment.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
void updateFromNativeNode(Node node, boolean fromScratch)
    throws IIOInvalidTreeException {
    NamedNodeMap attrs = node.getAttributes();
    int value = getAttributeValue(node, attrs, "process", 0, 2, false);
    tag = (value != -1) ? value+JPEG.SOF0 : tag;
    // If samplePrecision is present, it must be 8.
    // This just checks.  We don't bother to assign the value.
    value = getAttributeValue(node, attrs, "samplePrecision", 8, 8, false);
    value = getAttributeValue(node, attrs, "numLines", 0, 65535, false);
    numLines = (value != -1) ? value : numLines;
    value = getAttributeValue(node, attrs, "samplesPerLine", 0, 65535, false);
    samplesPerLine = (value != -1) ? value : samplesPerLine;
    int numComponents = getAttributeValue(node, attrs, "numFrameComponents",
                                          1, 4, false);
    NodeList children = node.getChildNodes();
    if (children.getLength() != numComponents) {
        throw new IIOInvalidTreeException
            ("numFrameComponents must match number of children", node);
    }
    componentSpecs = new ComponentSpec [numComponents];
    for (int i = 0; i < numComponents; i++) {
        componentSpecs[i] = new ComponentSpec(children.item(i));
    }
}
 
Example #17
Source File: GIFMetadata.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
protected static boolean getBooleanAttribute(Node node, String name,
                                             boolean defaultValue,
                                             boolean required)
  throws IIOInvalidTreeException {
    Node attr = node.getAttributes().getNamedItem(name);
    if (attr == null) {
        if (!required) {
            return defaultValue;
        } else {
            fatal(node, "Required attribute " + name + " not present!");
        }
    }
    String value = attr.getNodeValue();
    // Allow lower case booleans for backward compatibility, #5082756
    if (value.equals("TRUE") || value.equals("true")) {
        return true;
    } else if (value.equals("FALSE") || value.equals("false")) {
        return false;
    } else {
        fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
        return false;
    }
}
 
Example #18
Source File: XMLBox.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
/** Constructs a <code>UUIDListBox</code> based on the provided
   *  <code>org.w3c.dom.Node</code>.
   */
  public XMLBox(Node node) throws IIOInvalidTreeException {
      super(node);
      NodeList children = node.getChildNodes();

      for (int i = 0; i < children.getLength(); i++) {
          Node child = children.item(i);
          String name = child.getNodeName();

          if ("Content".equals(name)) {
String value = child.getNodeValue();
if (value != null)
    data = value.getBytes();
else if (child instanceof IIOMetadataNode) {
    value = (String)((IIOMetadataNode)child).getUserObject();
    if (value != null)
	data = value.getBytes();
}
          }
      }
  }
 
Example #19
Source File: GIFMetadata.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected static boolean getBooleanAttribute(Node node, String name,
                                             boolean defaultValue,
                                             boolean required)
  throws IIOInvalidTreeException {
    Node attr = node.getAttributes().getNamedItem(name);
    if (attr == null) {
        if (!required) {
            return defaultValue;
        } else {
            fatal(node, "Required attribute " + name + " not present!");
        }
    }
    String value = attr.getNodeValue();
    // Allow lower case booleans for backward compatibility, #5082756
    if (value.equals("TRUE") || value.equals("true")) {
        return true;
    } else if (value.equals("FALSE") || value.equals("false")) {
        return false;
    } else {
        fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
        return false;
    }
}
 
Example #20
Source File: JPEGMetadata.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Merge the given Unknown node into the marker sequence.
 * A new Unknown marker segment is created and added to the sequence as
 * follows:
 * If there already exist Unknown marker segments, the new one is inserted
 * after the last one.
 * If there are no Unknown marker segments, the new Unknown marker segment
 * is inserted after the JFIF segment, if there is one.
 * If there is no JFIF segment, the new Unknown segment is inserted before
 * the Adobe marker segment, if there is one.
 * If there is no Adobe segment, the new Unknown segment is inserted
 * at the beginning of the sequence.
 */
private void mergeUnknownNode(Node node) throws IIOInvalidTreeException {
    MarkerSegment newGuy = new MarkerSegment(node);
    int lastUnknown = findLastUnknownMarkerSegmentPosition();
    boolean hasJFIF = (findMarkerSegment(JFIFMarkerSegment.class, true) != null);
    int firstAdobe = findMarkerSegmentPosition(AdobeMarkerSegment.class, true);
    if (lastUnknown != -1) {
        markerSequence.add(lastUnknown+1, newGuy);
    } else if (hasJFIF) {
        markerSequence.add(1, newGuy);  // JFIF is always 0
    } if (firstAdobe != -1) {
        markerSequence.add(firstAdobe, newGuy);
    } else {
        markerSequence.add(0, newGuy);
    }
}
 
Example #21
Source File: GIFMetadata.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected static boolean getBooleanAttribute(Node node, String name,
                                             boolean defaultValue,
                                             boolean required)
  throws IIOInvalidTreeException {
    Node attr = node.getAttributes().getNamedItem(name);
    if (attr == null) {
        if (!required) {
            return defaultValue;
        } else {
            fatal(node, "Required attribute " + name + " not present!");
        }
    }
    String value = attr.getNodeValue();
    // Allow lower case booleans for backward compatibility, #5082756
    if (value.equals("TRUE") || value.equals("true")) {
        return true;
    } else if (value.equals("FALSE") || value.equals("false")) {
        return false;
    } else {
        fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
        return false;
    }
}
 
Example #22
Source File: JPEGMetadata.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void setFromTree(String formatName, Node root)
    throws IIOInvalidTreeException {
    if (formatName == null) {
        throw new IllegalArgumentException("null formatName!");
    }
    if (root == null) {
        throw new IllegalArgumentException("null root!");
    }
    if (isStream &&
        (formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
        setFromNativeTree(root);
    } else if (!isStream &&
               (formatName.equals(JPEG.nativeImageMetadataFormatName))) {
        setFromNativeTree(root);
    } else if (!isStream &&
               (formatName.equals
                (IIOMetadataFormatImpl.standardMetadataFormatName))) {
        // In this case a reset followed by a merge is correct
        super.setFromTree(formatName, root);
    } else {
        throw  new IllegalArgumentException("Unsupported format name: "
                                            + formatName);
    }
}
 
Example #23
Source File: J2KMetadata.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
public void mergeTree(String formatName, Node root)
    throws IIOInvalidTreeException {
    if (formatName == null) {
        throw new IllegalArgumentException(I18N.getString("J2KMetadata0"));
    }

    if (root == null) {
        throw new IllegalArgumentException(I18N.getString("J2KMetadata2"));
    }

    if (formatName.equals(nativeMetadataFormatName) &&
        root.getNodeName().equals(nativeMetadataFormatName)) {
        mergeNativeTree(root);
    } else if (formatName.equals
                (IIOMetadataFormatImpl.standardMetadataFormatName)) {
        mergeStandardTree(root);
    } else {
        throw  new IllegalArgumentException(I18N.getString("J2KMetadata1")
                                            + " " + formatName);
    }
}
 
Example #24
Source File: JPEGMetadata.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void setFromTree(String formatName, Node root)
    throws IIOInvalidTreeException {
    if (formatName == null) {
        throw new IllegalArgumentException("null formatName!");
    }
    if (root == null) {
        throw new IllegalArgumentException("null root!");
    }
    if (isStream &&
        (formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
        setFromNativeTree(root);
    } else if (!isStream &&
               (formatName.equals(JPEG.nativeImageMetadataFormatName))) {
        setFromNativeTree(root);
    } else if (!isStream &&
               (formatName.equals
                (IIOMetadataFormatImpl.standardMetadataFormatName))) {
        // In this case a reset followed by a merge is correct
        super.setFromTree(formatName, root);
    } else {
        throw  new IllegalArgumentException("Unsupported format name: "
                                            + formatName);
    }
}
 
Example #25
Source File: COMMarkerSegment.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a marker segment from a native tree node.  If the node
 * is an <code>IIOMetadataNode</code> and contains a user object,
 * that object is used rather than the string attribute.  If the
 * string attribute is used, the default encoding is used.
 */
COMMarkerSegment(Node node) throws IIOInvalidTreeException{
    super(JPEG.COM);
    if (node instanceof IIOMetadataNode) {
        IIOMetadataNode ourNode = (IIOMetadataNode) node;
        data = (byte []) ourNode.getUserObject();
    }
    if (data == null) {
        String comment =
            node.getAttributes().getNamedItem("comment").getNodeValue();
        if (comment != null) {
            data = comment.getBytes(); // Default encoding
        } else {
            throw new IIOInvalidTreeException("Empty comment node!", node);
        }
    }
}
 
Example #26
Source File: MarkerSegment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a MarkerSegment from an "unknown" DOM Node.
 */
MarkerSegment(Node node) throws IIOInvalidTreeException {
    // The type of node should have been verified already.
    // get the attribute and assign it to the tag
    tag = getAttributeValue(node,
                            null,
                            "MarkerTag",
                            0, 255,
                            true);
    length = 0;
    // get the user object and clone it to the data
    if (node instanceof IIOMetadataNode) {
        IIOMetadataNode iioNode = (IIOMetadataNode) node;
        try {
            data = (byte []) iioNode.getUserObject();
        } catch (Exception e) {
            IIOInvalidTreeException newGuy =
                new IIOInvalidTreeException
                ("Can't get User Object", node);
            newGuy.initCause(e);
            throw newGuy;
        }
    } else {
        throw new IIOInvalidTreeException
            ("Node must have User Object", node);
    }
}
 
Example #27
Source File: MarkerSegment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a MarkerSegment from an "unknown" DOM Node.
 */
MarkerSegment(Node node) throws IIOInvalidTreeException {
    // The type of node should have been verified already.
    // get the attribute and assign it to the tag
    tag = getAttributeValue(node,
                            null,
                            "MarkerTag",
                            0, 255,
                            true);
    length = 0;
    // get the user object and clone it to the data
    if (node instanceof IIOMetadataNode) {
        IIOMetadataNode iioNode = (IIOMetadataNode) node;
        try {
            data = (byte []) iioNode.getUserObject();
        } catch (Exception e) {
            IIOInvalidTreeException newGuy =
                new IIOInvalidTreeException
                ("Can't get User Object", node);
            newGuy.initCause(e);
            throw newGuy;
        }
    } else {
        throw new IIOInvalidTreeException
            ("Node must have User Object", node);
    }
}
 
Example #28
Source File: PNGMetadata.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private String getStringAttribute(Node node, String name,
                                  String defaultValue, boolean required)
    throws IIOInvalidTreeException {
    Node attr = node.getAttributes().getNamedItem(name);
    if (attr == null) {
        if (!required) {
            return defaultValue;
        } else {
            fatal(node, "Required attribute " + name + " not present!");
        }
    }
    return attr.getNodeValue();
}
 
Example #29
Source File: DQTMarkerSegment.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
Qtable(Node node) throws IIOInvalidTreeException {
    if (node.getNodeName().equals("dqtable")) {
        NamedNodeMap attrs = node.getAttributes();
        int count = attrs.getLength();
        if ((count < 1) || (count > 2)) {
            throw new IIOInvalidTreeException
                ("dqtable node must have 1 or 2 attributes", node);
        }
        elementPrecision = 0;
        tableID = getAttributeValue(node, attrs, "qtableId", 0, 3, true);
        if (node instanceof IIOMetadataNode) {
            IIOMetadataNode ourNode = (IIOMetadataNode) node;
            JPEGQTable table = (JPEGQTable) ourNode.getUserObject();
            if (table == null) {
                throw new IIOInvalidTreeException
                    ("dqtable node must have user object", node);
            }
            data = table.getTable();
        } else {
            throw new IIOInvalidTreeException
                ("dqtable node must have user object", node);
        }
    } else {
        throw new IIOInvalidTreeException
            ("Invalid node, expected dqtable", node);
    }
}
 
Example #30
Source File: PngDitDepthTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IIOInvalidTreeException {

        // getting the writer for the png format
        Iterator iter = ImageIO.getImageWritersByFormatName("png");
        ImageWriter writer = (ImageWriter) iter.next();

        // creating a color model
        ColorModel colorModel = ColorModel.getRGBdefault();

        // creating a sample model
        SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);

        // creating a default metadata object
        IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
        String formatName = metaData.getNativeMetadataFormatName();

        // first call
        Node metaDataNode = metaData.getAsTree(formatName);
        try {
            metaData.setFromTree(formatName, metaDataNode);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // second call (bitdepht is already set to an invalid value)
        metaDataNode = metaData.getAsTree(formatName);

        metaData.setFromTree(formatName, metaDataNode);

    }