I am reading a PNG image using a PNG ImageReader. I am marking the initial position of the ImageInputStream through IIS.mark() call just before invoking the reader.read() method. This read process is aborted when it completes 50% by calling abort() in one of the listener methods. After this, I am resetting the position of the ImageInputStream to the initial marked position by calling IIS.reset(). Then I am using the same reader to the read the image till completion. This results in an IIOException. Call to IIS.reset() throws an exception saying the initially marked position has been discarded. Caching is disabled at begining of the application.
PNG ImageReader actually calls IIS.flushBefore() which actually flushes the portion of the image input stream that was marked earlier. This does not seem to be happening with other image formats. However, there is an issue with JPEG where the abort flag is not cleared properly and causes every subsequent read operation to be aborted when abort() is called once. A separate bug has been filed on this. (4885702)
This is reproducible on all platforms since JDK1.4.
I have attached a sample testcase. Execute the testcase and pass a png image. You would see the exception given below when calling the reset() on the IIS.
Here is the exception:
javax.imageio.IIOException: Previous marked position has been discarded!