/**
   * Constructor. Create an Exceptions attribute from a data stream.
   *
   * @param in The data stream of the class file.
   * @param nameIndex The index into the constant pool of the name of the attribute.
   * @param length The length of the attribute, excluding the header.
   * @exception IOException If an error occurs while reading.
   */
  public Exceptions(ClassFile clazz, DataInputStream in, int nameIndex, int length)
      throws IOException {
    super(nameIndex, length);

    this.clazz = clazz;

    int count = in.readUnsignedShort();

    exceptions = new int[count];

    for (int i = 0; i < count; i++) {
      exceptions[i] = in.readUnsignedShort();
    }
  }
Beispiel #2
0
  /**
   * Read the class's name, superclass, and interfaces.
   *
   * @param in The stream from which to read.
   * @exception IOException If an error occurs while reading.
   */
  void readClassInfo(DataInputStream in) throws IOException {
    int index;

    thisClass = in.readUnsignedShort();
    superClass = in.readUnsignedShort();

    int numInterfaces = in.readUnsignedShort();

    interfaces = new int[numInterfaces];

    for (int i = 0; i < numInterfaces; i++) {
      interfaces[i] = in.readUnsignedShort();
    }
  }
Beispiel #3
0
  /**
   * Read a constant from the constant pool.
   *
   * @param in The stream from which to read.
   * @return The constant.
   * @exception IOException If an error occurs while reading.
   */
  Constant readConstant(DataInputStream in) throws IOException {
    int tag = in.readUnsignedByte();
    Object value;

    switch (tag) {
      case Constant.CLASS:
      case Constant.STRING:
      case Constant.METHOD_TYPE: // @since 1.8
        value = Integer.valueOf(in.readUnsignedShort());
        break;
      case Constant.FIELD_REF:
      case Constant.METHOD_REF:
      case Constant.INTERFACE_METHOD_REF:
      case Constant.NAME_AND_TYPE:
      case Constant.INVOKE_DYNAMIC: // @since 1.8
        value = new int[2];

        ((int[]) value)[0] = in.readUnsignedShort();
        ((int[]) value)[1] = in.readUnsignedShort();
        break;
      case Constant.INTEGER:
        value = Integer.valueOf(in.readInt());
        break;
      case Constant.FLOAT:
        value = Float.valueOf(in.readFloat());
        break;
      case Constant.LONG:
        // Longs take up 2 constant pool entries.
        value = Long.valueOf(in.readLong());
        break;
      case Constant.DOUBLE:
        // Doubles take up 2 constant pool entries.
        value = Double.valueOf(in.readDouble());
        break;
      case Constant.UTF8:
        value = in.readUTF();
        break;
      case Constant.METHOD_HANDLE: // @since 1.8
        value = new int[2];

        ((int[]) value)[0] = in.readUnsignedByte();
        ((int[]) value)[1] = in.readUnsignedShort();
        break;
      default:
        throw new ClassFormatError("Invalid constant tag: " + tag);
    }

    return new Constant(tag, value);
  }
  public void unmarshal(DataInputStream dis) {
    super.unmarshal(dis);

    try {
      minefieldID.unmarshal(dis);
      requestingEntityID.unmarshal(dis);
      minefieldSequenceNumbeer = (int) dis.readUnsignedShort();
      requestID = (short) dis.readUnsignedByte();
      pduSequenceNumber = (short) dis.readUnsignedByte();
      numberOfPdus = (short) dis.readUnsignedByte();
      numberOfMinesInThisPdu = (short) dis.readUnsignedByte();
      numberOfSensorTypes = (short) dis.readUnsignedByte();
      pad2 = (short) dis.readUnsignedByte();
      dataFilter = dis.readInt();
      mineType.unmarshal(dis);
      for (int idx = 0; idx < numberOfSensorTypes; idx++) {
        TwoByteChunk anX = new TwoByteChunk();
        anX.unmarshal(dis);
        sensorTypes.add(anX);
      }

      pad3 = (short) dis.readUnsignedByte();
      for (int idx = 0; idx < numberOfMinesInThisPdu; idx++) {
        Vector3Float anX = new Vector3Float();
        anX.unmarshal(dis);
        mineLocation.add(anX);
      }

    } // end try
    catch (Exception e) {
      System.out.println(e);
    }
  } // end of unmarshal method
 public void unmarshal(DataInputStream dis) {
   try {
     recordType = (short) dis.readUnsignedByte();
     changeIndicator = (short) dis.readUnsignedByte();
     associationStatus = (short) dis.readUnsignedByte();
     associationType = (short) dis.readUnsignedByte();
     entityID.unmarshal(dis);
     ownStationLocation = (int) dis.readUnsignedShort();
     physicalConnectionType = (short) dis.readUnsignedByte();
     groupMemberType = (short) dis.readUnsignedByte();
     groupNumber = (int) dis.readUnsignedShort();
   } // end try
   catch (Exception e) {
     System.out.println(e);
   }
 } // end of unmarshal method
 /**
  * Reads a <code>MethodInfo</code> from an input stream.
  *
  * @param cf The class file defining the method.
  * @param in The input stream to read from.
  * @return The method information read.
  * @throws IOException If an IO error occurs.
  */
 public static MethodInfo read(ClassFile cf, DataInputStream in) throws IOException {
   int accessFlags = in.readUnsignedShort();
   int nameIndex = in.readUnsignedShort();
   int descriptorIndex = in.readUnsignedShort();
   MethodInfo mi = new MethodInfo(cf, accessFlags, nameIndex, descriptorIndex);
   int attrCount = in.readUnsignedShort();
   for (int j = 0; j < attrCount; j++) {
     AttributeInfo ai = mi.readAttribute(in);
     if (ai instanceof Signature) {
       mi.signatureAttr = (Signature) ai;
     } else if (ai instanceof Code) {
       mi.codeAttr = (Code) ai;
     } else if (ai != null) {
       mi.addAttribute(ai);
     }
   }
   return mi;
 }
Beispiel #7
0
  /**
   * Read the class's methods.
   *
   * @param in The stream from which to read.
   * @exception IOException If an error occurs while reading.
   */
  void readMethods(DataInputStream in) throws IOException {
    int numMethods = in.readUnsignedShort();

    methods = new Method[numMethods];

    for (int i = 0; i < numMethods; i++) {
      methods[i] = createMethod(in);
    }
  }
Beispiel #8
0
  /**
   * Read the class's fields.
   *
   * @param in The stream from which to read.
   * @exception IOException If an error occurs while reading.
   */
  void readFields(DataInputStream in) throws IOException {
    int numFields = in.readUnsignedShort();

    fields = new Field[numFields];

    for (int i = 0; i < numFields; i++) {
      fields[i] = createField(in);
    }
  }
Beispiel #9
0
  /**
   * Read the class file header.
   *
   * @param in The stream from which to read.
   * @exception IOException If an error occurs while reading.
   */
  void readHeader(DataInputStream in) throws IOException {
    int magic = in.readInt();

    if (magic != 0xCAFEBABE) {
      throw new ClassFormatError("Bad magic number.");
    }

    int major = in.readUnsignedShort();
    int minor = in.readUnsignedShort();
  }
Beispiel #10
0
  /**
   * Read the class's attributes. Since none of the attributes are required, just read the length of
   * each attribute and skip that many bytes.
   *
   * @param in The stream from which to read.
   * @exception IOException If an error occurs while reading.
   */
  public void readAttributes(DataInputStream in) throws IOException {
    int numAttributes = in.readUnsignedShort();

    attrs = new Attribute[numAttributes];

    for (int i = 0; i < numAttributes; i++) {
      int nameIndex = in.readUnsignedShort();
      int length = in.readInt();
      String name = (String) constants[nameIndex].value();
      Attribute a = createAttribute(in, name, nameIndex, length);
      if (a != null) {
        attrs[i] = a;
      } else {
        long n = in.skip(length);
        if (n != length) {
          throw new EOFException();
        }
      }
    }
  }
  public void unmarshal(DataInputStream dis) {
    super.unmarshal(dis);

    try {
      entityId.unmarshal(dis);
      communicationsDeviceID = (int) dis.readUnsignedShort();
      encodingScheme = (int) dis.readUnsignedShort();
      tdlType = (int) dis.readUnsignedShort();
      sampleRate = dis.readInt();
      dataLength = (int) dis.readUnsignedShort();
      samples = (int) dis.readUnsignedShort();
      for (int idx = 0; idx < dataLength; idx++) {
        OneByteChunk anX = new OneByteChunk();
        anX.unmarshal(dis);
        data.add(anX);
      }

    } // end try
    catch (Exception e) {
      System.out.println(e);
    }
  } // end of unmarshal method
  /**
   * Reads an attribute for this method from the specified input stream.
   *
   * @param in The input stream to read from.
   * @return The attribute read, possibly <code>null</code> if it was known to be unimportant for
   *     our purposes.
   * @throws IOException If an IO error occurs.
   */
  private AttributeInfo readAttribute(DataInputStream in) throws IOException {

    AttributeInfo ai = null;

    int attributeNameIndex = in.readUnsignedShort();
    int attributeLength = in.readInt();

    String attrName = cf.getUtf8ValueFromConstantPool(attributeNameIndex);

    if (CODE.equals(attrName)) { // 4.7.3
      ai = Code.read(this, in);
    } else if (EXCEPTIONS.equals(attrName)) { // 4.7.4
      int exceptionCount = in.readUnsignedShort();
      int[] exceptionIndexTable = null;
      if (exceptionCount > 0) {
        exceptionIndexTable = new int[exceptionCount];
        for (int i = 0; i < exceptionCount; i++) {
          exceptionIndexTable[i] = in.readUnsignedShort();
        }
      }
      Exceptions e = new Exceptions(this, exceptionIndexTable);
      ai = e;
    }

    // TODO: Handle other Attribute types.

    // Attributes common to all members, or unhandled attributes.
    else {
      ai = super.readAttribute(in, attrName, attributeLength);
      //			if (ai!=null) { // "Deprecated" attribute returns null
      //				System.out.println("-------------- " + ai.getName());
      //			}
    }

    return ai;
  }
Beispiel #13
0
  /**
   * Read the class's constant pool. Constants in the constant pool are modeled by an array of
   * <tt>reflect.Constant</tt>/
   *
   * @param in The stream from which to read.
   * @exception IOException If an error occurs while reading.
   * @see Constant
   * @see #constants
   */
  void readConstantPool(DataInputStream in) throws IOException {
    int count = in.readUnsignedShort();

    constants = new Constant[count];

    // The first constant is reserved for internal use by the JVM.
    constants[0] = null;

    // Read the constants.
    for (int i = 1; i < count; i++) {
      constants[i] = readConstant(in);

      switch (constants[i].tag()) {
        case Constant.LONG:
        case Constant.DOUBLE:
          // Longs and doubles take up 2 constant pool entries.
          constants[++i] = null;
          break;
      }
    }
  }
Beispiel #14
0
 public void processMessage(DataInputStream dataIn) throws IOException {
   count = 0;
   int msgsize = dataIn.readInt();
   count = 1;
   int msgtype = 0;
   if (msgsize >= 2) msgtype = dataIn.readUnsignedShort();
   else {
     if (msgsize == 1) dataIn.readByte();
     ExpCoordinator.printer.print(
         new String("ERROR:NCCPConnection.run msgsize(" + msgsize + ") < 2 msgtype = " + msgtype));
     ExpCoordinator.printer.printHistory();
     return;
   }
   count = 2;
   switch (msgtype) {
     case NCCP.MessageResponse:
       ExpCoordinator.print(
           new String(
               "NCCPConnection::run message is  NCCP.MessageResponse " + msgsize + " " + msgtype),
           3);
       MessageRunnable tmp_msg = new MessageRunnable(msgsize, msgtype, dataIn);
       tmp_msg.print(5);
       SwingUtilities.invokeLater(tmp_msg);
       break;
     case NCCP.MessagePeriodic:
       ExpCoordinator.printer.print(
           new String(
               "NCCPConnection::run message is  NCCP.MessagePeriodic " + msgsize + " " + msgtype),
           3);
       processPeriodicMsg(msgsize, msgtype, dataIn);
       break;
     default:
       ExpCoordinator.printer.print(
           new String("NCCPConnection::run message is  Other " + msgsize + " " + msgtype));
       SwingUtilities.invokeLater(new MessageRunnable(msgsize, msgtype, dataIn));
   }
 }
  /** Process multiplexing protocol received from underlying connection. */
  public void run() throws IOException {
    try {
      int op, id, length;
      MultiplexConnectionInfo info;

      while (true) {

        // read next op code from remote endpoint
        op = dataIn.readUnsignedByte();
        switch (op) {

            // remote endpoint initiating new connection
          case OPEN:
            id = dataIn.readUnsignedShort();

            if (multiplexLog.isLoggable(Log.VERBOSE)) {
              multiplexLog.log(Log.VERBOSE, "operation  OPEN " + id);
            }

            info = connectionTable.get(id);
            if (info != null) throw new IOException("OPEN: Connection ID already exists");
            info = new MultiplexConnectionInfo(id);
            info.in = new MultiplexInputStream(this, info, 2048);
            info.out = new MultiplexOutputStream(this, info, 2048);
            synchronized (connectionTable) {
              connectionTable.put(id, info);
              ++numConnections;
            }
            sun.rmi.transport.Connection conn;
            conn = new TCPConnection(channel, info.in, info.out);
            channel.acceptMultiplexConnection(conn);
            break;

            // remote endpoint closing connection
          case CLOSE:
            id = dataIn.readUnsignedShort();

            if (multiplexLog.isLoggable(Log.VERBOSE)) {
              multiplexLog.log(Log.VERBOSE, "operation  CLOSE " + id);
            }

            info = connectionTable.get(id);
            if (info == null) throw new IOException("CLOSE: Invalid connection ID");
            info.in.disconnect();
            info.out.disconnect();
            if (!info.closed) sendCloseAck(info);
            synchronized (connectionTable) {
              connectionTable.remove(id);
              --numConnections;
            }
            break;

            // remote endpoint acknowledging close of connection
          case CLOSEACK:
            id = dataIn.readUnsignedShort();

            if (multiplexLog.isLoggable(Log.VERBOSE)) {
              multiplexLog.log(Log.VERBOSE, "operation  CLOSEACK " + id);
            }

            info = connectionTable.get(id);
            if (info == null) throw new IOException("CLOSEACK: Invalid connection ID");
            if (!info.closed) throw new IOException("CLOSEACK: Connection not closed");
            info.in.disconnect();
            info.out.disconnect();
            synchronized (connectionTable) {
              connectionTable.remove(id);
              --numConnections;
            }
            break;

            // remote endpoint declaring additional bytes receivable
          case REQUEST:
            id = dataIn.readUnsignedShort();
            info = connectionTable.get(id);
            if (info == null) throw new IOException("REQUEST: Invalid connection ID");
            length = dataIn.readInt();

            if (multiplexLog.isLoggable(Log.VERBOSE)) {
              multiplexLog.log(Log.VERBOSE, "operation  REQUEST " + id + ": " + length);
            }

            info.out.request(length);
            break;

            // remote endpoint transmitting data packet
          case TRANSMIT:
            id = dataIn.readUnsignedShort();
            info = connectionTable.get(id);
            if (info == null) throw new IOException("SEND: Invalid connection ID");
            length = dataIn.readInt();

            if (multiplexLog.isLoggable(Log.VERBOSE)) {
              multiplexLog.log(Log.VERBOSE, "operation  TRANSMIT " + id + ": " + length);
            }

            info.in.receive(length, dataIn);
            break;

          default:
            throw new IOException("Invalid operation: " + Integer.toHexString(op));
        }
      }
    } finally {
      shutDown();
    }
  }
Beispiel #16
0
 /**
  * Read the class's access flags.
  *
  * @param in The stream from which to read.
  * @exception IOException If an error occurs while reading.
  */
 void readAccessFlags(DataInputStream in) throws IOException {
   modifiers = in.readUnsignedShort();
 }