Java PushbackInputStream reset() Example

PushbackInputStream class reset() method example. This example shows you how to use reset() method.


Syntax is : public void reset() throws IOException
This method repositions this stream to the position at the time the mark method was last called on this input stream. The method reset for class PushbackInputStream does nothing except throw an IOException.

Here is the code.

/**
 * @(#) ResetPushbackInputStream.java
 * A class representing use of method reset() of PushbackInputStream 
class in java.io Package.
 * @Version  10-June-2008
 @author   Rose India Team
 */
import java.io.*;

public class ResetPushbackInputStream {

    public static void main(String[] argsthrows IOException {

        byte[] byteArrayOut = new byte[]{'M''A''H''E''N''D''R','A'};

        /* Create object of ByteArrayOutputStream class to write specified 
        byte array to the output byte stream. */
        ByteArrayOutputStream objByteStream = new ByteArrayOutputStream();
        objByteStream.write(byteArrayOut, 08);

        // Create object of ByteArrayInputStream class.
        InputStream objInStream = new ByteArrayInputStream(byteArrayOut);

        //Create object of MarkSupportedFilterInputStream class.
        PushbackInputStream obj = new PushbackInputStream(objInStream);

        // Read from the input stream buffer.
        System.out.println("\nFirst element is  : " (charobj.read());
        System.out.println("Next element is : " (charobj.read());

        // Set the mark position for second element.
        obj.mark(1);
        System.out.println("Element at second position has marked but The " +
                "mark method of PushbackInputStream does nothing.");
        System.out.println("Next element is  : " (charobj.read());
        System.out.println("Next element is  : " (charobj.read());

        try {
            // Reset the BufferedInputStream.
            obj.reset();
        catch (IOException ex) {
            System.out.println("The method reset for class PushbackInputStream"+
                    " does nothing except throw an IOException.");
        }
    }
}

output of the program.
 First element is  : M
Next element is : A
Element at second position has marked but The mark method of PushbackInputStream does nothing.
Next element is  : H
Next element is  : E
The method reset for class PushbackInputStream does nothing except throw an IOException.

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

HOME | COPYRIGHT | CONTACT US