InputStream Mark() Example
Marks the current position in this input stream.
InputStreamclass Mark() method example. This example shows you how to use Mark() method.This method Marks the current position in this input stream.
Here is the code:-
/**
* @Program that Marks the current position in this input stream.
* Mark.java
* Author:-RoseIndia Team
* Date:-06-Jun-2008
*/
import java.io.*;
public class Mark 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 |
|