Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1.  public int read(String pn, Process p) //zwraca: /-1 - potok nie istnieje /-2 - pusty potok / -3 potok w stanie zapisu / 1 - odczytano
  2.     {
  3.         if(pipes.isEmpty())
  4.         {
  5.             if(sv==true)
  6.                 System.out.println("Nie mozna pobrac komunikatu! Potok: \"" + pn + "\" nie istnieje!");
  7.             return -1;
  8.         }
  9.         String ret="";
  10.  
  11.         int size=pipes.size();
  12.  
  13.  
  14.         int i; //przechowuje indeks potoku
  15.         for(i=0;i<size;i++)
  16.         {
  17.             if(pipes.elementAt(i).pipe_name.equals(pn))
  18.             {
  19.  
  20.                 if(this.open(pipes.elementAt(i), 'r')==1)
  21.                 {
  22.                     if(pipes.elementAt(i).messages.isEmpty()==false)
  23.                     {
  24.                         ret=pipes.elementAt(i).messages.firstElement();
  25.                         pipes.elementAt(i).messages.removeElementAt(0);
  26.  
  27.                         this.close(pipes.elementAt(i));
  28.                         int msize=p.getMEMEsize();
  29.                         for(int j=1;j<msize;j++)
  30.                         {
  31.                             if(p.getMEMEat(j)==' ' && p.getMEMEat(j+1)==' ')
  32.                             {
  33.                                 int off=msize-j;
  34.                                 int ret_length=ret.length();
  35.                                 for(int k=0;k<ret_length && k<off;k++)
  36.                                 {
  37.                                     j++;
  38.                                     p.setMEME(ret.charAt(k), j);
  39.                                 }
  40.                                 break;
  41.                             }
  42.                         }
  43.                         if(sv==true)
  44.                             System.out.println("Z potoku: \"" + pn + "\" odczytano komunikat: " + ret);
  45.                         return 1;
  46.                     }
  47.                     else
  48.                     {
  49.                         if(sv==true)
  50.                             System.out.println("Nie można pobrac komunikatu. Potok: \"" + pn + "\" jest pusty!");
  51.                         this.close(pipes.elementAt(i));
  52.                         return -2;
  53.                     }
  54.                 }
  55.                 else
  56.                 {
  57.                     if(sv==true)
  58.                         System.out.println("Nie można pobrac komunikatu. Potok: \"" + pn + "\" w stanie zapisu!");
  59.                     this.close(pipes.elementAt(i));
  60.                     return -3;
  61.                 }
  62.  
  63.             }
  64.  
  65.         }
  66.         if(sv==true)
  67.             System.out.println("Nie mozna pobrac komunikatu! Potok: \"" + pn + "\" nie istnieje!");
  68.         return -1;
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement