/[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.5 by dog, Thu Oct 21 15:21:55 2004 UTC revision 1.6 by dog, Thu Nov 25 22:15:05 2004 UTC
# Line 1  Line 1 
1  /*  /*
2   * $Id$   * LineIterator.java
3   * Copyright (C) 2002 The Free Software Foundation   * Copyright (C) 2002 The Free Software Foundation
4   *   *
5   * This file is part of GNU inetlib, a library.   * This file is part of GNU inetlib, a library.
# Line 46  import java.util.NoSuchElementException; Line 46  import java.util.NoSuchElementException;
46   * An iterator over an NNTP multi-line response.   * An iterator over an NNTP multi-line response.
47   *   *
48   * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>   * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
  * @version $Revision$ $Date$  
49   */   */
50  public class LineIterator implements Iterator, PendingData  public class LineIterator
51      implements Iterator, PendingData
52  {  {
53    
54    static final String DOT = ".";    static final String DOT = ".";
# Line 57  public class LineIterator implements Ite Line 57  public class LineIterator implements Ite
57    NNTPConnection connection;    NNTPConnection connection;
58    String current;    String current;
59    
60    LineIterator (NNTPConnection connection)    LineIterator(NNTPConnection connection)
61    {    {
62      this.connection = connection;      this.connection = connection;
63    }    }
64    
65    void doRead () throws IOException    void doRead()
66        throws IOException
67    {    {
68      if (doneRead)      if (doneRead)
69        {        {
70          return;          return;
71        }        }
72      String line = connection.read ();      String line = connection.read();
73      if (DOT.equals (line))      if (DOT.equals(line))
74        {        {
75          current = null;          current = null;
76        }        }
# Line 83  public class LineIterator implements Ite Line 84  public class LineIterator implements Ite
84    /**    /**
85     * Indicates whether there are more lines to be read.     * Indicates whether there are more lines to be read.
86     */     */
87    public boolean hasNext ()    public boolean hasNext()
88    {    {
89      try      try
90        {        {
91          doRead ();          doRead();
92        }        }
93      catch (IOException e)      catch (IOException e)
94        {        {
95          return false;          return false;
96        }        }
97      return (current != null);      return(current != null);
98    }    }
99    
100    /**    /**
101     * Returns the next line.     * Returns the next line.
102     */     */
103    public Object next ()    public Object next()
104    {    {
105      try      try
106        {        {
107          return nextLine ();          return nextLine();
108        }        }
109      catch (IOException e)      catch (IOException e)
110        {        {
111          throw new NoSuchElementException ("I/O error: " + e.getMessage ());          throw new NoSuchElementException("I/O error: " + e.getMessage());
112        }        }
113    }    }
114    
115    /**    /**
116     * Returns the next line.     * Returns the next line.
117     */     */
118    public String nextLine () throws IOException    public String nextLine()
119        throws IOException
120    {    {
121      doRead ();      doRead();
122      if (current == null)      if (current == null)
123        {        {
124          throw new NoSuchElementException ();          throw new NoSuchElementException();
125        }        }
126      doneRead = false;      doneRead = false;
127      return current;      return current;
# Line 128  public class LineIterator implements Ite Line 130  public class LineIterator implements Ite
130    /**    /**
131     * This iterator is read-only.     * This iterator is read-only.
132     */     */
133    public void remove ()    public void remove()
134    {    {
135      throw new UnsupportedOperationException ();      throw new UnsupportedOperationException();
136    }    }
137    
138    /**    /**
139     * Read to the end of this iterator.     * Read to the end of this iterator.
140     */     */
141    public void readToEOF () throws IOException    public void readToEOF()
142        throws IOException
143    {    {
144      do      do
145        {        {
146          doRead ();          doRead();
147        }        }
148      while (current != null);      while (current != null);
149    }    }
150    
151  }  }
152    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

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