com.feilong.csv.handler.CsvContentBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of feilong Show documentation
Show all versions of feilong Show documentation
feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.
/*
* Copyright (C) 2008 feilong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.csv.handler;
import static java.lang.System.lineSeparator;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.feilong.core.bean.ConvertUtil;
import com.feilong.csv.entity.CsvConfig;
/**
* 构造 csv 输出内容.
*
* @author feilong
* @since 1.7.1
* @since 1.10.7 rename
*/
public class CsvContentBuilder{
/** The Constant log. */
private static final Logger LOGGER = LoggerFactory.getLogger(CsvContentBuilder.class);
//---------------------------------------------------------------
/** 转义引号用的字符 ". */
private static final char ESCAPE_CHARACTER = '"';
/** 默认的引号字符 "引号. */
private static final char DEFAULT_QUOTE_CHARACTER = '"';
/**
* \\u转义字符的意思是"\\u后面的1-4位16进制数表示的Unicode码对应的汉字",而Unicode 0000 代表的字符是 NUL,也就是空的意思,
* 如果把这个字符输出到控制台,显示为空格.
*/
private static final char NO_QUOTE_CHARACTER = '\u0000';
//---------------------------------------------------------------
/** Don't let anyone instantiate this class. */
private CsvContentBuilder(){
//AssertionError不是必须的. 但它可以避免不小心在类的内部调用构造器. 保证该类在任何情况下都不会被实例化.
//see 《Effective Java》 2nd
throw new AssertionError("No " + getClass().getName() + " instances for you!");
}
//---------------------------------------------------------------
/**
* Writes the entire list to a CSV file. The list is assumed to be a String[]
*
* @param allLines
* a List of String[], with each String[] representing a line of the file.
* @param csvConfig
* the csv params
* @return the write content
*/
public static final String build(List