示例#1
0
 protected void processOtherMsg(int msgsize, int msgtype, DataInputStream dIn)
     throws SocketException, IOException, java.lang.NullPointerException {
   dIn.skipBytes(msgsize - 2); // need to just skip this message because we don't recognize it
   ExpCoordinator.printer.print(
       new String("NCCPConnection.processOtherMsg skipping message " + msgsize + " " + msgtype));
   ExpCoordinator.printer.printHistory();
 }
示例#2
0
 public MessageRunnable(int msz, int mtp, DataInputStream di)
     throws IOException, SocketException {
   msgsize = msz;
   msgtype = mtp;
   msgbytes = new byte[msgsize - 2];
   di.readFully(msgbytes);
   // di.read(msgbytes);
   din = new DataInputStream(new ByteArrayInputStream(msgbytes));
 }
示例#3
0
  protected void read(DataInputStream s) {
    try {
      ref = new WeakReference<DataBuffer>(this, Nd4j.bufferRefQueue());
      referencing = Collections.synchronizedSet(new HashSet<String>());
      dirty = new AtomicBoolean(false);
      allocationMode = AllocationMode.valueOf(s.readUTF());
      length = s.readInt();
      Type t = Type.valueOf(s.readUTF());
      if (t == Type.DOUBLE) {
        if (allocationMode == AllocationMode.HEAP) {
          if (this.dataType() == Type.FLOAT) { // DataBuffer type
            // double -> float
            floatData = new float[length()];
          } else if (this.dataType() == Type.DOUBLE) {
            // double -> double
            doubleData = new double[length()];
          } else {
            // double -> int
            intData = new int[length()];
          }
          for (int i = 0; i < length(); i++) {
            put(i, s.readDouble());
          }
        } else {
          wrappedBuffer = ByteBuffer.allocateDirect(length() * getElementSize());
          wrappedBuffer.order(ByteOrder.nativeOrder());
          for (int i = 0; i < length(); i++) {
            put(i, s.readDouble());
          }
        }
      } else {
        if (allocationMode == AllocationMode.HEAP) {
          if (this.dataType() == Type.FLOAT) { // DataBuffer type
            // float -> float
            floatData = new float[length()];
          } else if (this.dataType() == Type.DOUBLE) {
            // float -> double
            doubleData = new double[length()];
          } else {
            // float-> int
            intData = new int[length()];
          }
          for (int i = 0; i < length(); i++) {
            put(i, s.readFloat());
          }
        } else {
          wrappedBuffer = ByteBuffer.allocateDirect(length() * getElementSize());
          wrappedBuffer.order(ByteOrder.nativeOrder());
          for (int i = 0; i < length(); i++) {
            put(i, s.readFloat());
          }
        }
      }

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
示例#4
0
  /**
   * Reads an image from an archived file and return it as ByteBuffer object.
   *
   * @author Mike Butler, Kiet Le
   */
  private ByteBuffer readImage(String filename, Dimension dim) {
    if (dim == null) dim = new Dimension(0, 0);
    ByteBuffer bytes = null;
    try {
      DataInputStream dis =
          new DataInputStream(getClass().getClassLoader().getResourceAsStream(filename));
      dim.width = dis.readInt();
      dim.height = dis.readInt();
      System.out.println("Creating buffer, width: " + dim.width + " height: " + dim.height);
      // byte[] buf = new byte[3 * dim.height * dim.width];
      bytes = BufferUtil.newByteBuffer(3 * dim.width * dim.height);
      for (int i = 0; i < bytes.capacity(); i++) {
        bytes.put(dis.readByte());
      }
      dis.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
    bytes.rewind();
    return bytes;
  }
示例#5
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));
   }
 }