javabytearrayinputstream

Argument in mark method of ByteArrayInputStream


I tried the following code to understand the working of mark() method of ByteArrayInputStream.

class tryByteArray  
{  
    public static void main(String args[]) throws Exception  
    {  
        byte[] buffer={71, 69, 69, 75, 83};  
        try(ByteArrayInputStream obj=new ByteArrayInputStream(buffer))  
        {  
            System.out.println("\nChar "+(char)obj.read());  
            obj.mark(0);  
            System.out.println("Char "+(char)obj.read());  
            System.out.println("Char "+(char)obj.read());  
            System.out.println("Char "+(char)obj.read());  
            obj.reset();  
            System.out.println("\nChar "+(char)obj.read());  
            System.out.println("Char "+(char)obj.read());  
          }  
    }  
}

It gave the following output:-

Char G
Char E
Char E
Char K

Char E
Char E  

But when I changed the argument of mark() method to 1,2 or any number it still shows the same output. Can someone explain to me the working of mark() method?


Solution

  • From the docs:

    Note: The readAheadLimit for this class has no meaning.

    Edit: Also take a look at the source code.