Borular IO'da, JVM'de aynı anda çalışan iki iş parçacığı arasında bir bağlantı sağlar. Yani Borular hem kaynak hem de hedef olarak kullanılır.
- PipedInputStream ayrıca PipedOutputStream ile de bağlanır. Yani veriler PipedOutputStream kullanılarak yazılabilir ve PipedInputStream kullanılarak yazılabilir. Ancak her iki iş parçacığını aynı anda kullanmak iş parçacıkları için bir kilitlenme yaratacaktır.
- Bağlı borulu çıkış akışına veri baytları sağlayan bir iş parçacığının artık canlı olmaması durumunda, borunun bozuk olduğu söylenir.
Beyanname: public class PipedInputStream extends InputStream
Yapıcı: | PipedInputStream(): | bağlı olmadığı bir PipedInputStream oluşturur.
| PipedInputStream(int pSize): | Belirtilen boru boyutuna bağlı olmayan bir PipedInputStream oluşturur.
| PipedInputStream(PipedOutputStream outStream): | PipedOutputStream - 'outStream'e bağlı bir PipedInputStream oluşturur.
| PipedInputStream(PipedOutputStream outStream int pSize): | Belirtilen kanal boyutuyla Borulu Çıkış Akışına bağlanan bir Borulu Giriş Akışı oluşturur. Yöntemler: | int okuma(): | 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 (); } } } Çıkış : using read() : G using read() : E using read() : K
| read(byte[] buffer int offset int maxlen): | java.io.PipedInputStream.read(byte[] buffer int offset int maxlen) Borulu Giriş Akışından arabellek dizisine verinin maksimum baytına kadar okur. Akışın sonuna ulaşıldığında veya istisna atıldığında yöntem bloke olur. Sözdizimi: 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.
| almak(int bayt): | java.io.PipedInputStream.receive(int bayt) verinin baytını alır. Herhangi bir giriş yoksa yöntem bloklanır. Sözdizimi: 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.
| kapalı() : | java.io.PipedInputStream.close() Borulu Giriş Akışını kapatır ve tahsis edilen kaynakları serbest bırakır. Sözdizimi: public void close() Parameters : -------------- Return : void Exception : -> IOException : if in case IO error occurs.
| connect(PipedOutputStream kaynağı): | java.io.PipedInputStream.connect(PipedOutputStream kaynağı) Borulu Giriş Akışını 'kaynak' Borulu Çıkış Akışına bağlar ve 'kaynağın' boru olması durumunda başka bir akış IO istisnası atılır Sözdizimi: 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.
| mevcut() : | java.io.PipedInputStream.available() hayır döndürür. Gerçekte engellenmeden Giriş Akışından okunabilen bayt sayısı. Sözdizimi: 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.
PipedInputStream sınıfı yöntemlerinin çalışmasını açıklayan Java programı: 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 (); } } } Çıkış: Use of available() : 5 Using read(buffer offset maxlen) : GEEKS Closing the stream
Next Article: Java'da Java.io.PipedOutputStream sınıfı Test Oluştur