예제 #1
0
  /** Return {@code true} if a double slot is read (in case of Double or Long constant). */
  private boolean readConstantPoolEntry(final DataInput di, final int index) throws IOException {

    final int tag = di.readUnsignedByte();
    switch (tag) {
      case CP_METHOD_TYPE:
        di.skipBytes(2); // readUnsignedShort()
        return false;
      case CP_METHOD_HANDLE:
        di.skipBytes(3);
        return false;
      case CP_INTEGER:
      case CP_FLOAT:
      case CP_REF_FIELD:
      case CP_REF_METHOD:
      case CP_REF_INTERFACE:
      case CP_NAME_AND_TYPE:
      case CP_INVOKE_DYNAMIC:
        di.skipBytes(4); // readInt() / readFloat() / readUnsignedShort() * 2
        return false;
      case CP_LONG:
      case CP_DOUBLE:
        di.skipBytes(8); // readLong() / readDouble()
        return true;
      case CP_UTF8:
        constantPool[index] = di.readUTF();
        return false;
      case CP_CLASS:
      case CP_STRING:
        // reference to CP_UTF8 entry. The referenced index can have a higher number!
        constantPool[index] = di.readUnsignedShort();
        return false;
      default:
        throw new ClassFormatError("Unkown tag value for constant pool entry: " + tag);
    }
  }
예제 #2
0
  private void readRowByte(
      final DataInput input,
      Rectangle srcRegion,
      int xSub,
      int ySub,
      byte[] rowDataByte,
      final int off,
      final int length,
      WritableRaster destChannel,
      Raster srcChannel,
      int y)
      throws IOException {
    // If subsampled or outside source region, skip entire row
    if (y % ySub != 0 || y < srcRegion.y || y >= srcRegion.y + srcRegion.height) {
      input.skipBytes(length);

      return;
    }

    input.readFully(rowDataByte, off, length);

    // Subsample horizontal
    if (xSub != 1) {
      for (int x = 0; x < srcRegion.width / xSub; x++) {
        rowDataByte[srcRegion.x + x] = rowDataByte[srcRegion.x + x * xSub];
      }
    }

    int dstY = (y - srcRegion.y) / ySub;
    destChannel.setDataElements(0, dstY, srcChannel);
  }
예제 #3
0
 private void readVersion(final DataInput di) throws IOException {
   // sequence: minor version, major version (argument_index is 1-based)
   if (DEBUG) {
     print("Java Class version %2$d.%1$d", di.readUnsignedShort(), di.readUnsignedShort());
   } else {
     di.skipBytes(4);
   }
 }
예제 #4
0
 @Override
 public int skipBytes(int n) {
   try {
     return input.skipBytes(n);
   } catch (IOException e) {
     throw new IllegalStateException(e);
   }
 }
 public ConstantValueAttr(ConstantPool cp, String name, int length, DataInput din)
     throws IOException {
   super(cp, name);
   int index = din.readUnsignedShort();
   if ((length -= 2) > 0) {
     din.skipBytes(length);
   }
   mConstant = cp.getConstant(index);
 }
 private static void skipField(DataInput in) throws IOException {
   int len = in.readInt();
   // skipBytes doesn't have to block
   int skipped = in.skipBytes(len);
   if (skipped < len) {
     // wastefully use readFully() if skipBytes didn't work
     byte[] bytes = new byte[(len - skipped)];
     in.readFully(bytes);
   }
 }
예제 #7
0
 private void skip(int num) throws IOException {
   while (num > 0) {
     long result;
     if (in != null) {
       result = in.skip(num);
     } else {
       result = din.skipBytes(num);
     }
     if (result > 0) {
       num -= result;
     }
   }
 }
예제 #8
0
 public static String readFixedString(int size, DataInput in) throws IOException {
   StringBuilder b = new StringBuilder(size);
   int i = 0;
   boolean more = true;
   while (more && i < size) {
     char ch = in.readChar();
     i++;
     if (ch == 0) more = false;
     else b.append(ch);
   }
   in.skipBytes(2 * (size - i));
   return b.toString();
 }
예제 #9
0
  /**
   * Skip <i>len</i> number of bytes in input stream<i>in</i>
   *
   * @param in input stream
   * @param len number of bytes to skip
   * @throws IOException when skipped less number of bytes
   */
  public static void skipFully(DataInput in, int len) throws IOException {
    int total = 0;
    int cur = 0;

    while ((total < len) && ((cur = in.skipBytes(len - total)) > 0)) {
      total += cur;
    }

    if (total < len) {
      throw new IOException(
          "Not able to skip " + len + " bytes, possibly " + "due to end of input.");
    }
  }
예제 #10
0
 private void readAnnotationElementValue(final DataInput di) throws IOException {
   final int tag = di.readUnsignedByte();
   if (DEBUG) {
     print("tag='%c'", (char) tag);
   }
   switch (tag) {
     case BYTE:
     case CHAR:
     case DOUBLE:
     case FLOAT:
     case INT:
     case LONG:
     case SHORT:
     case BOOLEAN:
     case STRING:
       di.skipBytes(2);
       break;
     case ENUM:
       di.skipBytes(4); // 2 * u2
       break;
     case CLASS:
       di.skipBytes(2);
       break;
     case ANNOTATION:
       readAnnotation(di);
       break;
     case ARRAY:
       final int count = di.readUnsignedShort();
       for (int i = 0; i < count; ++i) {
         readAnnotationElementValue(di);
       }
       break;
     default:
       throw new ClassFormatError(
           "Not a valid annotation element type tag: 0x" + Integer.toHexString(tag));
   }
 }
예제 #11
0
 private String readAnnotation(final DataInput di) throws IOException {
   final String rawTypeName = resolveUtf8(di);
   // num_element_value_pairs
   final int count = di.readUnsignedShort();
   if (DEBUG) {
     print("annotation elements count: %d", count);
   }
   for (int i = 0; i < count; ++i) {
     if (DEBUG) {
       print("element '%s'", resolveUtf8(di));
     } else {
       di.skipBytes(2);
     }
     readAnnotationElementValue(di);
   }
   return rawTypeName;
 }
  public void readObject(DataInput in) throws IOException {

    boolean sgIO = in.readBoolean();
    int nodeID = in.readInt();

    int nodeClassID = in.readShort();

    nodeClassName = null;

    if (nodeClassID == -1) nodeClassName = in.readUTF();

    readConstructorParams(in);

    if (nodeClassID != -1) {
      node = createNode();
      nodeClassName = node.getClass().getName();
    } else node = createNode(nodeClassName);

    if (sgIO) {
      if (control.getCurrentFileVersion() == 1)
        ((com.sun.j3d.utils.scenegraph.io.SceneGraphIO) node).readSceneGraphObject(in);
      else {
        int size = in.readInt();
        if (node instanceof com.sun.j3d.utils.scenegraph.io.SceneGraphIO) {
          byte[] bytes = new byte[size];
          in.readFully(bytes);
          ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
          DataInputStream tmpIn = new DataInputStream(byteStream);
          ((com.sun.j3d.utils.scenegraph.io.SceneGraphIO) node).readSceneGraphObject(tmpIn);
          tmpIn.close();
        } else {
          in.skipBytes(size);
        }
      }
    }

    symbol = control.getSymbolTable().createSymbol(this, node, nodeID);
    readUserData(in);
    if (control.getCurrentFileVersion() > 2) {
      node.setName(readString(in));
    }

    readCapabilities(in);
  }
예제 #13
0
  private void readAttributes(
      final DataInput di, final char reporterType, final boolean skipReporting) throws IOException {

    final int count = di.readUnsignedShort();
    if (DEBUG) {
      print("attribute count (%s) = %d", reporterType, count);
    }
    for (int i = 0; i < count; ++i) {
      final String name = resolveUtf8(di);
      // in bytes, use this to skip the attribute info block
      final int length = di.readInt();
      if (!skipReporting
          && ("RuntimeVisibleAnnotations".equals(name)
              || "RuntimeInvisibleAnnotations".equals(name))) {
        readAnnotations(di, reporterType);
      } else {
        if (DEBUG) {
          print("skip attribute %s", name);
        }
        di.skipBytes(length);
      }
    }
  }
예제 #14
0
 private void skip(int num) throws IOException {
   while (num > 0) {
     long result;
     if (in != null) {
       result = in.skip(num);
     } else {
       result = din.skipBytes(num);
     }
     if (result > 0) {
       num -= result;
     } else {
       if (in != null) {
         result = in.read();
       } else {
         result = din.readByte();
       }
       if (result == -1) {
         throw new IOException("Premature end of input.");
       } else {
         num--;
       }
     }
   }
 }
예제 #15
0
  /**
   * Factory method for creating <tt>AttributeInfo</tt> structures.
   *
   * <p>An <tt>AttributeInfo</tt> of the appropriate subtype from the <tt>attributes</tt> package is
   * created unless the type of the attribute is unknown in which case an instance of
   * <tt>AttributeInfo</tt> is returned.
   *
   * <p>
   *
   * <p>Attributes are skipped if the environment variable <tt>SYSTEM_PROPERTY_SKIP_ATTRIBUTES</tt>
   * is set to true.
   *
   * @param in the <tt>DataInput</tt> from which to read the <tt>AttributeInfo</tt> structure
   * @param classFile the parent class file of the structure to be created
   * @return the new <tt>AttributeInfo</tt> structure
   * @throws InvalidByteCodeException if the byte code is invalid
   * @throws IOException if an exception occurs with the <tt>DataInput</tt>
   */
  public static AttributeInfo createOrSkip(DataInput in, ClassFile classFile)
      throws InvalidByteCodeException, IOException {

    AttributeInfo attributeInfo = null;

    if (Boolean.getBoolean(SYSTEM_PROPERTY_SKIP_ATTRIBUTES)) {
      in.skipBytes(2);
      in.skipBytes(in.readInt());
    } else {
      int attributeNameIndex = in.readUnsignedShort();
      int attributeLength = in.readInt();

      ConstantUtf8Info cpInfoName = classFile.getConstantPoolUtf8Entry(attributeNameIndex);
      String attributeName = null;

      if (cpInfoName == null) {
        return null;
      }

      attributeName = cpInfoName.getString();

      if (ConstantValueAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new ConstantValueAttribute();

      } else if (CodeAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new CodeAttribute();

      } else if (ExceptionsAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new ExceptionsAttribute();

      } else if (InnerClassesAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new InnerClassesAttribute();

      } else if (SyntheticAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new SyntheticAttribute();

      } else if (SourceFileAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new SourceFileAttribute();

      } else if (LineNumberTableAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new LineNumberTableAttribute();

      } else if (LocalVariableTableAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new LocalVariableTableAttribute();

      } else if (DeprecatedAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new DeprecatedAttribute();

      } else if (EnclosingMethodAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new EnclosingMethodAttribute();

      } else if (SignatureAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new SignatureAttribute();

      } else if (LocalVariableTypeTableAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new LocalVariableTypeTableAttribute();

      } else if (RuntimeVisibleAnnotationsAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new RuntimeVisibleAnnotationsAttribute();

      } else if (RuntimeInvisibleAnnotationsAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new RuntimeInvisibleAnnotationsAttribute();

      } else if (AnnotationDefaultAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new AnnotationDefaultAttribute();

      } else if (BootstrapMethodsAttribute.ATTRIBUTE_NAME.equals(attributeName)) {
        attributeInfo = new BootstrapMethodsAttribute(attributeLength);

      } else {
        attributeInfo = new AttributeInfo(attributeLength);
      }
      attributeInfo.setAttributeNameIndex(attributeNameIndex);
      attributeInfo.setClassFile(classFile);
      attributeInfo.read(in);
    }

    return attributeInfo;
  }
예제 #16
0
 public static void skipCompressedByteArray(DataInput in) throws IOException {
   int length = in.readInt();
   if (length != -1) in.skipBytes(length);
 }
예제 #17
0
 private void readInterfaces(final DataInput di) throws IOException {
   final int count = di.readUnsignedShort();
   di.skipBytes(count * 2); // count * u2
 }
예제 #18
0
 private void readSuperClass(final DataInput di) throws IOException {
   di.skipBytes(2); // u2
 }
예제 #19
0
 private void readAccessFlags(final DataInput di) throws IOException {
   di.skipBytes(2); // u2
 }
 /**
  * skips samplesToSkip data points. It is up to the caller to insure that the type of SAC file
  * (iftype = LEVEN, IRLIM, IAMPH) and how many data points remain are compatible with the size of
  * the float array to be read.
  *
  * @throws IOException
  */
 public static int skipSamples(DataInput dataIn, int samplesToSkip) throws IOException {
   return dataIn.skipBytes(samplesToSkip * 4) / 4;
 }
 public int skipBytes(int n) throws IOException {
   return in.skipBytes(n);
 }
예제 #22
0
 public int skipBytes(int n) throws IOException {
   return dataInput.skipBytes(n);
 }