KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > Ostermiller > util > CSVParse


1 /*
2  * Read files in comma separated value format.
3  * Copyright (C) 2002-2004 Stephen Ostermiller
4  * http://ostermiller.org/contact.pl?regarding=Java+Utilities
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * See COPYING.TXT for details.
17  */

18
19 package com.Ostermiller.util;
20
21 import java.io.*;
22
23 /**
24  * Read files in comma separated value format.
25  * More information about this class is available from <a target="_top" HREF=
26  * "http://ostermiller.org/utils/CSVLexer.html">ostermiller.org</a>.
27  * This interface is designed to be set of general methods that all
28  * CSV parsers should implement.
29  *
30  * @author Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
31  * @since ostermillerutils 1.00.00
32  */

33 public interface CSVParse {
34
35     /**
36      * Read the next value from the file. The line number from
37      * which this value was taken can be obtained from getLastLineNumber().
38      *
39      * @return the next value or null if there are no more values.
40      * @throws IOException if an error occurs while reading.
41      *
42      * @since ostermillerutils 1.00.00
43      */

44     public String JavaDoc nextValue() throws IOException;
45
46     /**
47      * Get the line number that the last token came from.
48      *
49      * @return line number or -1 if no tokens have been returned yet.
50      *
51      * @since ostermillerutils 1.00.00
52      */

53     public int lastLineNumber();
54
55     /**
56      * Get all the values from a line.
57      * <p>
58      * If the line has already been partially read, only the
59      * values that have not already been read will be included.
60      *
61      * @return all the values from the line or null if there are no more values.
62      * @throws IOException if an error occurs while reading.
63      *
64      * @since ostermillerutils 1.00.00
65      */

66     public String JavaDoc[] getLine() throws IOException;
67
68     /**
69      * Get the line number that the last token came from.
70      * <p>
71      * New line breaks that occur in the middle of a token are not
72      * counted in the line number count.
73      *
74      * @return line number or -1 if no tokens have been returned yet.
75      *
76      * @since ostermillerutils 1.00.00
77      */

78     public int getLastLineNumber();
79
80     /**
81      * Get all the values from the file.
82      * <p>
83      * If the file has already been partially read, only the
84      * values that have not already been read will be included.
85      * <p>
86      * Each line of the file that has at least one value will be
87      * represented. Comments and empty lines are ignored.
88      * <p>
89      * The resulting double array may be jagged.
90      *
91      * @return all the values from the file or null if there are no more values.
92      * @throws IOException if an error occurs while reading.
93      *
94      * @since ostermillerutils 1.00.00
95      */

96     public String JavaDoc[][] getAllValues() throws IOException;
97
98
99     /**
100      * Change this parser so that it uses a new delimiter.
101      * <p>
102      * The initial character is a comma, the delimiter cannot be changed
103      * to a quote or other character that has special meaning in CSV.
104      *
105      * @param newDelim delimiter to which to switch.
106      * @throws BadDelimiterException if the character cannot be used as a delimiter.
107      *
108      * @since ostermillerutils 1.02.08
109      */

110     public void changeDelimiter(char newDelim) throws BadDelimiterException;
111
112     /**
113      * Change this parser so that it uses a new character for quoting.
114      * <p>
115      * The initial character is a double quote ("), the delimiter cannot be changed
116      * to a comma or other character that has special meaning in CSV.
117      *
118      * @param newQuote character to use for quoting.
119      * @throws BadQuoteException if the character cannot be used as a quote.
120      *
121      * @since ostermillerutils 1.02.16
122      */

123     public void changeQuote(char newQuote) throws BadQuoteException;
124
125
126     /**
127      * Close any stream upon which this parser is based.
128      *
129      * @since ostermillerutils 1.02.26
130      * @throws IOException if an error occurs while closing the stream.
131      */

132     public void close() throws IOException;
133
134 }
135
Popular Tags