本文整理汇总了Java中org.supercsv.io.ICsvListReader类的典型用法代码示例。如果您正苦于以下问题:Java ICsvListReader类的具体用法?Java ICsvListReader怎么用?Java ICsvListReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ICsvListReader类属于org.supercsv.io包,在下文中一共展示了ICsvListReader类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseMatrix
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
public static Table<String, String, Float> parseMatrix(Reader reader) throws IOException {
Table<String, String, Float> table = HashBasedTable.create();
try (ICsvListReader csvReader = new CsvListReader(reader, CsvPreference.STANDARD_PREFERENCE)) {
List<String> columnHeaders = csvReader.read();
List<String> row;
while ((row = csvReader.read()) != null) {
String rowHeader = row.get(0);
for (int i = 1; i < row.size(); i++) {
String columnHeader = columnHeaders.get(i);
String value = row.get(i);
table.put(rowHeader, columnHeader, value == null ? Float.NaN : Float.parseFloat(value));
}
}
}
return table;
}
示例2: readTable
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
/**
* Выполняет формирование таблицы из файла
*
* @param tableName название таблицы
* @param reader сервис чтения файла
*/
protected void readTable(String tableName, ICsvListReader reader) throws DataSetException, IOException {
String[] headers = reader.getHeader(true);
if (headers == null) {
throw new DataSetException(String.format("Table '%s' must contains headers", tableName));
}
Column[] columns = new Column[headers.length];
for (int i = 0; i < headers.length; i++) {
columns[i] = new Column(headers[i], DataType.UNKNOWN);
}
consumer.startTable(new DefaultTableMetaData(tableName, columns));
List<String> row;
while ((row = reader.read()) != null) {
consumer.row(row.toArray());
}
consumer.endTable();
}
示例3: readCompleteWorkAuthors
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
private List<String> readCompleteWorkAuthors(String inputFilename) throws FileNotFoundException, IOException {
CellProcessor[] processors = new CellProcessor[62];
for (int x = 0; x < processors.length; x++) {
processors[x] = new ConvertNullTo("");
}
List<String> result = new ArrayList<>(5000);
try (ICsvListReader listReader = new CsvListReader(new FileReader(
inputFilename), CsvPreference.STANDARD_PREFERENCE)) {
listReader.getHeader(true); //skip titles
List<Object> ergList;
while ((ergList = listReader.read(processors)) != null) {
if ("1".equals(ergList.get(5)) && !ergList.get(17).toString().isEmpty()) {
result.add(ergList.get(17).toString());
}
}
}
return result;
}
示例4: read
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
@Override
public List<Preference> read(InputStream is)
throws Exception {
Map<String, UserPreference> userPreferenceMap = new HashMap<String, UserPreference>();
//List<Preference> elements = new LinkedList<Preference>();
try {
ICsvListReader reader = new CsvListReader(new InputStreamReader(is), /*CsvPreference.STANDARD_PREFERENCE */CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
String[] tokens = reader.getHeader(true);
//elements.add(readPreference(tokens, userPreferenceMap));
int i = 1000;
List<String> element;
while ((element = reader.read()) != null && i-->0) {
tokens = element.toArray(new String[element.size()]);
readPreference(tokens, userPreferenceMap);
//elements.add(readPreference(tokens, userPreferenceMap));
}
} catch (Exception e) {
throw e;
}
return convertUserPreferencesToPreferences(userPreferenceMap);
}
示例5: read
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
@Override
public List<Preference> read(InputStream is)
throws Exception {
List<Preference> elements = new LinkedList<Preference>();
try {
ICsvListReader reader = new CsvListReader(new InputStreamReader(is), CsvPreference.STANDARD_PREFERENCE /*CsvPreference.EXCEL_PREFERENCE*/);
String[] tokens = reader.getHeader(true);
//elements.add(readPreference(tokens));
List<String> element;
while ((element = reader.read()) != null) {
tokens = element.toArray(new String[element.size()]);
elements.add(readPreference(tokens));
}
} catch (Exception e) {
throw e;
}
return elements;
}
示例6: read
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
@Override
public List<IrisPlant> read(InputStream is)
throws Exception {
List<IrisPlant> elements = new LinkedList<IrisPlant>();
try {
ICsvListReader reader = new CsvListReader(new InputStreamReader(is), CsvPreference.STANDARD_PREFERENCE /*CsvPreference.EXCEL_PREFERENCE*/);
String[] tokens = reader.getHeader(true);
elements.add(readIrisPlant(tokens));
List<String> element;
while ((element = reader.read()) != null) {
tokens = element.toArray(new String[element.size()]);
elements.add(readIrisPlant(tokens));
}
} catch (Exception e) {
throw e;
}
return elements;
}
示例7: read
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
@Override
public List<SalaryYear> read(InputStream is)
throws Exception {
List<SalaryYear> elements = new ArrayList<>();
try (ICsvListReader reader = new CsvListReader(new InputStreamReader(is), CsvPreference.EXCEL_PREFERENCE)) {
reader.getHeader(true);
List<String> element;
while ((element = reader.read()) != null) {
String[] tokens = element.toArray(new String[element.size()]);
SalaryYear salaryYear = new SalaryYear();
salaryYear.setEmail(tokens[0]);
salaryYear.setYear(2013);
List<SalaryMonth> months = new ArrayList<>(12);
for (int i = 1; i < 13; i++) {
months.add(buildSalaryMonth(i, tokens[i]));
}
salaryYear.setMonths(months);
elements.add(salaryYear);
}
}
return elements;
}
示例8: parseExternalDataElement
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
/**
* Parses a an {@link ITextElement} as CSV file and returns a list of parsed
* lines.
*/
@Override
protected List<ExternalDataRecord<C>> parseExternalDataElement(
ITextElement element) throws ConQATException {
List<ExternalDataRecord<C>> parsedLines = new ArrayList<ExternalDataRecord<C>>();
// only working on strings, thus resource is not required to be closed
@SuppressWarnings("resource")
ICsvListReader csvListReader = new CsvListReader(new StringReader(
element.getTextContent()), csvParserPreference);
try {
List<C> headerCells = getHeaderObjects(csvListReader
.getHeader(true));
List<String> lineCells;
while ((lineCells = csvListReader.read()) != null) {
ExternalDataRecord<C> parsedCsvLine = new ExternalDataRecord<C>(
fieldsEnumClass, headerCells, lineCells);
parsedLines.add(parsedCsvLine);
}
} catch (IOException e) {
throw new ConQATException("CSV parser exception occured", e);
}
return parsedLines;
}
示例9: parse
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
@Override
public JsonObject[] parse(final String[] lines) throws IOException {
List<JsonObject> events = new ArrayList();
boolean truncDupDelimiters = m_truncDupDelimiters;
int delimiter = m_delimiter;
CsvPreference pref = m_csvPreference;
Pattern delimPattern = null;
String delimStr = String.copyValueOf(Character.toChars(delimiter));
if (truncDupDelimiters) {
m_logger.debug("Truncating duplicate delimiters");
delimPattern = Pattern.compile(delimStr + "+");
}
StringBuilder sb = new StringBuilder();
for (String line : lines) {
if (delimPattern != null) {
Matcher m = delimPattern.matcher(line);
line = m.replaceAll(delimStr);
}
m_logger.trace("line: {}", line);
sb.append(line);
sb.append(pref.getEndOfLineSymbols());
}
ICsvListReader listReader = new CsvListReader(
new StringReader(sb.toString()),
pref);
List<Object> values;
AbstractFilter filter = m_filter;
String[] fieldNames = m_fieldNames;
CellProcessor[] processors = m_cellProcessors;
while ((values = listReader.read(processors)) != null) {
//
// Build one JsonObject event per row
//
// @TODO support setting of event type (metric or notification)
JsonObject event = Events.createNotificationEvent(
filter,
HostOs.hostName(),
EVENT_PRIORITY_NORMAL,
"",
"");
for (int i = 0; i < values.size(); i++) {
String fieldName = fieldNames[i];
Object value = values.get(i);
//
// Append to existing value
//
if (event.containsField(fieldName)) {
sb = new StringBuilder(event.getString(fieldName));
sb.append(value);
event.putValue(fieldName, sb.toString());
} else {
event.putValue(fieldName, value);
}
}
events.add(event);
}
return events.toArray(new JsonObject[events.size()]);
}
示例10: initializeReader
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
public static void initializeReader(CSVLoader.CSVConfig config, Client csvClient, ICsvListReader reader) {
m_config = config;
m_csvClient = csvClient;
m_listReader = reader;
}
示例11: importFile
import org.supercsv.io.ICsvListReader; //导入依赖的package包/类
@Override
public void importFile(final Path file) {
final CellProcessor[] processors = csvConfig.getProcessors();
List<Object> objectList;
try (ICsvListReader listReader = new CsvListReader(new FileReader(file.toFile()), CsvPreference.STANDARD_PREFERENCE)) {
listReader.getHeader(true);
while ((objectList = listReader.read(processors)) != null) {
// get all columns
String title = (String) objectList.get(1);
final String typeStr = (String) objectList.get(2);
final String episodesStr = (String) objectList.get(3);
String infoLinkStr = (String) objectList.get(4);
String location = (String) objectList.get(5);
// prepare attributes
title = isNotBlank(title) ? title.trim() : null;
final AnimeType type = isNotBlank(typeStr) ? AnimeType.findByName(typeStr.trim()) : null;
final int episodes = isNotBlank(episodesStr) && isNumeric(episodesStr) ? Integer.parseInt(episodesStr) : 0;
infoLinkStr = infoLinkStr != null ? infoLinkStr.trim() : infoLinkStr;
location = isNotBlank(location) ? location.trim() : null;
final InfoLink infoLink = new InfoLink(infoLinkStr);
// create object by list type
final CsvConfigType csvConfigType = CsvConfigType.findByName((String) objectList.get(0));
switch (csvConfigType) {
case ANIMELIST:
animeListEntries.add(new Anime(title, infoLink).type(type).episodes(episodes).location(location));
break;
case WATCHLIST:
watchListEntries.add(new WatchListEntry(title, infoLink));
break;
case FILTERLIST:
filterListEntries.add(new FilterEntry(title, infoLink));
break;
default:
break;
}
}
persistence.addAnimeList(animeListEntries);
persistence.addFilterList(filterListEntries);
persistence.addWatchList(watchListEntries);
} catch (final IOException e) {
log.error("An error occurred trying to import the CSV file: ", e);
}
}