1 /* 2 * Copyright 2007 Kasper B. Graversen 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.supercsv.io; 17 18 import java.io.Closeable; 19 import java.io.IOException; 20 21 import org.supercsv.exception.SuperCsvException; 22 23 /** 24 * The interface for CSV readers. 25 * 26 * @author Kasper B. Graversen 27 * @author James Bassett 28 */ 29 public interface ICsvReader extends Closeable { 30 31 /** 32 * Get column N of the current line (column indexes begin at 1). 33 * 34 * @param n 35 * the index of the column to get 36 * @return the n'th column 37 * @throws IndexOutOfBoundsException 38 * if the supplied index is not a valid column index 39 * @since 1.0 40 */ 41 String get(int n); 42 43 /** 44 * This method is used to get an optional header of the CSV file and move the file cursor to the first row 45 * containing data (the second row from the top). The header can subsequently be used as the 46 * <code>nameMapping</code> array for read operations. 47 * 48 * @param firstLineCheck 49 * if true, ensures that this method is only called when reading the first line (as that's where the 50 * header is meant to be) 51 * @return the array of header fields, or null if EOF is encountered 52 * @throws IOException 53 * if an I/O exception occurs 54 * @throws SuperCsvException 55 * if firstLineCheck == true and it's not the first line being read 56 * @since 1.0 57 */ 58 String[] getHeader(boolean firstLineCheck) throws IOException; 59 60 /** 61 * Gets the current position in the file, where the first line of the file is line number 1. 62 * 63 * @return the line number 64 * @since 1.0 65 */ 66 int getLineNumber(); 67 68 /** 69 * Returns the untokenized CSV row that was just read (which can potentially span multiple lines in the file). 70 * 71 * @return the untokenized CSV row that was just read 72 * @since 2.0.0 73 */ 74 String getUntokenizedRow(); 75 76 /** 77 * Gets the current row number (i.e. the number of CSV records - including the header - that have been read). This 78 * differs from the lineNumber, which is the number of real lines that have been read in the file. The first row is 79 * row 1 (which is typically the header row). 80 * 81 * @return the current row number 82 * @since 2.0.0 83 */ 84 int getRowNumber(); 85 86 /** 87 * Returns the length (i.e. number of columns) of the current row. 88 * 89 * @return the length of the current row 90 * @since 1.0 91 */ 92 int length(); 93 94 }