Entry tags:
was it hard?
/** * Iterates over a LineNumberReader * Usage: * LineNumberReader r = new LineNumberReader(new InputStreamReader(new FileInputStream("system.properties"))); * for (String line : r) { * ... * } * @param in the source * @return an iterable that scans over the lines of the source * @throws IOException when it cannot read the first line * @throws RuntimeException when it cannot read further down the stream */ public static Iterable<String> iterate(final LineNumberReader in) throws IOException { final String first = in.readLine(); return new Iterable<String>() { @Override public Iteratoriterator() { return new Iterator () { String current = first; @Override public boolean hasNext() { return current != null; } @Override public String next() { if (!hasNext()) { throw new NoSuchElementException(); } try { return current; } finally { try { current = in.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } } @Override public void remove() { throw new UnsupportedOperationException(); } }; }}; }