Java.io.PipedOutputStream-luokka Javassa

Java.io.PipedOutputStream-luokka Javassa

Java.io.PipedInputStream-luokka Javassa

io.PipedOutputStream-luokka Javassa


Putket IO:ssa tarjoavat linkin kahden JVM:ssä samanaikaisesti käynnissä olevan säikeen välillä. Joten putkia käytetään sekä lähteenä että määränpäänä.  

  • PipedInputStream liitetään myös PipedOutputStreamin kanssa. Joten dataa voidaan kirjoittaa käyttämällä PipedOutputStreamia ja PipedInputStreamia. Mutta molempien säikeiden käyttäminen samanaikaisesti luo umpikujan säikeille.
  • PipedOutputStream lähettää putken pään. Tiedot kirjoitetaan PipedOutputStreamiin. Putken sanotaan olevan rikki, jos PipedInputStream, joka luki tietoja, ei ole enää.

Ilmoitus:   

 public class PipedOutputStream   
extends OutputStream

Rakentaja:   

  • PipedOutputStream() : luo PipedOutputStreamin, jota ei ole yhdistetty.
  • PipedOutputStream(PipedOutputStream inStream) : luo PipedOutputStreamin että se 
    on yhdistetty PipedInputStreamiin - 'inStream'.

Menetelmät: 

write() : java.io.PipedOutputStream.write(int tavu) kirjoittaa tietyn tavun putkilähtövirtaan. 

Syntaksi: 

    public void write(int byte)     

Parameters :
byte : byte to be written

Return : void
Exception :
-> IOException : if in case IO error occurs.

write(byte[] puskurin int offset int maxlen) : java.io.PipedOutputStream.write(byte[] puskurin int offset int maxlen) kirjoittaa maxlen tavua dataa puskurista Piped Output Streamiin. Menetelmä estää, jos streamiin ei kirjoiteta tavuja. 

Syntaksi: 

    public void write(byte[] buffer int offset int maxlen)     

Parameters :
buffer : data of the buffer
offset : starting in the destination array - 'buffer'.
maxlen : maximum length of array to be read

Return : void
Exception :
-> IOException : if in case IO error occurs. Java
   // Java program illustrating the working of PipedInputStream   // write(byte[] buffer int offset int maxlen)   import     java.io.*  ;   public     class   NewClass   {      public     static     void     main  (  String  []     args  )     throws     IOException      {      PipedInputStream     geek_input     =     new     PipedInputStream  ();      PipedOutputStream     geek_output     =     new     PipedOutputStream  ();      // Use of connect() : connecting geek_input with geek_output      geek_input  .  connect  (  geek_output  );      byte  []     buffer     =     {  'J'       'A'       'V'       'A'  };      // Use of write(byte[] buffer int offset int maxlen)      geek_output  .  write  (  buffer       0       4  );      int     a     =     5  ;      System  .  out  .  print  (  'Use of write(buffer offset maxlen) : '  );      while  (  a  >  0  )      {      System  .  out  .  print  (  ' '     +     (  char  )     geek_input  .  read  ());      a  --  ;      }      }   }   

Lähtö: 

 Use of write(buffer offset maxlen) : J A V A   
  • close() : java.io.PipedOutputStream.close() sulkee Piped Output Streamin ja vapauttaa allokoidut resurssit. 
    Syntaksi: 
 public void close()   
Parameters :
--------------
Return :
void
Exception :
-> IOException : if in case IO error occurs.
  • connect(PipedInputStream-kohde) : java.io.PipedOutputStream.connect(PipedInputStream-kohde yhdistää Piped Output Streamin "kohde" Piped Input Streamiin ja jos "kohde" on putket jollain muulla stream IO -poikkeuksella 
    Syntaksi: 
 public void connect(PipedInputStream destination)   
Parameters :
destination : the Piped Input Stream to be connected to
Return :
void
Exception :
-> IOException : if in case IO error occurs.
  • flush() : java.io.PipedOutputStream.flush() huuhtelee Output Streamin. 
    Syntaksi: 
 public void flush()   
Parameters :
------------
Return :
void
Exception :
-> IOException : if in case IO error occurs.

Java-koodi, joka havainnollistaa PipedOutputStream-luokkamenetelmien toimintaa: 

Java
   // Java program illustrating the working of PipedInputStream   // write() write(byte[] buffer int offset int maxlen)   // close() flush() connect()   import     java.io.*  ;   public     class   NewClass   {      public     static     void     main  (  String  []     args  )     throws     IOException      {      PipedInputStream     geek_input     =     new     PipedInputStream  ();      PipedOutputStream     geek_output     =     new     PipedOutputStream  ();      try      {      // Use of connect() : connecting geek_input with geek_output      geek_input  .  connect  (  geek_output  );      // Use of write(int byte) :      geek_output  .  write  (  71  );      geek_output  .  write  (  69  );      geek_output  .  write  (  69  );      geek_output  .  write  (  75  );      geek_output  .  write  (  83  );      // Use of flush() method :      geek_output  .  flush  ();      System  .  out  .  println  (  'Use of flush() method : '  );      int     i     =     5  ;      while  (  i     >     0  )      {      System  .  out  .  print  (  ' '     +     (  char  )     geek_input  .  read  ());      i  --  ;      }      // USe of close() method :      System  .  out  .  println  (  'nClosing the Output stream'  );      geek_output  .  close  ();      }      catch     (  IOException     except  )      {      except  .  printStackTrace  ();      }      }   }   

Lähtö: 

 Use of flush() method :    
G E E K S
Closing the Output stream


 

Luo tietokilpailu