PipedOutputStream flush Example

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


PipedOutputStream class flush example. public void flush() throws IOException Flushes this output stream and forces any buffered output bytes to be written out. This will notify any readers that bytes are waiting in the pipe.

Here is the code

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

public class Flush {

    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