/[classpath]/inetlib/source/gnu/inet/nntp/LineIterator.java
ViewVC logotype

Diff of /inetlib/source/gnu/inet/nntp/LineIterator.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dog, Sun Oct 19 08:51:37 2003 UTC revision 1.2 by dog, Sun Oct 19 16:16:50 2003 UTC
# Line 37  import java.util.NoSuchElementException; Line 37  import java.util.NoSuchElementException;
37   * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>   * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
38   * @version $Revision$ $Date$   * @version $Revision$ $Date$
39   */   */
40  public class LineIterator  public class LineIterator implements Iterator, PendingData
   implements Iterator, PendingData  
41  {  {
42    
43    static final String DOT = ".";    static final String DOT = ".";
44      
45    boolean doneRead = false;    boolean doneRead = false;
46    NNTPConnection connection;    NNTPConnection connection;
47    String current;    String current;
48    
49    LineIterator(NNTPConnection connection)      LineIterator(NNTPConnection connection)
50    {    {
51      this.connection = connection;      this.connection = connection;
52    }    }
53      
54    void doRead()    void doRead() throws IOException
     throws IOException  
55    {    {
56      if (doneRead)      if (doneRead)
57        return;        return;
58      String line = connection.read();      String line = connection.read();
59      if (DOT.equals(line))      if (DOT.equals(line))
60        current = null;          current = null;
61      else      else
62        current = line;          current = line;
63      doneRead = true;        doneRead = true;
64    }    }
65    
66    /**    /**
67     * Indicates whether there are more lines to be read.     * Indicates whether there are more lines to be read.
68     */       */
69    public boolean hasNext()    public boolean hasNext()
70    {    {
71      try      try
72      {      {
73        doRead();        doRead();
74      }      }
75      catch (IOException e)      catch(IOException e)
76      {      {
77        return false;        return false;
78      }      }
79      return (current!=null);      return (current != null);
80    }    }
81    
82    /**    /**
# Line 90  public class LineIterator Line 88  public class LineIterator
88      {      {
89        return nextLine();        return nextLine();
90      }      }
91      catch (IOException e)      catch(IOException e)
92      {      {
93        throw new NoSuchElementException("I/O error: "+e.getMessage());        throw new NoSuchElementException("I/O error: " + e.getMessage());
94      }      }
95    }    }
96    
97    /**    /**
98     * Returns the next line.     * Returns the next line.
99     */     */
100    public String nextLine()    public String nextLine() throws IOException
     throws IOException  
101    {    {
102      doRead();      doRead();
103      if (current==null)      if (current == null)
104        throw new NoSuchElementException();        throw new NoSuchElementException();
105      doneRead = false;        doneRead = false;
106      return current;        return current;
107    }    }
108    
109    /**    /**
# Line 120  public class LineIterator Line 117  public class LineIterator
117    /**    /**
118     * Read to the end of this iterator.     * Read to the end of this iterator.
119     */     */
120    public void readToEOF()    public void readToEOF() throws IOException
     throws IOException  
121    {    {
122      do      do
123      {      {
124        doRead();        doRead();
125      }      }
126      while (current!=null);      while (current != null);
127    }    }
128      
129  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26