InputStream Reset() Example
Repositions this stream to the position at the time the mark method was last called on this input stream.
InputStreamclass Reset() method example. This example shows you how to use Reset() method.This method Reposits this stream to the position at the time the mark method was last called on this input stream.
Here is the code:-
/**
* @Program that Reposits this stream to the position at the time the mark
* method was last called on this input stream.
* Reset.java
* Author:-RoseIndia Team
* Date:-06-Jun-2008
*/
import java.io.*;
public class Reset extends InputStream{
public int read() throws IOException {
return 0;
}
public static void main(String args[]) throws Exception {
PipedInputStream pis = new PipedInputStream();
PipedOutputStream o = new PipedOutputStream();
pis.connect(o);
byte b[] = {1, 2, 3, 4, 5};
o.write(b);
if (pis.markSupported()) {
pis.mark(b.length);
}
pis.reset();
System.out.println("Byte of data from input stream.");
//Returns the number of remaining bytes
while (pis.available() != 0) {
//Read InputStream
System.out.println(pis.read());
}
//Closing InputStream
pis.close();
}
} |
Output of the Program
Byte of data from input stream.
1
2
3
4
5 |
|