zoukankan      html  css  js  c++  java
  • csv解析框架Windmill的一个demo

    csv文件内容如下,第一行是文件头

     解析代码如下:

    package com.xxx;
    
    import lombok.Data;
    import org.apache.commons.lang3.builder.ToStringBuilder;
    
    
    @Data
    public class CodecRegistries {
        private String index;
        private String name;
        /**
         * WAVE form Registration Number
         */
        private Integer hex;
        /***
         * Codec ID in the IANA Namespace
         */
        private String mimeType;
    
        /***
         * WAVE form wFormatTag ID
         */
        private String wFormatTag;
    
        /***
         * WAVEFORMAT Use
         */
        private String use;
    
        /***
         * WAVEFORMAT Name
         */
        private String formatName;
    
        /***
         * WAVEFORMAT Description
         */
        private String descr;
    
        /***
         * Additional Information
         */
        private String additional;
    
        /***
         *
         */
        private String contact;
    
        @Override
        public String toString() {
            return new ToStringBuilder(this)
                    .append("index", index)
                    .append("name", name)
                    .append("hex", hex)
                    .append("mimeType", mimeType)
                    .append("wFormatTag", wFormatTag)
                    .append("use", use)
                    .append("formatName", formatName)
                    .append("descr", descr)
                    .append("additional", additional)
                    .append("contact", contact)
                    .toString();
        }
    }
    static Map<Integer,CodecRegistries> codes = new HashMap<>();
       
     static void readCodeRegistries(String fileName)
        {
            try (InputStream inputStream = new FileInputStream(fileName)) {
    
                FileSource source = FileSource.of(inputStream);
    
                CsvParserConfig config = CsvParserConfig.builder()
                        .charset(StandardCharsets.UTF_8)
                        .build();
    
                Map<Integer, CodecRegistries> map = Windmill.parse(source, Parsers.csv(config)).skip(1).map(row -> {
                    CodecRegistries registration = new CodecRegistries();
    
                    registration.setIndex(row.cell(0).asString());
                    registration.setName(row.cell(1).asString());
              //通过自定义数据转换代码,将16进制数0x0001这样的数值转换成Integer
                    Integer hex = new NumberValue<Integer>(row.cell(2).asString(), hexDecimal -> Integer.decode(hexDecimal)).value();
    
                    registration.setHex(hex);
                    registration.setMimeType(row.cell(3).asString());
                    registration.setWFormatTag(row.cell(4).asString());
                    registration.setUse(row.cell(5).asString());
                    registration.setFormatName(row.cell(6).asString());
                    registration.setDescr(row.cell(7).asString());
                    registration.setAdditional(row.cell(8).asString());
                    registration.setContact(row.cell(9).asString());
                    return registration;
    
                }).collect(Collectors.toMap(CodecRegistries::getHex, Function.identity()));
                codes.putAll(map);
            }catch (IOException e){
                System.err.println(e);
            }
        }
  • 相关阅读:
    yolov3计算mAP
    ESP32 ADC的坑
    DCNv2编译过程报错:error: identifier "THCudaBlas_SgemmBatched" is undefined
    Arduino在Lib中输出调试参数
    ESP32获取WT901CTTL/232四元数
    常用公共前端CDN库
    js / php 网站底部版权文字自动改变年份
    以管理员身份在当前目录打开命令行窗口
    【JavaScript】提取字符串里的分数,及计算平均分并与平均分比较输出
    添加谷歌翻译到你的网站
  • 原文地址:https://www.cnblogs.com/passedbylove/p/11444562.html
Copyright © 2011-2022 走看看