content: /*
   * AttributeExtended.java    12:37 AM, August 11, 2007
   *
   * Copyright  2007, BinaryInternals.org. All rights reserved.
   * Use is subject to license terms.
   */
  package org.binaryinternals.format.classfile.attribute;
  
  import java.io.IOException;
  import javax.swing.tree.DefaultMutableTreeNode;
  import org.binaryinternals.commonlib.core.FileFormat;
  import org.binaryinternals.commonlib.core.FileFormatException;
  import org.binaryinternals.commonlib.core.PosDataInputStream;
  import org.binaryinternals.commonlib.ui.JTreeNodeFileComponent;
  import org.binaryinternals.format.classfile.u2;
  
  /**
   * The class for the Unrecognized attribute. Non-standard attribute, all of the
   * attributes which are not defined in the VM Spec will be represented by this
   * class.
   *
   * <pre>
   *    attribute_info {
   *        u2 attribute_name_index;
   *        u4 attribute_length;
   *
   *        u1 info[attribute_length];
   *    }
   * </pre>
   *
   * The {@code info} is the raw byte array data.
   *
   *
   * @author Amos Shi
   * @since Java 1.0.2
   *
   * <pre>
   * java:S101 - Class names should comply with a naming convention --- We respect the name from JVM Spec instead
   * </pre>
   */
  @SuppressWarnings("java:S101")
  public class Unrecognized_attribute extends attribute_info {
  
      private byte[] rawData;
  
      Unrecognized_attribute(final u2 nameIndex, final String type, final PosDataInputStream posDataInputStream) throws IOException, FileFormatException {
          super(nameIndex, type, posDataInputStream);
  
          if (this.attribute_length.value > 0) {
              this.rawData = new byte[this.attribute_length.value];
              int readBytes = posDataInputStream.read(this.rawData);
              if (readBytes != this.attribute_length.value) {
                  throw new IOException(String.format("Failed to read %d bytes, actual bytes red %d", this.attribute_length.value, readBytes));
              }
          }
  
          super.checkSize(posDataInputStream.getPos());
      }
  
      /**
       * Get the value of {@code info}, in raw data format.
       *
       * @return The value of {@code info}
       */
      public byte[] getRawData() {
          return this.rawData.clone();
      }
  
      @Override
      public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat classFile) {
          if (this.attribute_length.value > 0) {
              parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                      this.getStartPos() + 6,
                      this.attribute_length.value,
                      "raw data"
              )));
          }
      }
  
      @Override
      public String getMessageKey() {
          return "msg_attr_Unrecognized";
      }
  }
  