Exemplo n.º 1
0
  public void unmarshal(DataInputStream dis) {
    super.unmarshal(dis);

    try {
      minefieldID.unmarshal(dis);
      requestingEntityID.unmarshal(dis);
      requestID = (short) dis.readUnsignedByte();
      numberOfPerimeterPoints = (short) dis.readUnsignedByte();
      pad2 = (short) dis.readUnsignedByte();
      numberOfSensorTypes = (short) dis.readUnsignedByte();
      dataFilter = dis.readInt();
      requestedMineType.unmarshal(dis);
      for (int idx = 0; idx < numberOfPerimeterPoints; idx++) {
        Point anX = new Point();
        anX.unmarshal(dis);
        requestedPerimeterPoints.add(anX);
      }

      for (int idx = 0; idx < numberOfSensorTypes; idx++) {
        TwoByteChunk anX = new TwoByteChunk();
        anX.unmarshal(dis);
        sensorTypes.add(anX);
      }

    } // end try
    catch (Exception e) {
      System.out.println(e);
    }
  } // end of unmarshal method
Exemplo n.º 2
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);
  }
Exemplo n.º 3
0
  public void writeStream(DataInputStream input) throws IOException, NoSuchAlgorithmException {
    try {
      int bytesRead = 0;
      int bytesToSkip = 0;

      while (true) {
        final int value = input.readUnsignedByte();
        bytesRead++;
        check.nextByte(value);
        writeRaw(value);
        final int weakChecksum = check.weakChecksum();
        String strongChecksum = null;

        if (bytesToSkip > 0) {
          bytesToSkip--;
        } else {
          Map<String, Integer> weakMatches = inputBlocks.get(weakChecksum);
          if (weakMatches != null) {
            strongChecksum = check.strongChecksum();
            Integer previousOffset = weakMatches.get(strongChecksum);
            if (previousOffset != null) {
              snipRawBuffer();
              System.err.println(
                  "Using previously remembered : "
                      + previousOffset
                      + " : "
                      + (bytesRead - BLOCK_SIZE));
              writeBlock(previousOffset);
              bytesToSkip = BLOCK_SIZE - 1;
            }
          }
        }

        if ((bytesRead % BLOCK_SIZE) == 0) {
          Map<String, Integer> weakMatches = inputBlocks.get(weakChecksum);
          if (weakMatches == null) {
            weakMatches = new HashMap<String, Integer>();
            inputBlocks.put(weakChecksum, weakMatches);
          }
          if (strongChecksum == null) {
            strongChecksum = check.strongChecksum();
          }
          if (!weakMatches.containsKey(strongChecksum)) {
            weakMatches.put(strongChecksum, bytesRead - BLOCK_SIZE);
            System.err.println(
                "Remembering : "
                    + weakChecksum
                    + " : "
                    + strongChecksum
                    + " : "
                    + (bytesRead - BLOCK_SIZE));
          }
        }
      }
    } catch (EOFException e) {
      flushRaw();
    }
    System.err.println("Original data: " + rawChunks);
    System.err.println("Reused data: " + blockChunks);
  }
Exemplo n.º 4
0
  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
Exemplo n.º 5
0
 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
  /** 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();
    }
  }