示例#1
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;
  }
示例#2
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));
   }
 }