本文整理汇总了Java中org.apache.commons.csv.CSVFormat.withHeader方法的典型用法代码示例。如果您正苦于以下问题:Java CSVFormat.withHeader方法的具体用法?Java CSVFormat.withHeader怎么用?Java CSVFormat.withHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.csv.CSVFormat
的用法示例。
在下文中一共展示了CSVFormat.withHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DataSet
import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
/**
* Creates a new dataset with column labels and data read from the given Reader, using a specified input format.
*
* @param reader the Reader to read column labels and data from
* @param input_format the format
*/
@SuppressWarnings("WeakerAccess")
public DataSet(final Reader reader, final CSVFormat input_format) {
this();
try (CSVParser parser = new CSVParser(reader, input_format.withHeader())) {
labels.addAll(getColumnLabels(parser));
for (final CSVRecord record : parser) {
final List<String> items = csvRecordToList(record);
final int size = items.size();
// Don't add row if the line was empty.
if (size > 1 || (size == 1 && items.get(0).length() > 0)) {
records.add(items);
}
}
reader.close();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
示例2: injectHeaderFormat
import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
public CSVFormat injectHeaderFormat(CSVFormat format)
{
String[] names = new String[headers.length];
int i = 0;
for (Entry header : headers) {
names[i] = header.name;
i += 1;
}
return format.withHeader(names);
}
示例3: create
import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
public static CsvUnmarshaller create(CSVFormat format, CsvDataFormat dataFormat) {
// If we want to use maps, thus the header must be either fixed or automatic
if (dataFormat.isUseMaps() && format.getHeader() == null) {
format = format.withHeader();
}
// If we want to skip the header record it must automatic otherwise it's not working
if (format.getSkipHeaderRecord() && format.getHeader() == null) {
format = format.withHeader();
}
if (dataFormat.isLazyLoad()) {
return new StreamCsvUnmarshaller(format, dataFormat);
}
return new BulkCsvUnmarshaller(format, dataFormat);
}
示例4: getActiveFormat
import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
CSVFormat getActiveFormat() {
CSVFormat answer = format;
if (commentMarkerDisabled) {
answer = answer.withCommentMarker(null); // null disables the comment marker
} else if (commentMarker != null) {
answer = answer.withCommentMarker(commentMarker);
}
if (delimiter != null) {
answer = answer.withDelimiter(delimiter);
}
if (escapeDisabled) {
answer = answer.withEscape(null); // null disables the escape
} else if (escape != null) {
answer = answer.withEscape(escape);
}
if (headerDisabled) {
answer = answer.withHeader((String[]) null); // null disables the header
} else if (header != null) {
answer = answer.withHeader(header);
}
if (allowMissingColumnNames != null) {
answer = answer.withAllowMissingColumnNames(allowMissingColumnNames);
}
if (ignoreEmptyLines != null) {
answer = answer.withIgnoreEmptyLines(ignoreEmptyLines);
}
if (ignoreSurroundingSpaces != null) {
answer = answer.withIgnoreSurroundingSpaces(ignoreSurroundingSpaces);
}
if (nullStringDisabled) {
answer = answer.withNullString(null); // null disables the null string replacement
} else if (nullString != null) {
answer = answer.withNullString(nullString);
}
if (quoteDisabled) {
answer = answer.withQuote(null); // null disables quotes
} else if (quote != null) {
answer = answer.withQuote(quote);
}
if (quoteMode != null) {
answer = answer.withQuoteMode(quoteMode);
}
if (recordSeparatorDisabled) {
answer = answer.withRecordSeparator(null); // null disables the record separator
} else if (recordSeparator != null) {
answer = answer.withRecordSeparator(recordSeparator);
}
if (skipHeaderRecord != null) {
answer = answer.withSkipHeaderRecord(skipHeaderRecord);
}
return answer;
}
示例5: create
import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
/**
* Creates a new instance.
*
* @param format CSV format
* @param dataFormat Camel CSV data format
* @return New instance
*/
public static CsvMarshaller create(CSVFormat format, CsvDataFormat dataFormat) {
// If we don't want the header record, clear it
if (format.getSkipHeaderRecord()) {
format = format.withHeader((String[]) null);
}
String[] fixedColumns = dataFormat.getHeader();
if (fixedColumns != null && fixedColumns.length > 0) {
return new FixedColumnsMarshaller(format, fixedColumns);
}
return new DynamicColumnsMarshaller(format);
}
示例6: readEntityDictionary
import org.apache.commons.csv.CSVFormat; //导入方法依赖的package包/类
void readEntityDictionary(String filename, String charset, String type) {
String absoluteFilename = IOUtils.getAbsoluteFile(getBaseDir(),filename);
CSVFormat format = CSVFormat.RFC4180;
format = format.withHeader();
try {
InputStream in = IOUtils.getInputStream(absoluteFilename);
java.io.Reader reader = new InputStreamReader(in,charset);
CSVParser parser = format.parse(reader);
for(CSVRecord record :parser.getRecords()) {
String entityName = record.get("name");
String entityUrl = record.get("url");
StringTokenizer tokenizer = new StringTokenizer(entityName);
int tokenCount = 0;
StringBuilder tokenPhrase = new StringBuilder();
while(tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if(dictionaryMap.size() < tokenCount+1) {
dictionaryMap.add(new HashMap<String, Entity>());
}
if(tokenCount > 0) {
tokenPhrase.append(" ");
}
tokenPhrase.append(token);
Map<String,Entity> entityMap = dictionaryMap.get(tokenCount);
Entity newEntity = new Entity(entityName, !tokenizer.hasMoreTokens());
newEntity.setUrl(entityUrl);
newEntity.setType(type);
String key = normalize(tokenPhrase.toString());
Entity entity = entityMap.get(key);
if(entity == null) {
entityMap.put(key, newEntity);
} else if(newEntity.getName().length() < entity.getName().length()) {
entityMap.put(key, newEntity);
}
tokenCount++;
}
}
in.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}