本文整理匯總了Java中com.csvreader.CsvReader.readHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Java CsvReader.readHeaders方法的具體用法?Java CsvReader.readHeaders怎麽用?Java CsvReader.readHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.csvreader.CsvReader
的用法示例。
在下文中一共展示了CsvReader.readHeaders方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getValidatedCreader
import com.csvreader.CsvReader; //導入方法依賴的package包/類
/**
* Method used to detect the valid delimiter by trying to validate the header using a given delimiter.
*
* @param delimiter the delimiter to use to read the file
* @param fileInputStream the file to read
* @return a CsvReader pointing to the headers, null if the headers could not be validated
* @throws IOException if file reading goes wrong
*/
private CsvReader getValidatedCreader(final char delimiter, final InputStream fileInputStream, List<String[]> metaEntries) throws IOException {
// open file
CsvReader creader = new CsvReader(fileInputStream, delimiter, Charset.forName("UTF-8"));
//validate header
do {
if (!creader.readHeaders()) {
LOG.log(Level.FINEST, "automatic delimiter detection detected invalid delimiter: " + delimiter);
metaEntries.clear();
return null;
}
metaEntries.add(creader.getHeaders());
} while (!validator.validateHeader(creader.getHeaders()));
metaEntries.remove(metaEntries.size() - 1); //remove valid header
LOG.log(Level.INFO, "automatic delimiter detection detected valid delimiter: " + delimiter);
return creader;
}
示例2: parseData
import com.csvreader.CsvReader; //導入方法依賴的package包/類
public static List<RawDataEntry> parseData(String filepath)
throws FileNotFoundException {
List<RawDataEntry> libreEntrys = new ArrayList<>();
// read file
CsvReader creader = new CsvReader(filepath, '\t', Charset.forName("UTF-8"));
// TODO add stuff
// Teststreifen-Blutzucker (mg/dL)
// Keton (mmol/L)
try {
// validate header
// TODO implement a header-erkenner
for (int i = 0; i < 2; i++) {
creader.readHeaders();
//TODO compute meta data
}
//TODO check header data
// if (!CsvValidator.validateCarelinkHeader(creader)) {
// Logger.getLogger(CarelinkCsvImporter.class.getName()).
// log(Level.SEVERE,
// "Stop parser because of unvalid header:\n"
// + Arrays.toString(Constants.CARELINK_CSV_HEADER[0])
// + "\n{0}", creader.getRawRecord());
// return null;
// }
// read entries
while (creader.readRecord()) {
// Todo cathegorize entry
RawDataEntry entry = parseEntry(creader);
if (entry != null) {
libreEntrys.add(entry);
Logger.getLogger(MedtronicCsvImporter.class.getName()).log(
Level.INFO, "Got Entry: {0}", entry.toString());
} else {
// Logger.getLogger(CarelinkCsvImporter.class.getName()).log(
// Level.FINE, "Drop Entry: {0}", creader.getRawRecord());
}
}
} catch (IOException | ParseException ex) {
Logger.getLogger(MedtronicCsvImporter.class.getName()).log(
Level.SEVERE, "Error while parsing Careling CSV", ex);
} finally {
creader.close();
}
return libreEntrys;
}