цеви ин ИО обезбеђује везу између две нити које се истовремено покрећу у ЈВМ-у. Дакле, цеви се користе и као извор и као одредиште.
- ПипедИнпутСтреам се такође преноси са ПипедОутпутСтреам. Дакле, подаци се могу писати помоћу ПипедОутпутСтреам-а и могу се писати помоћу ПипедИнпутСтреам-а. Али коришћење обе нити у исто време ће створити застој за нити.
- Каже се да је цев прекинута ако нит која је обезбеђивала бајтове података повезаном цевоводном излазном току више није жива.
Декларација: public class PipedInputStream extends InputStream
Конструктор: | ПипедИнпутСтреам() : | креира ПипедИнпутСтреам који није повезан.
| ПипедИнпутСтреам(инт пСизе) : | креира ПипедИнпутСтреам који није повезан са наведеном величином цеви.
| ПипедИнпутСтреам(ПипедОутпутСтреам оутСтреам) : | креира ПипедИнпутСтреам који је повезан са ПипедОутпутСтреам - 'оутСтреам'.
| ПипедИнпутСтреам(ПипедОутпутСтреам оутСтреам инт пСизе) : | креира цевоводни улазни ток који је повезан на цевоводни излазни ток са наведеном величином цеви. Методе: | инт реад(): | Reads the next byte of data from this piped input stream.The value byte is returned as an int in the range 0 to 255. This method blocks until input data is available the end of the stream is detected or an exception is thrown. Java // Java program illustrating the working of read() method 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 read() method : geek_output . write ( 71 ); System . out . println ( 'using read() : ' + ( char ) geek_input . read ()); geek_output . write ( 69 ); System . out . println ( 'using read() : ' + ( char ) geek_input . read ()); geek_output . write ( 75 ); System . out . println ( 'using read() : ' + ( char ) geek_input . read ()); } catch ( IOException except ) { except . printStackTrace (); } } } Излаз : using read() : G using read() : E using read() : K
| реад(бите[] бафер инт оффсет инт маклен) : | јава.ио.ПипедИнпутСтреам.реад(бите[] буффер инт оффсет инт маклен) чита до маклен бајтова података из цевоводног улазног тока у низ бафера. Метод се блокира ако се достигне крај стрима или се избаци изузетак. Синтакса: public int read(byte[] buffer int offset int maxlen) Parameters : buffer : the destination buffer into which the data is to be read offset : starting in the destination array - 'buffer'. maxlen : maximum length of array to be read Return : next 'maxlen' bytes of the data as an integer value return -1 is end of stream is reached Exception : -> IOException : if in case IO error occurs. -> NullPointerException : if buffer is null. -> IndexOutOfBoundsException : if offset is -ve or maxlen is -ve or maxlen > buffer.length - offset.
| прими (инт бајт): | јава.ио.ПипедИнпутСтреам.рецеиве(инт бите) прима бајт података. Ако улаз није доступан, метода се блокира. Синтакса: protected void receive(int byte) Parameters : byte : the bytes of the data received Return : void Exception : -> IOException : if in case IO error occurs or pipe is broken.
| цлосе(): | јава.ио.ПипедИнпутСтреам.цлосе() затвара цевоводни улазни ток и ослобађа додељене ресурсе. Синтакса: public void close() Parameters : -------------- Return : void Exception : -> IOException : if in case IO error occurs.
| цоннецт (извор ПипедОутпутСтреам): | јава.ио.ПипедИнпутСтреам.цоннецт(ПипедОутпутСтреам извор) повезује цевоводни улазни ток са 'изворним' цевоводним излазним током и у случају да је 'извор' цеви са неким другим ИО-током избацује се изузетак Синтакса: public void connect(PipedOutputStream source) Parameters : source : the Piped Output Stream to be connected to Return : void Exception : -> IOException : if in case IO error occurs.
| доступно(): | јава.ио.ПипедИнпутСтреам.аваилабле() враћа бр. бајтова који се могу прочитати из улазног тока без да буду блокирани. Синтакса: public int available() Parameters : ------------- Return : no. of bytes that can be read from Input Stream without actually being blocked. 0 if the stream is already closed but by invoking close() method Exception : -> IOException : if in case IO error occurs.
Јава програм који објашњава рад метода класе ПипедИнпутСтреам: Java // Java program illustrating the working of PipedInputStream // connect() read(byte[] buffer int offset int maxlen) // close() available() 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 ); geek_output . write ( 71 ); geek_output . write ( 69 ); geek_output . write ( 69 ); geek_output . write ( 75 ); geek_output . write ( 83 ); // Use of available() : System . out . println ( 'Use of available() : ' + geek_input . available ()); // Use of read(byte[] buffer int offset int maxlen) : byte [] buffer = new byte [ 5 ] ; // destination 'buffer' geek_input . read ( buffer 0 5 ); String str = new String ( buffer ); System . out . println ( 'Using read(buffer offset maxlen) : ' + str ); // USe of close() method : System . out . println ( 'Closing the stream' ); geek_input . close (); } catch ( IOException except ) { except . printStackTrace (); } } } Излаз: Use of available() : 5 Using read(buffer offset maxlen) : GEEKS Closing the stream
Next Article: Јава.ио.ПипедОутпутСтреам класа у Јави Креирај квиз