当前位置: 首页>>代码示例>>Java>>正文


Java CsvReader.readHeaders方法代码示例

本文整理汇总了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;
}
 
开发者ID:lucasbuschlinger,项目名称:BachelorPraktikum,代码行数:26,代码来源:CSVImporter.java

示例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;
    }
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:50,代码来源:LibreTxtImporter.java


注:本文中的com.csvreader.CsvReader.readHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。