public void nick_name(String msg) { try { String name = msg.substring(13); this.setName(name); Vector v = father.onlineList; boolean isRepeatedName = false; int size = v.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) v.get(i); if (tempSat.getName().equals(name)) { isRepeatedName = true; break; } } if (isRepeatedName == true) { dout.writeUTF("<#NAME_REPEATED#>"); din.close(); dout.close(); sc.close(); flag = false; } else { v.add(this); father.refreshList(); String nickListMsg = ""; StringBuilder nickListMsgSb = new StringBuilder(); size = v.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) v.get(i); nickListMsgSb.append("!"); nickListMsgSb.append(tempSat.getName()); } nickListMsgSb.append("<#NICK_LIST#>"); nickListMsg = nickListMsgSb.toString(); Vector tempv = father.onlineList; size = tempv.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i); tempSat.dout.writeUTF(nickListMsg); if (tempSat != this) { tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is now online...."); } } } } catch (IOException e) { e.printStackTrace(); } }
// Run selected test cases. private void runTests() { for (int i = 0; i < tests.size(); i++) { // If box for test is checked, run it. if (tests.get(i).isSelected()) { // Get the URLs of all of the required files. String folderURL = tests.get(i).getText(); String testURL = folderURL.concat(folderURL.substring(folderURL.lastIndexOf('/'))); String efgFile = testURL + ".EFG"; String guiFile = testURL + ".GUI"; String tstFile = testURL + ".TST"; String prgFile = testURL + ".PRG"; // attempt to read in file with program's parameters try { FileInputStream fstream = new FileInputStream(prgFile); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); HashMap<String, String> prgParams = new HashMap<String, String>(); String strLine; while ((strLine = br.readLine()) != null) { // add found parameters into prgParams as <key, value> String[] matches = strLine.split("="); prgParams.put(matches[0], matches[1]); } if (prgParams.containsKey("path") && prgParams.containsKey("main")) { programPath = prgParams.get("path"); mainClass = prgParams.get("main"); } in.close(); } catch (Exception e) { System.err.println(e.getMessage()); } System.out.println("We hit Run"); // Run the replayer using the three test files. System.out.println( "../../../dist/guitar/jfc-replayer.sh -cp " + programPath + " -c " + mainClass + " -g " + guiFile + " -e " + efgFile + " -t " + tstFile); try { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec( "../../../dist/guitar/jfc-replayer.sh -cp " + programPath + " -c " + mainClass + " -g " + guiFile + " -e " + efgFile + " -t " + tstFile); // InputStream ips = proc.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } catch (Exception e) { e.printStackTrace(); } } } }