connect(PipedInputStream): This method is available in the java.io.PipedOutputStream class of Java.
Syntax:
void java.io.PipedOutputStream.connect(PipedInputStream snk) throws IOException
This method takes one argument. This method connects this piped output stream to a receiver.
If this object is already connected to piped input stream, an IOException is thrown.
If snk is an unconnected piped input stream and src is an unconnected piped output stream, they may be connected by either the call:
src.connect(snk) or the call: snk.connect(src).
The two calls have the same effect.
Parameters: One parameter is required for this method.
snk: the piped input stream to connect to.
Returns: NA
Throws:
IOException - if an I/O error occurs.
Approach
Java
import java.io.IOException;import java.io.PipedInputStream;import java.io.PipedOutputStream;public class PipedOutputStreamconnect {public static void main(String[] args) throws IOException {PipedOutputStream pipedOutputStream =new PipedOutputStream();PipedInputStream snk = new PipedInputStream();pipedOutputStream.connect(snk);System.out.println("Connecting the piped output stream");pipedOutputStream.close();}}
Output:
Connecting the piped output stream
Some other methods of PipedOutputStream
close(): This method closes this piped output stream and releases any system resources associated with this stream.
connect(PipedInputStream): This method connects this piped output stream to a receiver.
flush(): This method flushes this output stream and forces any buffered output by the test to be written out.
PipedOutputStream(): This method creates a piped output stream that is not yet connected to a piped input stream.
PipedOutputStream(PipedInputStream): This method creates a piped output stream connected to the specified piped input stream.
write(int): This method writes the specified byte to the piped output stream.
write(byte[], int, int): This method writes len bytes from the specified byte array starting at offset off to this piped output stream.
No comments:
Post a Comment