01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.mif;
17:
18: import java.io.BufferedReader;
19: import java.io.IOException;
20:
21: /**
22: * Simple tokenizer class for BufferedReaders
23: *
24: * @author Luca S. Percich, AMA-MI
25: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/mif/src/main/java/org/geotools/data/mif/MIFFileTokenizer.java $
26: * @version $Id: MIFFileTokenizer.java 22266 2006-10-19 11:30:55Z acuster $
27: */
28: public class MIFFileTokenizer extends MIFStringTokenizer {
29: private BufferedReader reader = null;
30: private int lineNumber = 0;
31:
32: /**
33: * Builds a tokenizer for a BufferedReader
34: *
35: * @param aReader
36: */
37: public MIFFileTokenizer(BufferedReader aReader) {
38: super ();
39: reader = aReader;
40: }
41:
42: /**
43: * Closes the associated reader.
44: */
45: public void close() {
46: try {
47: reader.close();
48: reader = null;
49: } catch (Exception e) {
50: }
51: }
52:
53: /**
54: * Stores the next non-null line from file buffer in the line buffer
55: *
56: * @return True if a non-null string was read, false if EOF or error
57: */
58: public boolean readLine() {
59: String buffer = "";
60:
61: do {
62: try {
63: buffer = reader.readLine();
64:
65: if (buffer == null) {
66: return readLine(""); //EOF
67: }
68: } catch (IOException e) {
69: return readLine("");
70: }
71:
72: lineNumber++;
73: buffer = buffer.trim();
74: } while (buffer.length() == 0);
75:
76: return readLine(buffer);
77: }
78:
79: /**
80: * Returns the current line number
81: *
82: */
83: public int getLineNumber() {
84: return lineNumber;
85: }
86: }
|