markSupported()方法是Java.io.ByteArrayInputStream方法的内置方法,用于测试此输入流是否支持mark和reset方法。 ByteArrayInputStreamInputStream的markSupported方法始终返回true
用法:
public boolean markSupported()
参数:该函数不接受任何参数。
返回值:该函数返回一个布尔值。如果此流实例支持mark和reset方法,则返回true,否则返回false。
下面是上述函数的实现:
示例1:
// 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 stram 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.");
}
}
}
输出:
5 6 7 Mark() invocation markSupported() : true reset() invoked 5 6
示例2:
// 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 stram 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.");
}
}
}
输出:
1 2 3 markSupported() : true reset() invoked 1 2
参考: https://docs.oracle.com/javase/10/docs/api/java/io/ByteArrayInputStream.html#markSupported()
相关用法
- Java StringReader markSupported()用法及代码示例
- Java CharArrayReader markSupported()用法及代码示例
- Java Reader markSupported()用法及代码示例
- Java PushbackReader markSupported()用法及代码示例
- Java ByteArrayInputStream available()用法及代码示例
- Java ByteArrayInputStream mark()用法及代码示例
- Java ByteArrayInputStream skip()用法及代码示例
- Java ByteArrayInputStream close()用法及代码示例
- Java ByteArrayInputStream reset()用法及代码示例
- Java Java lang.Long.lowestOneBit()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
- Java Java.util.Collections.rotate()用法及代码示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 ByteArrayInputStream markSupported() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。