FilterInputStream mark(int) in Java

mark(int): This method is available in the java.io.FilterInputStream class of Java.

Syntax:

void java.io.FilterInputStream.mark(int readlimit)

This method takes one argument. This 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.

The read limit argument tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

Parameters: One parameter is required for this method.

readlimit: the maximum limit of bytes that can be read before the mark position becomes invalid.

Returns: NA

Exceptions: NA

Approach

Java

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;

public class FilterInputStreammark {
    public static void main(String[] args) throws IOException {

        File data = new File("D:\\hello.txt");
        FileInputStream file = new FileInputStream(data);

        FilterInputStream filter =
new BufferedInputStream(file);

        int readlimit = 1;
        System.out.println("Mark the limit");
        filter.mark(readlimit);
        filter.close();
    }
}

Output:

Mark the limit


Other methods of FilterInputStream

available()This method returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking the next caller of a method for this input stream.

close()This method closes this input stream and releases any system resources associated with the stream.

markSupported()This method tests if this input stream supports the mark and reset methods.

read()This method reads the next byte of data from this input stream.

read(byte[])This method reads up to b.length bytes of data from this input stream into an array of bytes.

read(byte[], int, int)This method reads up to len bytes of data from this input stream into an array of bytes.

reset()This method repositions this stream to the position at the time the mark method was last called on this input stream.

skip(long)This method skips over and discards n bytes of data from the input stream.



No comments:

Post a Comment