1 |
/* |
/* |
2 |
* $Id$ |
* GroupIterator.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 newsgroup listing. |
* An iterator over an NNTP newsgroup 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 GroupIterator extends LineIterator |
public class GroupIterator |
50 |
|
extends LineIterator |
51 |
{ |
{ |
52 |
|
|
53 |
static final String CAN_POST = "y"; |
static final String CAN_POST = "y"; |
54 |
|
|
55 |
GroupIterator (NNTPConnection connection) |
GroupIterator(NNTPConnection connection) |
56 |
{ |
{ |
57 |
super (connection); |
super(connection); |
58 |
} |
} |
59 |
|
|
60 |
/** |
/** |
61 |
* Returns the next group. |
* Returns the next group. |
62 |
*/ |
*/ |
63 |
public Object next () |
public Object next() |
64 |
{ |
{ |
65 |
try |
try |
66 |
{ |
{ |
67 |
return nextGroup (); |
return nextGroup(); |
68 |
} |
} |
69 |
catch (IOException e) |
catch (IOException e) |
70 |
{ |
{ |
71 |
throw new NoSuchElementException ("I/O error: " + e.getMessage ()); |
throw new NoSuchElementException("I/O error: " + e.getMessage()); |
72 |
} |
} |
73 |
} |
} |
74 |
|
|
75 |
/** |
/** |
76 |
* Returns the next group. |
* Returns the next group. |
77 |
*/ |
*/ |
78 |
public Group nextGroup () throws IOException |
public Group nextGroup() |
79 |
|
throws IOException |
80 |
{ |
{ |
81 |
String line = nextLine (); |
String line = nextLine(); |
82 |
|
|
83 |
// Parse line |
// Parse line |
84 |
int start = 0, end; |
int start = 0, end; |
85 |
end = line.indexOf (' ', start); |
end = line.indexOf(' ', start); |
86 |
String name = line.substring (start, end); |
String name = line.substring(start, end); |
87 |
start = end + 1; |
start = end + 1; |
88 |
end = line.indexOf (' ', start); |
end = line.indexOf(' ', start); |
89 |
int last = Integer.parseInt (line.substring (start, end)); |
int last = Integer.parseInt(line.substring(start, end)); |
90 |
start = end + 1; |
start = end + 1; |
91 |
end = line.indexOf (' ', start); |
end = line.indexOf(' ', start); |
92 |
int first = Integer.parseInt (line.substring (start, end)); |
int first = Integer.parseInt(line.substring(start, end)); |
93 |
start = end + 1; |
start = end + 1; |
94 |
boolean canPost = CAN_POST.equals (line.substring (start)); |
boolean canPost = CAN_POST.equals(line.substring(start)); |
95 |
|
|
96 |
return new Group (name, last, first, canPost); |
return new Group(name, last, first, canPost); |
97 |
} |
} |
98 |
|
|
99 |
} |
} |
100 |
|
|