Java ByteArrayInputStream .markSupported ()
Syntax
ByteArrayInputStream.markSupported() has the following syntax.
public boolean markSupported()
Example
In the following code shows how to use ByteArrayInputStream.markSupported() method.
/*w w w . j a va 2s. com*/
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
byte[] buf = { 65, 66, 67, 68, 69 };
// create new byte array input stream
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
// test support for mark() and reset() methods invocation
boolean isMarkSupported = bais.markSupported();
System.out.println("Is mark supported : " + isMarkSupported);
System.out.println("Following is the proof:");
// print bytes
System.out.println(bais.read());
System.out.println(bais.read());
System.out.println(bais.read());
System.out.println("Mark() invocation");
// mark() invocation;
bais.mark(0);
System.out.println(bais.read());
System.out.println(bais.read());
System.out.println("Reset() invocation");
// reset() invocation
bais.reset();
System.out.println(bais.read());
System.out.println(bais.read());
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »