InputStream, mark(), reset()

前端 未结 2 941
予麋鹿
予麋鹿 2021-02-07 18:26

How are mark() and reset() methods working exactly(in code below), step by step ? I tried to write my own example but is starts to throw wrong mark exc

2条回答
  •  梦如初夏
    2021-02-07 19:16

    When f.mark(32); is reached the read cursor is already after &, and a marker is set for reset to know where to jump back. So when you have detected that a ; is missing to close the element, you are manually printing & and moving the read cursor right back (after & where the marker was placed, using the mark(32) call), using the reset method. On the next read, because your marked variable is not set it will print the characters.

    mark(32) means to automatically remove the marker if your read cursor will advance more then 32 character. This may be the issue in your other code, that is triggering an error, because the marker was invalidated already.

提交回复
热议问题