Reputation: 520
I have a hasNext() method for reading a file. It returns true if it's not the end of the file. In this method it has an Exception.
Exception Information:
My hasNext() method:
@Override
public boolean hasNext() {
try {
super.getSourceRead().mark(1);
if (super.getSourceRead().read() < 0) {
return false;
}
getSourceRead().reset();
return true;
} catch (IOException e) {
Logger.exceptionOccurred(e);
return false;
} catch (NullPointerException e) {
Logger.exceptionOccurred(e);
return false;
}
}
Upvotes: 2
Views: 2991
Reputation: 2984
Well as it's written in the doc for 1.5:
After reading this many characters, attempting to reset the stream may fail.
So in your case it says it may fail after reading 1 character.
Setting the limit to 2 puts us in the safe zone.
And just to make a nagging style remark: I hope you have a constant or a member for that limit somewhere in your class (sorry I had to :) )
Upvotes: 2