PipedOutputStream connect Example

PipedOutputStream class connect example. This example shows you how to use connect method.


PipedOutputStream class connect example. public void connect(PipedInputStream ) throws IOException Connects this piped output stream to a receiver. If this object is already connected to some other piped input stream, an IOException is thrown.

Here is the code

/**
 * @ # Connect.java
 * A class repersenting use to connect method 
 * of PipedOutputStream class in java.io package
 * version 03 June 2008
 * author Rose India 
 */
import java.io.*;

public class Connect {

    public static void main(String args[]) throws Exception {

        PipedOutputStream poStream = new PipedOutputStream();
        PipedInputStream piStream = new PipedInputStream();

        // Connects piped output stream to a receiver.
        poStream.connect(piStream);

        //write byte array
        byte b[] {12345};
        poStream.write(b, 05);

        //Flushes output stream
        poStream.flush();
        
        System.out.println("Read from piped input stream");
        while (piStream.available() != 0) {
            System.out.println(piStream.read());
        }

        //Reads the next byte from piped input stream.
        poStream.close();
        piStream.close();
    }
}

Output
Read from piped input stream
1
2
3
4
5

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US