Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7.  
  8. import com.ptibiscuit.coffeemachine.CoffeeMachine;
  9.  
  10. public class Controleur extends Thread
  11. {
  12.  
  13.     int m_port;
  14.     String message = "+";
  15.     String ligne;
  16.     String m_fichier;
  17.     ArrayList<String> al = new ArrayList<String>();
  18.  
  19.     public Controleur(int port, String fichier)
  20.     {
  21.         m_port = port;
  22.         m_fichier = fichier;
  23.     }
  24.    
  25.     public void run()
  26.     {
  27.         CoffeeMachine cofmach = new CoffeeMachine(m_port);
  28.         cofmach.addConnectionListener(new ConnectionManager());
  29.         cofmach.addDeconnectionListener(new ConnectionManager());
  30.         cofmach.addMessageListener(new ConnectionManager());
  31.         System.out.println("Serveur PluginLoumea - Version 1b");
  32.         System.out.println("--------------------");
  33.         System.out.println("Ecoute sur le port " + m_port + "...");
  34.        
  35.         try
  36.         {
  37.             cofmach.start();
  38.         }
  39.         catch (IOException e)
  40.         {
  41.             e.printStackTrace();
  42.         }
  43.        
  44.         this.ReadFile();
  45.        
  46.     }
  47.    
  48.     public void ReadFile()
  49.     {
  50.         try
  51.         {
  52.             InputStream is = new FileInputStream(m_fichier);
  53.             InputStreamReader isr = new InputStreamReader(is);
  54.             BufferedReader in = new BufferedReader(isr);
  55.            
  56.             while ((ligne = in.readLine()) != null)
  57.             {
  58.                 al.add(ligne);
  59.             }
  60.        
  61.            
  62.             for(int i = 0; i < al.size(); i++)
  63.             {
  64.                 message += al.get(i) + " ";
  65.             }
  66.            
  67.             message.trim();
  68.            
  69.         }
  70.         catch(Exception e)
  71.         {
  72.             e.printStackTrace();
  73.         }
  74.        
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement