Sunday, November 23, 2025
HomeLanguagesJavaByteArrayInputStream markSupported() method in Java with Examples

ByteArrayInputStream markSupported() method in Java with Examples

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




// Java program to implement
// the above function
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception
    {
 
        byte[] buf = { 5, 6, 7, 8, 9 };
 
        // Create new byte array input stream
        ByteArrayInputStream exam
            = new ByteArrayInputStream(buf);
 
        // print bytes
        System.out.println(exam.read());
        System.out.println(exam.read());
        System.out.println(exam.read());
 
        System.out.println("Mark() invocation");
 
        // Use of markSupported
        boolean check = exam.markSupported();
        System.out.println("markSupported() : "
                           + check);
 
        if (exam.markSupported()) {
 
            // Use of reset() method :
            // repositioning the stream to marked positions.
            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




// Java program to implement
// the above function
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception
    {
 
        byte[] buf = { 1, 2, 3 };
 
        // Create new byte array input stream
        ByteArrayInputStream exam
            = new ByteArrayInputStream(buf);
 
        // print bytes
        System.out.println(exam.read());
        System.out.println(exam.read());
        System.out.println(exam.read());
 
        // Use of markSupported
        boolean check = exam.markSupported();
 
        System.out.println("markSupported() : "
                           + check);
 
        if (exam.markSupported()) {
 
            // Use of reset() method :
            // repositioning the stream to marked positions
            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()
 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32410 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6909 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6865 POSTS0 COMMENTS
Umr Jansen
6852 POSTS0 COMMENTS