My question pertains to the mark() method of Java's StringReader. Here is my scenario:
StringReader reader = new StringReader("Test123");
reader.mark(0);
boolean bool = doSomething(reader)//reads from reader with calls to mark() inside
if (bool == false) {
reader.reset();
}
doSomethingElse(reader);
I want to recover my reader back to its original state if doSomething() returns false. Because reset() will only reset the reader back to the previously-called mark, and there are marks called from within the doSomething() method, it doesn't refer to the mark called one line before entering the doSomething() method. Is there a possible workaround to this? I appreciate the help!
Since you know that
doSomething()
callsmark()
, there's no point in callingmark()
before that.Instead of resetting the
StringReader
, you can just create a newStringReader
from the same string.