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.IOException; 19 import java.util.Map; 20 21 import org.supercsv.cellprocessor.ift.CellProcessor; 22 import org.supercsv.exception.SuperCsvConstraintViolationException; 23 import org.supercsv.exception.SuperCsvException; 24 25 /** 26 * The interface for writers that write from Maps. 27 * 28 * @author Kasper B. Graversen 29 * @author James Bassett 30 */ 31 public interface ICsvMapWriter extends ICsvWriter { 32 33 /** 34 * Writes the values of the Map as columns of a CSV file, using the supplied name mapping to map values to the 35 * appropriate columns. <tt>toString()</tt> will be called on each element prior to writing. 36 * 37 * @param values 38 * the Map containing the values to write 39 * @param nameMapping 40 * an array of Strings linking the Map keys to their corresponding CSV columns (the array length should 41 * match the number of columns). A <tt>null</tt> entry in the array indicates that the column should be 42 * ignored (the column will be empty). 43 * @throws IOException 44 * if an I/O error occurred 45 * @throws NullPointerException 46 * if values or nameMapping are null 47 * @throws SuperCsvException 48 * if there was a general exception while writing 49 * @since 1.0 50 */ 51 void write(Map<String, ?> values, String... nameMapping) throws IOException; 52 53 /** 54 * Writes the values of the Map as columns of a CSV file, using the supplied name mapping to map values to the 55 * appropriate columns. <tt>toString()</tt> will be called on each element prior to writing. 56 * 57 * @param values 58 * the Map containing the values to write 59 * @param nameMapping 60 * an array of Strings linking the Map keys to their corresponding CSV columns (the array length should 61 * match the number of columns). A <tt>null</tt> entry in the array indicates that the column should be 62 * ignored (the column will be empty). 63 * @param processors 64 * an array of CellProcessors used to further process data before it is written (each element in the 65 * processors array corresponds with a CSV column - the number of processors should match the number of 66 * columns). A <tt>null</tt> entry indicates no further processing is required (the value returned by 67 * toString() will be written as the column value). 68 * @throws IOException 69 * if an I/O error occurred 70 * @throws NullPointerException 71 * if values or nameMapping are null 72 * @throws SuperCsvConstraintViolationException 73 * if a CellProcessor constraint failed 74 * @throws SuperCsvException 75 * if there was a general exception while writing 76 * @since 1.20 77 */ 78 void write(Map<String, ?> values, String[] nameMapping, CellProcessor[] processors) throws IOException; 79 80 }