ByteArrayInputStream mark Example
ByteArrayInputStream class mark example. This example shows you how to use mark method.
ByteArrayInputStream class mark example. public void mark(int readAheadLimit) Set the current marked position in the stream. ByteArrayInputStream objects are marked at position zero by default when constructed. They may be marked at another position within the buffer by this method.
/**
* @ # Mark.java
* A class repersenting use to mark method
* of ByteArrayInputStream class in java.io package
* version 03 June 2008
* author Rose India
*/
import java.io.*;
public class Mark {
public static void main(String args[]) throws Exception {
byte b[] = {1, 2, 3, 4, 5};
ByteArrayInputStream baStream = new ByteArrayInputStream(b);
if (baStream.markSupported()) {
baStream.mark(b.length);
}
baStream.reset();
System.out.println("Byte of data from input stream.");
//Returns the number of remaining bytes
while (baStream.available() != 0) {
//Read ByteArrayInputStream
System.out.println(baStream.read());
}
//Closing ByteArrayInputStream
baStream.close();
}
} |
Output
Byte of data from input stream.
1
2
3
4
5 |
|