Advertisement
weeez

Simulation

Dec 16th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import encoding.*;
  2. import router.*;
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. public class Simulation{
  8.     public static void main(String[] args){
  9.         Node node = Network.createNetwork();
  10.         List<String> lista = new LinkedList<String>();
  11.        
  12.         String inputFile = args[0];
  13.         String outputFile = args[1];
  14.        
  15.         try(BufferedReader br = new BufferedReader(new FileReader(inputFile))){
  16.             PrintWriter pw = new PrintWriter(outputFile);
  17.             while(br.ready()){
  18.                 try{
  19.                     lista.clear();
  20.                     boolean jo = true;
  21.                     String sor = br.readLine();
  22.                     int vonalak_szama = 0;                 
  23.                     for(int i = 0; i < sor.length(); ++i){
  24.                         if(sor.charAt(i) == '|'){
  25.                             ++vonalak_szama;
  26.                         }
  27.                     }
  28.                     if(vonalak_szama != 1){
  29.                         jo = false;
  30.                     }
  31.                     if(jo){                    
  32.                         String[] sv = sor.split("@");
  33.                         String[] sv2 = sv[1].split("\\|");
  34.                         IPAddress ip = IPAddress.fromString(sv2[1]);
  35.                         Message msg = new Message(sv[0],sv2[0]);
  36.                         Packet<Message> csomag = new Packet<Message>(msg,ip);
  37.                         lista.add(node.tracePacket(csomag));
  38.                         try{
  39.                             String s = "";
  40.                             for(String f: lista){
  41.                                 s += f;
  42.                             }                      
  43.                             pw.print(s);
  44.                             pw.println();
  45.                         }
  46.                         catch(Exception e){
  47.                             System.err.println("Hiba tortent az iras soran!");
  48.                         }
  49.                     }
  50.                 }
  51.                 catch(Exception e){
  52.                 }
  53.             }
  54.             System.out.println("Sikeres fajl olvasas!");       
  55.             pw.close();
  56.             System.out.println("Sikeres fajl iras!");              
  57.         }
  58.         catch(FileNotFoundException e) {
  59.             System.err.println("Nem talalhato az inputfajl.");
  60.         }
  61.         catch(IOException e) {
  62.             System.err.println("IO hiba");
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement