View Javadoc
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.Flushable;
20  import java.io.IOException;
21  
22  /**
23   * The interface for CSV writers.
24   * 
25   * @author Kasper B. Graversen
26   * @author James Bassett
27   */
28  public interface ICsvWriter extends Closeable, Flushable {
29  	
30  	/**
31  	 * Gets the current position in the file. The first line of the file is line number 1.
32  	 * 
33  	 * @return the line number
34  	 * @since 1.0
35  	 */
36  	int getLineNumber();
37  	
38  	/**
39  	 * Gets the current row number (i.e. the number of CSV records - including the header - that have been written).
40  	 * This differs from the lineNumber, which is the number of real lines that have been written to the file. The first
41  	 * row is row 1 (which is typically the header row).
42  	 * 
43  	 * @return the current row number
44  	 * @since 2.0.0
45  	 */
46  	int getRowNumber();
47  	
48  	/**
49  	 * Writes a single-line comment to the CSV file (the comment must already include any special comment characters
50  	 * e.g. '#' at start). Please note that comments are not part of RFC4180, so this may make your CSV file less
51  	 * portable.
52  	 * 
53  	 * @param comment
54  	 *            the comment
55  	 * @throws NullPointerException
56  	 *             if comment is null
57  	 * @throws IOException
58  	 *             if an I/O error occurs
59  	 * @since 2.1.0
60  	 */
61  	void writeComment(String comment) throws IOException;
62  	
63  	/**
64  	 * Writes the header of the CSV file.
65  	 * 
66  	 * @param header
67  	 *            one or more header Strings
68  	 * @throws NullPointerException
69  	 *             if header is null
70  	 * @throws IOException
71  	 *             if an I/O error occurs
72  	 * @since 1.0
73  	 */
74  	void writeHeader(String... header) throws IOException;
75  	
76  }