KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > util > iterator > LineReadingIterator


1 /* LineReadingIterator
2 *
3 * $Id: LineReadingIterator.java,v 1.1.18.1 2007/01/13 01:31:40 stack-sf Exp $
4 *
5 * Created on Jul 27, 2004
6 *
7 * Copyright (C) 2004 Internet Archive.
8 *
9 * This file is part of the Heritrix web crawler (crawler.archive.org).
10 *
11 * Heritrix is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * any later version.
15 *
16 * Heritrix is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser Public License
22 * along with Heritrix; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */

25 package org.archive.util.iterator;
26
27 import java.io.BufferedReader JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.util.logging.Logger JavaDoc;
30
31 /**
32  * Utility class providing an Iterator interface over line-oriented
33  * text input, as a thin wrapper over a BufferedReader.
34  *
35  * @author gojomo
36  */

37 public class LineReadingIterator extends LookaheadIterator<String JavaDoc> {
38     private static final Logger JavaDoc logger =
39         Logger.getLogger(LineReadingIterator.class.getName());
40
41     protected BufferedReader JavaDoc reader = null;
42
43     public LineReadingIterator(BufferedReader JavaDoc r) {
44         reader = r;
45     }
46
47     /**
48      * Loads next line into lookahead spot
49      *
50      * @return whether any item was loaded into next field
51      */

52     protected boolean lookahead() {
53         try {
54             next = this.reader.readLine();
55             if(next == null) {
56                 // TODO: make this close-on-exhaust optional?
57
reader.close();
58             }
59             return (next!=null);
60         } catch (IOException JavaDoc e) {
61             logger.warning(e.toString());
62             return false;
63         }
64     }
65 }
66
Popular Tags