001package org.unix4j.io;
002
003import java.util.Iterator;
004import java.util.NoSuchElementException;
005
006import org.unix4j.line.Line;
007
008/**
009 * Base implementation for {@link Input} providing the 
010 * {@link #iterator() iterator()} method.
011 */
012abstract public class AbstractInput implements Input {
013
014        @Override
015        public Iterator<Line> iterator() {
016                return new Iterator<Line>() {
017                        @Override
018                        public boolean hasNext() {
019                                return hasMoreLines();
020                        }
021
022                        @Override
023                        public Line next() {
024                                final Line line = readLine();
025                                if (line != null) {
026                                        return line;
027                                }
028                                throw new NoSuchElementException();
029                        }
030
031                        @Override
032                        public void remove() {
033                                throw new UnsupportedOperationException("remove is not supported");
034                        }
035                };
036        }
037
038}