Signup/Sign In

Java FilterInputStream markSupported() method

In this tutorial, we will learn about the markSupported() method of FilterInputStream class in Java. This method is used to verify whether the current Filter Input Stream supports the calling of the mark() and reset() methods. It is a non-static method, available in the java.io package.

Syntax

This is the syntax declaration of this method. It does not accept any parameters. The return type of this method is boolean, i.e it returns true if the current stream supports the mark() and reset() method, otherwise it returns false.

public boolean markSupported()

Example 1: Verify Mark Support in FilterInputStream

Here, we are checking whether the current stream is allowed to set the mark method, if the mark() method is not allowed for the current stream then this method will return the false value. Otherwise, it will return the true value. In this example this method is returning a true value it means the given stream is supported to the mark() method.

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

public class StudyTonight
{
	public static void main(String args[])
	{
		try 
		{
			File file = new File("E:\\studytonight\\output.txt");

			FileInputStream fis = new FileInputStream(file);
			FilterInputStream filterIs = new BufferedInputStream(fis);

			System.out.println("is markSupported() ? " + filterIs.markSupported());

			fis.close();
			filterIs.close();
		} 
		catch (IOException ex) 
		{
			ex.printStackTrace();
		}
	}
}


is markSupported() ? true

Example 2: Verify Mark Support in FilterInputStream

In the given example, the markSupported() method is returning a false value that indicates that the current stream does not support to the mark() method and there will be no need to call reset() method

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

public class StudyTonight
{
	public static void main(String args[])
	{
		try 
		{
			File file = new File("E:\\studytonight\\myfile.txt");

			FileInputStream fis = new FileInputStream(file);
			FilterInputStream filterIs = new BufferedInputStream(fis);

			System.out.println("is markSupported() ? " + filterIs.markSupported());

			fis.close();
			filterIs.close();
		} 
		catch (IOException ex) 
		{
			ex.printStackTrace();
		}
	}
}


is markSupported() ? false

Conclusion:

In this tutorial, we learned about the markSupported() method of FilterInputStream class in Java, which checks whether the current file input stream supports the invocation of the mark() and reset() methods. If yes, it returns the boolean value true, and if not, it returns false. It is accessible with the class object only and if we try to access the method with the class name, we will get an error.



About the author:
I am the founder of Studytonight. I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development.