ByteArrayInputStream markSupported() method in Java with Examples
Last Updated :
20 Jul, 2021
The markSupported() method is a built-in method of the Java.io.ByteArrayInputStream method tests if this input stream supports the mark and reset methods. The markSupported method of ByteArrayInputStreamInputStream returns true always
Syntax :
public boolean markSupported()
Parameters : The function does not accepts any parameter. Return Value : The function returns a boolean value. It returns true if this stream instance supports the mark and reset methods, else false.
Below is the implementation of the above function:
Program 1:
Java
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception
{
byte[] buf = { 5, 6, 7, 8, 9 };
ByteArrayInputStream exam
= new ByteArrayInputStream(buf);
System.out.println(exam.read());
System.out.println(exam.read());
System.out.println(exam.read());
System.out.println("Mark() invocation");
boolean check = exam.markSupported();
System.out.println("markSupported() : "
+ check);
if (exam.markSupported()) {
exam.reset();
System.out.println("\nreset() invoked");
System.out.println(exam.read());
System.out.println(exam.read());
}
else {
System.out.println("reset() method not supported.");
}
}
}
Output:
5
6
7
Mark() invocation
markSupported() : true
reset() invoked
5
6
Program 2:
Java
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception
{
byte[] buf = { 1, 2, 3 };
ByteArrayInputStream exam
= new ByteArrayInputStream(buf);
System.out.println(exam.read());
System.out.println(exam.read());
System.out.println(exam.read());
boolean check = exam.markSupported();
System.out.println("markSupported() : "
+ check);
if (exam.markSupported()) {
exam.reset();
System.out.println("\nreset() invoked");
System.out.println(exam.read());
System.out.println(exam.read());
}
else {
System.out.println("reset() method not supported.");
}
}
}
Output:
1
2
3
markSupported() : true
reset() invoked
1
2
Reference: https://docs.oracle.com/javase/10/docs/api/java/io/ByteArrayInputStream.html#markSupported()
Share your thoughts in the comments
Add Your Comment
Please Login to comment...