| 1 | |
package com.aragost.javahg.internals; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.util.Iterator; |
| 5 | |
import java.util.NoSuchElementException; |
| 6 | |
|
| 7 | 984 | public class LineIterator implements Iterator<String>, Iterable<String> { |
| 8 | |
|
| 9 | 1744 | private boolean atEnd = false; |
| 10 | |
|
| 11 | |
private HgInputStream stream; |
| 12 | |
|
| 13 | 1744 | public LineIterator(HgInputStream stream) { |
| 14 | 1744 | this.stream = stream; |
| 15 | 1744 | } |
| 16 | |
|
| 17 | |
public Iterator<String> iterator() { |
| 18 | 1742 | return this; |
| 19 | |
} |
| 20 | |
|
| 21 | |
public boolean hasNext() { |
| 22 | 3712 | if (!this.atEnd) { |
| 23 | |
try { |
| 24 | 3712 | this.atEnd = (this.stream.isEof()); |
| 25 | 0 | } catch (IOException e) { |
| 26 | 0 | throw new RuntimeIOException(e); |
| 27 | 3712 | } |
| 28 | |
} |
| 29 | 3712 | return !this.atEnd; |
| 30 | |
} |
| 31 | |
|
| 32 | |
public String next() { |
| 33 | 984 | if (hasNext()) { |
| 34 | |
try { |
| 35 | 984 | return this.stream.textUpTo('\n'); |
| 36 | 0 | } catch (IOException e) { |
| 37 | 0 | throw new RuntimeIOException(e); |
| 38 | |
} |
| 39 | |
} else { |
| 40 | 0 | throw new NoSuchElementException(); |
| 41 | |
} |
| 42 | |
} |
| 43 | |
|
| 44 | |
public void remove() { |
| 45 | 0 | throw new UnsupportedOperationException(); |
| 46 | |
} |
| 47 | |
|
| 48 | |
} |