~ubuntu-branches/ubuntu/karmic/libgnuinet-java/karmic

« back to all changes in this revision

Viewing changes to source/gnu/inet/nntp/ActiveTimesIterator.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-04-14 12:42:10 UTC
  • Revision ID: james.westby@ubuntu.com-20040414124210-osc3q0wzthgme27p
Tags: upstream-0.0.cvs20031116
ImportĀ upstreamĀ versionĀ 0.0.cvs20031116

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: ActiveTimesIterator.java,v 1.2 2003/10/19 16:16:50 dog Exp $
 
3
 * Copyright (C) 2002 The Free Software Foundation
 
4
 * 
 
5
 * This file is part of GNU inetlib, a library.
 
6
 * 
 
7
 * GNU inetlib is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 * 
 
12
 * GNU inetlib is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 *
 
21
 * As a special exception, if you link this library with other files to
 
22
 * produce an executable, this library does not by itself cause the
 
23
 * resulting executable to be covered by the GNU General Public License.
 
24
 * This exception does not however invalidate any other reasons why the
 
25
 * executable file might be covered by the GNU General Public License.
 
26
 */
 
27
 
 
28
package gnu.inet.nntp;
 
29
 
 
30
import java.io.IOException;
 
31
import java.text.ParseException;
 
32
import java.util.Date;
 
33
import java.util.NoSuchElementException;
 
34
 
 
35
/**
 
36
 * An iterator over an NNTP LIST ACTIVE.TIMES listing.
 
37
 *
 
38
 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
 
39
 * @version $Revision: 1.2 $ $Date: 2003/10/19 16:16:50 $
 
40
 */
 
41
public class ActiveTimesIterator extends LineIterator
 
42
{
 
43
 
 
44
  ActiveTimesIterator(NNTPConnection connection)
 
45
  {
 
46
    super(connection);
 
47
  }
 
48
 
 
49
  /**
 
50
   * Returns the next group active time.
 
51
   */
 
52
  public Object next()
 
53
  {
 
54
    try
 
55
    {
 
56
      return nextGroup();
 
57
    }
 
58
    catch(IOException e)
 
59
    {
 
60
      throw new NoSuchElementException("I/O error: " + e.getMessage());
 
61
    }
 
62
  }
 
63
 
 
64
  /**
 
65
   * Returns the next group active time.
 
66
   */
 
67
  public ActiveTime nextGroup() throws IOException
 
68
  {
 
69
    String line = nextLine();
 
70
 
 
71
    // Parse line
 
72
      try
 
73
    {
 
74
      int start = 0, end;
 
75
        end = line.indexOf(' ', start);
 
76
      String group = line.substring(start, end);
 
77
        start = end + 1;
 
78
        end = line.indexOf(' ', start);
 
79
      Date time = connection.parseDate(line.substring(start, end));
 
80
        start = end + 1;
 
81
      String email = line.substring(start);
 
82
 
 
83
        return new ActiveTime(group, time, email);
 
84
    }
 
85
    catch(ParseException e)
 
86
    {
 
87
      throw new IOException(e.getMessage());
 
88
    }
 
89
  }
 
90
 
 
91
}