Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int read(String pn, Process p) //zwraca: /-1 - potok nie istnieje /-2 - pusty potok / -3 potok w stanie zapisu / 1 - odczytano
- {
- if(pipes.isEmpty())
- {
- if(sv==true)
- System.out.println("Nie mozna pobrac komunikatu! Potok: \"" + pn + "\" nie istnieje!");
- return -1;
- }
- String ret="";
- int size=pipes.size();
- int i; //przechowuje indeks potoku
- for(i=0;i<size;i++)
- {
- if(pipes.elementAt(i).pipe_name.equals(pn))
- {
- if(this.open(pipes.elementAt(i), 'r')==1)
- {
- if(pipes.elementAt(i).messages.isEmpty()==false)
- {
- ret=pipes.elementAt(i).messages.firstElement();
- pipes.elementAt(i).messages.removeElementAt(0);
- this.close(pipes.elementAt(i));
- int msize=p.getMEMEsize();
- for(int j=1;j<msize;j++)
- {
- if(p.getMEMEat(j)==' ' && p.getMEMEat(j+1)==' ')
- {
- int off=msize-j;
- int ret_length=ret.length();
- for(int k=0;k<ret_length && k<off;k++)
- {
- j++;
- p.setMEME(ret.charAt(k), j);
- }
- break;
- }
- }
- if(sv==true)
- System.out.println("Z potoku: \"" + pn + "\" odczytano komunikat: " + ret);
- return 1;
- }
- else
- {
- if(sv==true)
- System.out.println("Nie można pobrac komunikatu. Potok: \"" + pn + "\" jest pusty!");
- this.close(pipes.elementAt(i));
- return -2;
- }
- }
- else
- {
- if(sv==true)
- System.out.println("Nie można pobrac komunikatu. Potok: \"" + pn + "\" w stanie zapisu!");
- this.close(pipes.elementAt(i));
- return -3;
- }
- }
- }
- if(sv==true)
- System.out.println("Nie mozna pobrac komunikatu! Potok: \"" + pn + "\" nie istnieje!");
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement