1 |
/* |
/* |
2 |
* $Id$ |
* HeaderIterator.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. |
45 |
* An iterator over an NNTP XHDR listing. |
* An iterator over an NNTP XHDR listing. |
46 |
* |
* |
47 |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
|
* @version $Revision$ $Date$ |
|
48 |
*/ |
*/ |
49 |
public class HeaderIterator extends LineIterator |
public class HeaderIterator |
50 |
|
extends LineIterator |
51 |
{ |
{ |
52 |
|
|
53 |
HeaderIterator (NNTPConnection connection) |
HeaderIterator(NNTPConnection connection) |
54 |
{ |
{ |
55 |
super (connection); |
super(connection); |
56 |
} |
} |
57 |
|
|
58 |
/** |
/** |
59 |
* Returns the next header entry. |
* Returns the next header entry. |
60 |
*/ |
*/ |
61 |
public Object next () |
public Object next() |
62 |
{ |
{ |
63 |
try |
try |
64 |
{ |
{ |
65 |
return nextHeaderEntry (); |
return nextHeaderEntry(); |
66 |
} |
} |
67 |
catch (IOException e) |
catch (IOException e) |
68 |
{ |
{ |
69 |
throw new NoSuchElementException ("I/O error: " + e.getMessage ()); |
throw new NoSuchElementException("I/O error: " + e.getMessage()); |
70 |
} |
} |
71 |
} |
} |
72 |
|
|
73 |
/** |
/** |
74 |
* Returns the next header entry. |
* Returns the next header entry. |
75 |
*/ |
*/ |
76 |
public HeaderEntry nextHeaderEntry () throws IOException |
public HeaderEntry nextHeaderEntry() |
77 |
|
throws IOException |
78 |
{ |
{ |
79 |
String line = nextLine (); |
String line = nextLine(); |
80 |
|
|
81 |
// Parse line |
// Parse line |
82 |
int start = 0, end; |
int start = 0, end; |
83 |
end = line.indexOf (' ', start); |
end = line.indexOf(' ', start); |
84 |
String articleId = line.substring (start, end); |
String articleId = line.substring(start, end); |
85 |
start = end + 1; |
start = end + 1; |
86 |
String header = line.substring (start); |
String header = line.substring(start); |
87 |
|
|
88 |
return new HeaderEntry (articleId, header); |
return new HeaderEntry(articleId, header); |
89 |
} |
} |
90 |
|
|
91 |
} |
} |
92 |
|
|