Ejemplo n.º 1
0
  private int Load_Nodes(DataInputStream inStream) {
    // need to open file and load data
    int node_id;
    int x_cor;
    int y_cor;
    // int n_nodes, n_edges, node_cnt, arrow_status;
    Node n;
    String line;
    String item1, item2, item3, item4;

    node_id = 0;
    x_cor = 0;
    y_cor = 0;
    // n_nodes = 0;
    // n_edges = 0;
    // arrow_status = -1;

    try {

      if ((line = inStream.readLine()) != null) {
        StringTokenizer Data = new StringTokenizer(line, " ");
        item1 = Data.nextToken();
        n_nodes = Integer.parseInt(item1);
        item2 = Data.nextToken();
        n_edges = Integer.parseInt(item2);
        item3 = Data.nextToken();
        arrow_status = Integer.parseInt(item3);
        // item4 = Data.nextToken();
        // type = Integer.parseInt( item4 );
        // graph = new GraphClass( n_nodes, n_edges, arrow_status );
        nodes = new Node[n_nodes];
        edges = new Edge[n_edges];

        // ???

        while ((this.Node_Cnt() < n_nodes) && ((line = inStream.readLine()) != null)) {
          Data = new StringTokenizer(line, " ");
          item1 = Data.nextToken();
          item2 = Data.nextToken();
          item3 = Data.nextToken();
          node_id = Integer.parseInt(item1);
          x_cor = Integer.parseInt(item2);
          y_cor = Integer.parseInt(item3);
          n = new Node(node_id, x_cor, y_cor);
          this.Add_Node(n);
        }
        if (n_nodes != 0) {
          source_node = nodes[0];
        }
      }
    } catch (IOException e) {
      System.err.println("error in file" + e.toString());
      System.exit(1);
    }
    return this.Node_Cnt();
  }
  private byte[] loadClassData(String name) throws IOException {
    FileInputStream f = new FileInputStream("CrashClass.class");
    int size = (int) f.getChannel().size();
    DataInputStream s = new DataInputStream(f);

    byte[] b = new byte[size];
    s.readFully(b);
    s.close();

    return b;
  }
Ejemplo n.º 3
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();
 }
  public void initilize2() {
    int i;
    msg = s2.toCharArray();
    for (i = 0; i < s2.length(); i++) {
      try {
        dos.write(msg[i]);
        // System.out.print(msg[i]);
      } catch (Exception e) {
        System.out.print("init 2 send" + e);
      }
    }

    try {

      while ((rs = dis.readLine()) != null) {
        // System.out.println(rs);
        if (rs.equals("OK")) {
          break;
        }
        if (rs.equals("ERROR")) {
          break;
        }
      }

    } catch (Exception e) {
      System.out.println("init 2 rec" + e);
    }
  }
Ejemplo n.º 5
0
  private int Load_Edges(DataInputStream inStream, int num) {
    String line;
    String item1, item2, item3;
    int source_node;
    int dest_node;
    int value;
    int n_nodes, edge_cnt;
    // Node nodes_array[] = new Node[num]; // Wil
    Edge edge;
    n_nodes = num;
    Node nodes_array[];
    nodes_array = new Node[n_nodes];
    nodes_array = this.Node_Array(); // Wil
    edge_cnt = 0;

    try {
      while ((line = inStream.readLine()) != null) {
        StringTokenizer Data = new StringTokenizer(line, " ");
        item1 = Data.nextToken();
        item2 = Data.nextToken();
        item3 = Data.nextToken();
        source_node = Integer.parseInt(item1);
        dest_node = Integer.parseInt(item2);
        value = Integer.parseInt(item3);
        edge = new Edge(nodes_array[source_node - 1], nodes_array[dest_node - 1], value);
        this.Add_Edge(edge);
        edge_cnt++;
      }
      // inFile.close();
    } catch (IOException e) {
      System.err.println("Error in accessing URL: " + e.toString());
      System.exit(1);
    }
    return edge_cnt;
  }
Ejemplo n.º 6
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));
 }
Ejemplo n.º 7
0
 // --------------------------------------------------
 public void close() {
   try {
     is.close();
     os.close();
     socket.close();
     responseArea.appendText("***Connection closed" + "\n");
   } catch (IOException e) {
     responseArea.appendText("IO Exception" + "\n");
   }
 }
Ejemplo n.º 8
0
 // --------------------------------------------------
 public void run() {
   String inputLine;
   try {
     while ((inputLine = is.readLine()) != null) {
       responseArea.appendText(inputLine + "\n");
     }
   } catch (IOException e) {
     responseArea.appendText("IO Exception" + "\n");
   }
 }
 public void connectionclose() {
   try {
     is.close();
     os.close();
     dis.close();
     dos.close();
     sPort.close();
   } catch (Exception e) {
     System.out.println("close" + e);
   }
 }
Ejemplo n.º 10
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));
   }
 }
  public void read() {
    int i, j, k;
    String temp = "";
    String temp1 = "";

    msg = s3.toCharArray();
    for (i = 0; i < s3.length(); i++) {
      try {
        dos.write(msg[i]);
        // System.out.println(msg[i]);
      } catch (Exception e) {
        System.out.print("read send" + e);
      }
    }
    try {
      while ((rs = dis.readLine()) != null) {
        temp += rs;
        if (rs.equals("OK")) break;
        if (rs.equals("ERROR")) break;
      }

      k = 0;
      StringTokenizer t = new StringTokenizer(temp, "\"");
      while (t.hasMoreTokens()) {
        temp1 = "" + t.nextToken().trim();
        k++;
        if (k == 7) {
          System.out.println(temp1);
          VoiceManager voiceManager = VoiceManager.getInstance();
          Voice helloVoice = voiceManager.getVoice("kevin");
          helloVoice.allocate();
          helloVoice.speak(temp1);
          helloVoice.deallocate();
        }
      }

    } catch (Exception e) {
      System.out.print("read rec" + e);
    }
  }
  public void delete() {
    int i;
    msg = s4.toCharArray();
    try {
      for (i = 0; i < s4.length(); i++) {
        dos.write(msg[i]);
        System.out.print(msg[i]);
      }

    } catch (Exception e) {
      System.out.print("del send" + e);
    }
    try {
      while ((rs = dis.readLine()) != null) {
        System.out.println(rs);
        if (rs.equals("OK")) break;
        if (rs.equals("ERROR")) break;
        if (rs.equals("+CMS ERROR: 321")) break;
      }
    } catch (Exception e) {
      System.out.print("del rec" + e);
    }
  }
Ejemplo n.º 13
0
 private void fillBuffer() throws Exception {
   bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
   if (bytesRead == -1) buffer[0] = -1;
 }