Java LineNumberInputStream mark() Example
LineNumberInputStream class mark() method example. This example shows you how to use mark() method.
Syntax is : public void mark(int readlimit)
Method marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes. This is deprecated method of deprecated class.
Here is the code.
/**
* @(#) MarkLineNumberInputStream.java
* A class representing use of method mark() of LineNumberInputStream
class in java.io Package. This is deprecated class in java 1.6 API.
* @Version 05-May-2008
* @author Rose India Team
*/
import java.io.*;
public class MarkLineNumberInputStream {
public static void main(String[] args) throws IOException{
String str = "MAHENDRA";
System.out.println("Elements in buffer are : " + str);
/* Create object of StringBufferInputStream class. This is deprecated
class in java api 1.6. */
StringBufferInputStream obj = new StringBufferInputStream("MAHENDRA");
// Create object of LineNumberInputStream class.
LineNumberInputStream objInputStream = new LineNumberInputStream(obj);
// Read from the buffer one character at a time:
System.out.println("First element is : "+(char)objInputStream.read());
// mark first element of the buffer stream.
objInputStream.mark(0);
System.out.println("Mark first element of the buffer stream.");
System.out.println("Next element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
// reset() method call that resets the buffer to the mark position.
objInputStream.reset();
System.out.println("After reset() method call.");
System.out.println("Next element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
System.out.println("Next element is : "+(char)objInputStream.read());
}
} |
Output of the program.
Elements in buffer are : MAHENDRA
First element is : M
Mark first element of the buffer stream.
Next element is : A
Next element is : H
After reset() method call.
Next element is : M
Next element is : A
Next element is : H |
|